The PokéCommunity Forums Fan Games ROM Hacking Tools, Tutorials & Resources
Tutorial GBA ASM Programming

Tools, Tutorials & Resources Various tools to help you develop your hacks can be found here.

Reply
 
Thread Tools
  #26    
Old October 12th, 2010 (5:57 PM).
Full Metal's Avatar
Full Metal Full Metal is offline
C(++) Developer.
  • Silver Tier
 
Join Date: Jan 2008
Location: In my mind.
Age: 21
Gender: Male
Nature: Timid
Posts: 806
Send a message via Windows Live Messenger to Full Metal
Quote:
Originally Posted by HackMew View Post
"pokemon_data" and "var" are not a label. They're symbols.
Can you explain the difference between these two?
I thought that (labels/symbols) worked by the assembler calculating the distance between the (symbol/label) and the current instruction (and then doing stuff to make the instruction)
And you branch to a label, but in the end doesn't the assembler do the same sort of thing?
Not arguing, just trying to learn, i promise ;
__________________

★ full metal.

I like to push it,
and push it,
until my luck is over.
Reply With Quote

Relevant Advertising!

  #27    
Old October 14th, 2010 (5:43 PM).
Shiny Quagsire's Avatar
Shiny Quagsire Shiny Quagsire is offline
I'm Still Alive, Elsewhere
     
    Join Date: May 2009
    Location: Hoenn Safari Zone
    Age: 19
    Gender: Male
    Nature: Jolly
    Posts: 700
    Quote:
    Originally Posted by Full Metal View Post


    Can you explain the difference between these two?
    I thought that (labels/symbols) worked by the assembler calculating the distance between the (symbol/label) and the current instruction (and then doing stuff to make the instruction)
    And you branch to a label, but in the end doesn't the assembler do the same sort of thing?
    Not arguing, just trying to learn, i promise ;
    Codewise, there isn't really much of a difference. You could use a label or symbol and it really wouldn't matter. However, if your naming a section, I'm not so sure if that's OK.
    __________________



    Reply With Quote
      #28    
    Old November 9th, 2010 (3:13 PM).
    0m3GA ARS3NAL's Avatar
    0m3GA ARS3NAL 0m3GA ARS3NAL is offline
    Im comin' home...
    • Silver Tier
     
    Join Date: Jan 2008
    Location: Superjail Penitentiary
    Age: 24
    Gender: Male
    Nature: Gentle
    Posts: 1,812
    I like it, though I have a question.

    About that sleep bit loading, how can one CHANGE the bits like the sleep bits, to induce sleep?
    __________________
    >Boot Jailbot
    >Pass *****
    .
    .
    Jailbot OS Ver 1.1.2
    Greetings Warden
    of Superjail Penitentiary
    Awaiting user input...

    >Display User_Info
    ╠══User Info══╣
    Username:
    0m3GA ARS3NAL
    Age: 18
    Sex: Male ♂
    Race: Caucasian
    Quote:
    "What is this
    I don't even..."

    M/O: Often acts out to get attention, but recently has changed that. Has been studying up on hacking information and hopes to participate in more advanced hacking discussion.
    ╠══End of File══╣
    Awaiting user input...

    >
    Reply With Quote
      #29    
    Old November 9th, 2010 (3:41 PM).
    Shiny Quagsire's Avatar
    Shiny Quagsire Shiny Quagsire is offline
    I'm Still Alive, Elsewhere
       
      Join Date: May 2009
      Location: Hoenn Safari Zone
      Age: 19
      Gender: Male
      Nature: Jolly
      Posts: 700
      Quote:
      Originally Posted by 0m3GA ARS3NAL View Post
      I like it, though I have a question.

      About that sleep bit loading, how can one CHANGE the bits like the sleep bits, to induce sleep?
      I've had to set bits, and I've found that the best way to do it is:
      1. Shift the bits right to ensure there isn't any sleep bits already there
      2. Add a number (Let's say, 3) to the amount
      3. Store that value back into the RAM with strb
      __________________



      Reply With Quote
        #30    
      Old November 9th, 2010 (3:49 PM).
      0m3GA ARS3NAL's Avatar
      0m3GA ARS3NAL 0m3GA ARS3NAL is offline
      Im comin' home...
      • Silver Tier
       
      Join Date: Jan 2008
      Location: Superjail Penitentiary
      Age: 24
      Gender: Male
      Nature: Gentle
      Posts: 1,812
      Quote:
      Originally Posted by shiny quagsire View Post
      I've had to set bits, and I've found that the best way to do it is:
      1. Shift the bits right to ensure there isn't any sleep bits already there
      2. Add a number (Let's say, 3) to the amount
      3. Store that value back into the RAM with strb
      I'm a little confused...

      may I have an example?
      __________________
      >Boot Jailbot
      >Pass *****
      .
      .
      Jailbot OS Ver 1.1.2
      Greetings Warden
      of Superjail Penitentiary
      Awaiting user input...

      >Display User_Info
      ╠══User Info══╣
      Username:
      0m3GA ARS3NAL
      Age: 18
      Sex: Male ♂
      Race: Caucasian
      Quote:
      "What is this
      I don't even..."

      M/O: Often acts out to get attention, but recently has changed that. Has been studying up on hacking information and hopes to participate in more advanced hacking discussion.
      ╠══End of File══╣
      Awaiting user input...

      >
      Reply With Quote
        #31    
      Old November 9th, 2010 (3:59 PM).
      Shiny Quagsire's Avatar
      Shiny Quagsire Shiny Quagsire is offline
      I'm Still Alive, Elsewhere
         
        Join Date: May 2009
        Location: Hoenn Safari Zone
        Age: 19
        Gender: Male
        Nature: Jolly
        Posts: 700
        Quote:
        Originally Posted by 0m3GA ARS3NAL View Post
        I'm a little confused...

        may I have an example?
        Sure

        OK, lets take our initial routine:
        Code:
        .align 2
        .thumb
        .global example1
        
        main:
        		push {r0-r1,lr}
        		ldr r0, pokemon_data
        		ldrb r0, [r0]
        		lsl r0, r0, #0x5
        		lsr r0, r0, #0x5
        		ldr r1, var
        		strh r0, [r1]
        		pop {r0-r1,pc}
        
        .align 2
        
        pokemon_data:
        		.word 0x02024284 + 0x50
        var:
        		.word 0x020270B6 + (0x800D * 2)
        Now, we want to replace all of our checking and returning stuff with this:

        Code:
        lsr r0, r0, #0x3				@Shift over initial sleeping bits (If there)
        lsl r0, r0, #0x3				@Set it back
        add r0, #0xyoursleepturns		@Add our number of sleeping turns
        ldr r1, pokemon_data			@Load our writing destination
        strh r0, [r1]				@store r0 in the address contained in r1
        Our final result:

        Code:
        .align 2
        .thumb
        .global example1
        
        main:
        		push {r0-r1,lr}
        		ldr r0, pokemon_data
        		ldrb r0, [r0]
        		lsr r0, r0, #0x3 
        		lsl r0, r0, #0x3
        		add r0, #0xyoursleepturns
        		ldr r1, pokemon_data 
        		strh r0, [r1] 
        		pop {r0-r1,pc}
        
        .align 2
        
        pokemon_data:
        		.word 0x02024284 + 0x50
        Since I didn't need the var, I removed it
        __________________



        Reply With Quote
          #32    
        Old November 9th, 2010 (5:35 PM).
        0m3GA ARS3NAL's Avatar
        0m3GA ARS3NAL 0m3GA ARS3NAL is offline
        Im comin' home...
        • Silver Tier
         
        Join Date: Jan 2008
        Location: Superjail Penitentiary
        Age: 24
        Gender: Male
        Nature: Gentle
        Posts: 1,812
        This pleases 0m3GA
        Thanks, it makes more sense once I see a commented out routine.

        Little ASM hacks like these are pretty easy now that I see it, but the bigger stuff, like Day and Night, and Havking the player's sprite to change it and keep it changed...
        __________________
        >Boot Jailbot
        >Pass *****
        .
        .
        Jailbot OS Ver 1.1.2
        Greetings Warden
        of Superjail Penitentiary
        Awaiting user input...

        >Display User_Info
        ╠══User Info══╣
        Username:
        0m3GA ARS3NAL
        Age: 18
        Sex: Male ♂
        Race: Caucasian
        Quote:
        "What is this
        I don't even..."

        M/O: Often acts out to get attention, but recently has changed that. Has been studying up on hacking information and hopes to participate in more advanced hacking discussion.
        ╠══End of File══╣
        Awaiting user input...

        >
        Reply With Quote
          #33    
        Old November 30th, 2010 (10:16 AM).
        2RandomStudios's Avatar
        2RandomStudios 2RandomStudios is offline
        Angry Jigglypuff
           
          Join Date: Nov 2010
          Location: Database Error
          Gender: Male
          Posts: 77
          after much trial and error, I simply can't get the thumb.bat to work! it gives me errors such as "as.exe is missing" (which it isnt) and "can't compile example1_fr.asm the file does not exist" (which it does)
          Please help!
          __________________
          Reply With Quote
            #34    
          Old November 30th, 2010 (4:26 PM). Edited November 30th, 2010 by forestw785.
          forestw785's Avatar
          forestw785 forestw785 is offline
          I divide by 0.
             
            Join Date: Sep 2009
            Gender: Male
            Posts: 60
            Quote:
            Originally Posted by 2RandomStudios View Post
            after much trial and error, I simply can't get the thumb.bat to work! it gives me errors such as "as.exe is missing" (which it isnt) and "can't compile example1_fr.asm the file does not exist" (which it does)
            Please help!
            I'm guessing you didn't route your cmd prompt to the folder with your ASM stuff.

            If it's on your desktop, then how you route command prompt there would be:
            xp: cd \Documents and Settings\(username for your computer)\Desktop\ASM
            7/Vista: cd \Users\(username for your computer)\Desktop\ASM

            And press enter, and then the command prompt is rerouted to your ASM folder.


            My problems:
            I follow your tutorial, and I get everything to work in the first two lessons with no problems, but even with your "explanations" I don't understand what these codes are actually doing. I'm basically just telling the ROM to behave a certain way without knowing how I'm making it behave that way.
            Example:
            • What is a callasm?
            • What is buffernumber 0x0 lastresult

            There are others too, and you even define them. An example of that would be:
            .align 2-This aligns the ASM by a multiple of 2, since each instruction is 2 bytes long. (aligning the ASM does what exactly?, and a multiple of two what?)
            push {r0-r1,lr}- This pushes registers r0, r1, and the link register into the stack. (what is {r0-r1,lr}? what is r0, r1, and lr?}

            Look at it from someone else's perspective:
            Gita monooto hon : These are words in another language, and they deal with sound.
            Not specific enough, and provide no real understanding of the material, right?
            __________________


            Reply With Quote
              #35    
            Old November 30th, 2010 (8:50 PM).
            2RandomStudios's Avatar
            2RandomStudios 2RandomStudios is offline
            Angry Jigglypuff
               
              Join Date: Nov 2010
              Location: Database Error
              Gender: Male
              Posts: 77
              Quote:
              Originally Posted by forestw785 View Post
              I'm guessing you didn't route your cmd prompt to the folder with your ASM stuff.

              If it's on your desktop, then how you route command prompt there would be:
              xp: cd \Documents and Settings\(username for your computer)\Desktop\ASM
              7/Vista: cd \Users\(username for your computer)\Desktop\ASM

              And press enter, and then the command prompt is rerouted to your ASM folder.


              My problems:
              I follow your tutorial, and I get everything to work in the first two lessons with no problems, but even with your "explanations" I don't understand what these codes are actually doing. I'm basically just telling the ROM to behave a certain way without knowing how I'm making it behave that way.
              Example:
              • What is a callasm?
              • What is buffernumber 0x0 lastresult

              There are others too, and you even define them. An example of that would be:
              .align 2-This aligns the ASM by a multiple of 2, since each instruction is 2 bytes long. (aligning the ASM does what exactly?, and a multiple of two what?)
              push {r0-r1,lr}- This pushes registers r0, r1, and the link register into the stack. (what is {r0-r1,lr}? what is r0, r1, and lr?}

              Look at it from someone else's perspective:
              Gita monooto hon : These are words in another language, and they deal with sound.
              Not specific enough, and provide no real understanding of the material, right?
              I followed that step exactly and it tells me that "C:\Users\(name)\Desktop\ASM" is not a recognized command!
              __________________
              Reply With Quote
                #36    
              Old November 30th, 2010 (8:55 PM).
              Incineroar's Avatar
              Incineroar Incineroar is online now
              the spirit of the fighter
              • Moderator
              • Platinum Tier
              • Developer
               
              Join Date: May 2009
              Location: Iki Town
              Age: 22
              Gender: Male
              Nature: Brave
              Posts: 13,345
              Quote:
              Originally Posted by 2RandomStudios View Post
              I followed that step exactly and it tells me that "C:\Users\(name)\Desktop\ASM" is not a recognized command!
              I'm sure if you use CD Desktop, or C:\Users\Name\CD it will work. It will than say C:\Desktop_ and you can continue from there.
              __________________
              Reply With Quote
                #37    
              Old November 30th, 2010 (8:55 PM).
              colcolstyles's Avatar
              colcolstyles colcolstyles is offline
              Yours truly
              • Crystal Tier
               
              Join Date: May 2008
              Location: The Bay Area
              Gender: Male
              Nature: Lonely
              Posts: 1,584
              Quote:
              Originally Posted by 2RandomStudios View Post
              I followed that step exactly and it tells me that "C:\Users\(name)\Desktop\ASM" is not a recognized command!
              That's probably because you forgot to include the "cd" before the file path. Try this:

              Code:
              cd C:\Users\(name)\Desktop\ASM
              __________________

              Brother of Vrai
              Reply With Quote
                #38    
              Old November 30th, 2010 (9:10 PM).
              Shiny Quagsire's Avatar
              Shiny Quagsire Shiny Quagsire is offline
              I'm Still Alive, Elsewhere
                 
                Join Date: May 2009
                Location: Hoenn Safari Zone
                Age: 19
                Gender: Male
                Nature: Jolly
                Posts: 700
                Quote:
                Originally Posted by forestw785 View Post
                I'm guessing you didn't route your cmd prompt to the folder with your ASM stuff.

                If it's on your desktop, then how you route command prompt there would be:
                xp: cd \Documents and Settings\(username for your computer)\Desktop\ASM
                7/Vista: cd \Users\(username for your computer)\Desktop\ASM

                And press enter, and then the command prompt is rerouted to your ASM folder.


                My problems:
                I follow your tutorial, and I get everything to work in the first two lessons with no problems, but even with your "explanations" I don't understand what these codes are actually doing. I'm basically just telling the ROM to behave a certain way without knowing how I'm making it behave that way.
                Example:
                • What is a callasm?
                • What is buffernumber 0x0 lastresult

                There are others too, and you even define them. An example of that would be:
                .align 2-This aligns the ASM by a multiple of 2, since each instruction is 2 bytes long. (aligning the ASM does what exactly?, and a multiple of two what?)
                push {r0-r1,lr}- This pushes registers r0, r1, and the link register into the stack. (what is {r0-r1,lr}? what is r0, r1, and lr?}

                Look at it from someone else's perspective:
                Gita monooto hon : These are words in another language, and they deal with sound.
                Not specific enough, and provide no real understanding of the material, right?
                Alright. It sounds like you havn't done too much scripting. Callasm calls a select routine from a script. It basically calls your ASM and returns. Call ASM. Buffernumber takes a number in a variable and stores it into a buffer such as [buffer1]. As for alignment, it makes sure the labels, and accessed data can are in addresses that are multiples of two.

                Quote:
                Originally Posted by ASM Book

                A Simple Example
                Boundaries are evenly divisible memory addresses. For example, an address that is aligned on a 4-BYTE (DWORD) boundary is evenly divisible by 4. The processor will always get it's data from DWORD boundaries and in DWORD sizes. So, if you had the following
                1111 2222 3333 4444...
                and you wanted to get the second DWORD, the processor would find it on an address divisible by 4 (a boundary) and get it in one fetch. However, if the data was misaligned like this
                1122 2233 3344 4400...
                and you wanted the same DWORD, the processor would
                1. Get the first DWORD (FETCH 1)
                2. Chop off the leftmost 3 bytes
                3. Get the second DWORD (FETCH 2)
                4. Chop off the rightmost 1 byte
                5. Then put them both together.
                This requires 2 memory fetches and takes longer to execute. This is how it applies to DWORDs as in the previous example. For word size values, there would be no change because the 2 bytes are available in the first pass in both cases. There are certain instructions that work better on 16-BYTE boundaries (such as movsd) and some that require it (some FPU instructions).
                So basically it allows code to be acessed right and it helps the processor to be faster.

                r0, r1, and lr are your variables. They are used to keep data for code, and then the data is used. Some times they hold addresses, data to be written, and arguments for other routines.
                __________________



                Reply With Quote
                  #39    
                Old November 30th, 2010 (10:18 PM).
                2RandomStudios's Avatar
                2RandomStudios 2RandomStudios is offline
                Angry Jigglypuff
                   
                  Join Date: Nov 2010
                  Location: Database Error
                  Gender: Male
                  Posts: 77
                  Quote:
                  Originally Posted by colcolstyles View Post
                  That's probably because you forgot to include the "cd" before the file path. Try this:

                  Code:
                  cd C:\Users\(name)\Desktop\ASM
                  Thanks so much for the help. It works perfectly now!
                  __________________
                  Reply With Quote
                    #40    
                  Old November 30th, 2010 (10:50 PM).
                  0m3GA ARS3NAL's Avatar
                  0m3GA ARS3NAL 0m3GA ARS3NAL is offline
                  Im comin' home...
                  • Silver Tier
                   
                  Join Date: Jan 2008
                  Location: Superjail Penitentiary
                  Age: 24
                  Gender: Male
                  Nature: Gentle
                  Posts: 1,812
                  Quote:
                  Originally Posted by 2RandomStudios View Post
                  Thanks so much for the help. It works perfectly now!
                  Alternativly, you can go to

                  C:/Windows/System32/

                  Grab the CMD.exe file there and COPY it, then paste the copy in the folder with the as.exe file.

                  From then on all you've got to do is double click on the CMD.EXE and then go from there, no need to redirect it.
                  You can also put a shortcut onto the desktop for easy access.
                  __________________
                  >Boot Jailbot
                  >Pass *****
                  .
                  .
                  Jailbot OS Ver 1.1.2
                  Greetings Warden
                  of Superjail Penitentiary
                  Awaiting user input...

                  >Display User_Info
                  ╠══User Info══╣
                  Username:
                  0m3GA ARS3NAL
                  Age: 18
                  Sex: Male ♂
                  Race: Caucasian
                  Quote:
                  "What is this
                  I don't even..."

                  M/O: Often acts out to get attention, but recently has changed that. Has been studying up on hacking information and hopes to participate in more advanced hacking discussion.
                  ╠══End of File══╣
                  Awaiting user input...

                  >
                  Reply With Quote
                    #41    
                  Old January 3rd, 2011 (6:39 PM).
                  SPG's Avatar
                  SPG SPG is offline
                  Pyroblock
                     
                    Join Date: Dec 2010
                    Age: 20
                    Gender: Male
                    Posts: 88
                    quick question, how would i make a pokemon base stat go higherthan 255? i know this requirs asm and if i over looked it and its in this tut plz tell me so your time isn't wasted any more
                    __________________
                    want to help with forbidden version? or want more details about it? pm me or contact me at [email protected]
                    Reply With Quote
                      #42    
                    Old January 4th, 2011 (2:30 PM).
                    colcolstyles's Avatar
                    colcolstyles colcolstyles is offline
                    Yours truly
                    • Crystal Tier
                     
                    Join Date: May 2008
                    Location: The Bay Area
                    Gender: Male
                    Nature: Lonely
                    Posts: 1,584
                    Quote:
                    Originally Posted by SPG View Post
                    quick question, how would i make a pokemon base stat go higherthan 255? i know this requirs asm and if i over looked it and its in this tut plz tell me so your time isn't wasted any more
                    You will have to expand the pokémon data structure so that the six base stats will all be halfowrds (16-bit) instead of bytes (8-bit). You will also have to change the references to the data table because each entry (i.e., each pokémon's data) will now be longer. Then you'll have to hunt down every single routine that loads a pokémon's base stats and change them so that each one loads halfwords instead of bytes. You possibly will also have to make some changes to these routines as they will be interpreting the data as bytes.

                    In other words, just give up.
                    __________________

                    Brother of Vrai
                    Reply With Quote
                      #43    
                    Old January 6th, 2011 (1:07 PM).
                    NintendoBoyDX NintendoBoyDX is offline
                       
                      Join Date: Jul 2010
                      Gender: Male
                      Posts: 94
                      Quick question. When you load the status byte and want to separate the 3 sleep bits, why not just and it by 7? I'm just starting out with assembly but I was wondering why you shifted the bits to clear instead of just using and.
                      Reply With Quote
                        #44    
                      Old January 6th, 2011 (6:21 PM). Edited January 6th, 2011 by Xenesis.
                      Xenesis's Avatar
                      Xenesis Xenesis is offline
                      Syogun Changer
                         
                        Join Date: May 2006
                        Location: Australia
                        Nature: Sassy
                        Posts: 55
                        Send a message via AIM to Xenesis Send a message via Windows Live Messenger to Xenesis
                        Using shifts to clear bits has it's advantages. Mainly because to and something you need to load a value into a register and then and between two registers. Using bitshifts to cut off bits you don't care about is often simpler because it requires only one register.

                        Basically, as a consequence of the processor design there's no function for AND rX, Value, just AND rX, rY

                        Here's a summary of all the ALU operations from gbatek:

                        Code:
                        THUMB.4: ALU operations
                        
                        Opcode Format
                        
                          Bit    Expl.
                          15-10  Must be 010000b for this type of instructions
                          9-6    Opcode (0-Fh)
                                   0: AND Rd,Rs     ;AND logical       Rd = Rd AND Rs
                                   1: EOR Rd,Rs     ;XOR logical       Rd = Rd XOR Rs
                                   2: LSL Rd,Rs     ;log. shift left   Rd = Rd << (Rs AND 0FFh)
                                   3: LSR Rd,Rs     ;log. shift right  Rd = Rd >> (Rs AND 0FFh)
                                   4: ASR Rd,Rs     ;arit shift right  Rd = Rd SAR (Rs AND 0FFh)
                                   5: ADC Rd,Rs     ;add with carry    Rd = Rd + Rs + Cy
                                   6: SBC Rd,Rs     ;sub with carry    Rd = Rd - Rs - NOT Cy
                                   7: ROR Rd,Rs     ;rotate right      Rd = Rd ROR (Rs AND 0FFh)
                                   8: TST Rd,Rs     ;test            Void = Rd AND Rs
                                   9: NEG Rd,Rs     ;negate            Rd = 0 - Rs
                                   A: CMP Rd,Rs     ;compare         Void = Rd - Rs
                                   B: CMN Rd,Rs     ;neg.compare     Void = Rd + Rs
                                   C: ORR Rd,Rs     ;OR logical        Rd = Rd OR Rs
                                   D: MUL Rd,Rs     ;multiply          Rd = Rd * Rs
                                   E: BIC Rd,Rs     ;bit clear         Rd = Rd AND NOT Rs
                                   F: MVN Rd,Rs     ;not               Rd = NOT Rs
                          5-3    Rs - Source Register       (R0..R7)
                          2-0    Rd - Destination Register  (R0..R7)
                        As you can see, they only work between two registers (with the exception of the NOT/NEG operations).
                        Reply With Quote
                          #45    
                        Old January 6th, 2011 (6:36 PM).
                        NintendoBoyDX NintendoBoyDX is offline
                           
                          Join Date: Jul 2010
                          Gender: Male
                          Posts: 94
                          Quote:
                          Originally Posted by Xenesis View Post
                          Using shifts to clear bits has it's advantages. Mainly because to and something you need to load a value into a register and then and between two registers. Using bitshifts to cut off bits you don't care about is often simpler because it requires only one register.
                          If I'm not mistaken though and directly edits the contents of one register, so it only requires one register as well.
                          Reply With Quote
                            #46    
                          Old January 6th, 2011 (6:43 PM).
                          colcolstyles's Avatar
                          colcolstyles colcolstyles is offline
                          Yours truly
                          • Crystal Tier
                           
                          Join Date: May 2008
                          Location: The Bay Area
                          Gender: Male
                          Nature: Lonely
                          Posts: 1,584
                          I'm pretty sure it takes two. Let's say you have some value in r0. In order to clear the top 29 bits, you would have to load 7 into an arbitrary register and then AND the two. I can't think of any way to do it with only one register other than to use logical shifts. Plus, I think that the "mov" instruction takes up more cycles than logical shifts so it'll save you a nanosecond or two. :D
                          __________________

                          Brother of Vrai
                          Reply With Quote
                            #47    
                          Old January 6th, 2011 (6:44 PM).
                          Xenesis's Avatar
                          Xenesis Xenesis is offline
                          Syogun Changer
                             
                            Join Date: May 2006
                            Location: Australia
                            Nature: Sassy
                            Posts: 55
                            Send a message via AIM to Xenesis Send a message via Windows Live Messenger to Xenesis
                            Quote:
                            Originally Posted by NintendoBoyDX View Post
                            If I'm not mistaken though and directly edits the contents of one register, so it only requires one register as well.
                            Yes, that's correct.

                            However, you can't AND an immediate value in code, you have to AND two registers.

                            Eg, you can't go:

                            AND r0, #0x3

                            because the hardware doesn't support it.

                            You have to go something like:

                            MOV r1, #0x3
                            AND r0, r1

                            Which requires two free registers. If you want to clear bits, you can just do something like:

                            lsl r0, r0, #0x19
                            lsr r0, r0, #0x19

                            Which only requires one free register.

                            Quote:
                            Originally Posted by colcolstyles View Post
                            Plus, I think that the "mov" instruction takes up more cycles than logical shifts so it'll save you a nanosecond or two. :D
                            The difference between the two is generally rather minor. You're unlikely to add much bloat to the game's code as is unless you start abusing swi operations relentlessly.
                            Reply With Quote
                              #48    
                            Old January 6th, 2011 (6:59 PM).
                            colcolstyles's Avatar
                            colcolstyles colcolstyles is offline
                            Yours truly
                            • Crystal Tier
                             
                            Join Date: May 2008
                            Location: The Bay Area
                            Gender: Male
                            Nature: Lonely
                            Posts: 1,584
                            Quote:
                            Originally Posted by Xenesis View Post
                            The difference between the two is generally rather minor. You're unlikely to add much bloat to the game's code as is unless you start abusing swi operations relentlessly.
                            True, although if the code is in a loop and you're already pressed for time (which you shouldn't be if you're hacking a commercial ROM), it could possibly make a difference. Actually, if this is to be used in a loop, you're probably better off "mov"-ing the 7 into a register outside the loop so that you only need one instruction (an "and") to clear bits while inside the loop.
                            __________________

                            Brother of Vrai
                            Reply With Quote
                              #49    
                            Old January 6th, 2011 (7:37 PM).
                            NintendoBoyDX NintendoBoyDX is offline
                               
                              Join Date: Jul 2010
                              Gender: Male
                              Posts: 94
                              Thanks Xenesis, colcolstyles. There was just one more thing that wasn't clear to me:
                              .word 0x020270B6 + (0x800D * 2)
                              If the 0x8000-0x8013 variables are the only static one, how would there be an address of the "first" variable(I assume 0x0000), wouldn't it be DMA along with the rest?

                              BTW, looking at an example code from a tutorial JPAN posted a while ago, he subtracts 0x8000 from his variable values, multiplies them by 4, then finally adds that to the 0x8000 variable's address. I don't understand why it would be necessary to do that(or how that works quite frankly), even though with the code in this tutorial you can simply store the value to loaded variable.
                              Here was the code:
                              Code:
                                                        .align 2
                                                        .thumb
                                Var_adder:      push {r0-r2, lr}
                                                        Ldr r0, first_var_addr @this will load the address of that lable
                                                        Ldrh r0, [r0, #0x0]      @and this will load its content.
                                                        Ldr r1, second_var_addr
                                                        Ldrh r1, [r1, #0x0]      @both variable numbers are loaded   
                                                        Lsl r2, r2, #0x10          @cleans the bottom half of register r2
                                                        Add r2, r2,#0x8          @places 0x8 in r2
                                                        Lsl r2, r2, #0xc            @and this turns 0x8 in 0x8000, and cleans the rest                                                               @of r2             
                                                        Sub r1, r1, r2               @leaves only the last value in
                                                        Sub r0, r0, r2               @each variable.
                                                        Lsl r1, r1, #0x2            @after multiplied by 4, It becomes the 
                                                                                            @offset of that address
                                                        Ldr r2, var_8000_addr
                                                        Lsl r0, r0, #0x2            @same here.
                                                        Add r0, r2, r0              @by adding the variable address to the offest
                                                        Add r1, r2, r1              @you get the correct variable address
                                                        Ldrh r2, [r0, #0x0]      @now we load the content of the variables we
                                                        Ldrh r1, [r1, #0x0]      @want to add
                                                        Add r2, r1, r2              @and add them
                                                        Strh r2, [r0, #0x0]       @the result, that is in r2, is placed in the first                                                                        @variable, the one in 0x8013
                                                        Pop {r0-r2, pc}           @and we’re done
                                 
                                first_var_addr: .word 0x020370dc
                                second_var_addr:.word 0x020370de
                                var_8000_addr:.word 0x020370b8
                              Reply With Quote
                                #50    
                              Old February 3rd, 2013 (8:11 PM).
                              阴魂君's Avatar
                              阴魂君 阴魂君 is offline
                              _(:зゝ∠)_ so busy i am…
                                 
                                Join Date: Nov 2012
                                Location: China
                                Age: 21
                                Gender: Male
                                Nature: Brave
                                Posts: 22
                                Excuse me,I don't know why,but I can't download the asm pack in China... Could you please send it to my email? My email address is [email protected]
                                thanks a lot >_<
                                Reply With Quote
                                Reply
                                Quick Reply

                                Sponsored Links
                                Thread Tools

                                Posting Rules
                                You may not post new threads
                                You may not post replies
                                You may not post attachments
                                You may not edit your posts

                                BB code is On
                                Smilies are On
                                [IMG] code is On
                                HTML code is Off

                                Forum Jump


                                All times are GMT -8. The time now is 9:39 AM.