What do those Labels (move.w, sub.w, bcs.s , etc. Most of the others)

Discussion in 'Discussion and Q&A Archive' started by DarkLeach, Jan 6, 2012.

Thread Status:
Not open for further replies.
  1. DarkLeach

    DarkLeach Well-Known Member Member

    Joined:
    Jul 3, 2011
    Messages:
    193
    Location:
    In the middle of desert heat
    I've been Sonic hacking for a little while and I've had something troubling me. I want to add features/ modify things in Sonic 1. I notice these labels and I have no clue what they do, but I could figure out a few (Like add, subtract, and check to see if this is here). (Most of you probably know this, but I can't find info on it anywhere). I just copy/ do what tutorials tell me to do and copy and paste from the other sections of the Sonic 1 ASM Code. I know what a few things do but these labels are so confusing :p . If someone could tell me what each Label does or point me in the right direction to find out what these all stand for, it would be greatly appreciated! :)
     
  2. Ravenfreak

    Ravenfreak Still hacking the 8-bit titles Member

    Joined:
    Feb 10, 2010
    Messages:
    410
    Location:
    O'Fallon, MO
    First off, the w after "move" means word. A word is a two-byte value, while a byte consists of two nibbles (or just one digit.) You might also come across a move.l, which means you're moving a longword value. For example this is a word:


    01 02 and this is what a byte looks like: 03. Now move.w means you're moving a word value to another address or register. Sub.w means you're subtracting a word from another value whether it be a register, or an address. Of course, this is all from memory as I haven't touched any of the 16-bit Sonic games in a long time. So I suggest you also check out these two guides on Sonic Retro:


    http://info.sonicretro.org/SCHG:68000_Instruction_Set


    http://info.sonicretro.org/SCHG:Assembly_Hacking


    I hope that helps. :p
     
  3. DarkLeach

    DarkLeach Well-Known Member Member

    Joined:
    Jul 3, 2011
    Messages:
    193
    Location:
    In the middle of desert heat
    I see all the commands that I've been Having trouble with! Thanks! :) , I'll study them whenever I get some time and be able to do what I want to do. However on the Instruction Page, I didn't see "BCS" What does that do? :p
     
  4. Crash

    Crash Well-Known Member Member

    Joined:
    Jul 15, 2010
    Messages:
    302
    Location:
    Australia
  5. DanielHall

    DanielHall Well-Known Member Member

    Joined:
    Jan 18, 2010
    Messages:
    860
    Location:
    North Wales
    I'm sure BCS branches when a certain bit is set. The other would be BCC.
     
  6. GT Koopa

    GT Koopa Well-Known Member Member

    Joined:
    Mar 9, 2011
    Messages:
    83
    Location:
    Elgin. IL
    http://68k.hax.com/


    This is the site I use. Still can't make heads or tails of most of it but in general it is a big help.
     
  7. MarkeyJester

    MarkeyJester ♡ ! Member

    Joined:
    Jun 27, 2009
    Messages:
    2,867
    BCS = Branch if Carry Set


    BCC = Branch if Carry Clear


    The processor has its own set of flags to determin the conditions (or "results") of your instructions, there are 5 as I understand it C (Carry), V (oVerflow), Z (Zero), N (Negative), X (eXtended):


    The instructions above reads the carry flag to see if it is set or cleared, an example of the instrution in use:



    Recheck:
    add.b d0,d0


    bcc Recheck



    If we were to imagine that d0 was 00 00 00 08, as we're only adding a byte, we only need to pay attention to the 08, now 08 in binary is 0000 1000.


    So, adding d0 to d0 means adding 08 to 08, this results in 10. With 08 in binary meaning 0000 1000, and 10 in binary meaning 0001 0000, all that's happened here is the bits have shifted left:



    Code:
    C d0
    
    v v
    
    - 0000 1000
    < Shift left once <



    Code:
    C d0
    
    v v
    
    0 0001 0000


    Now you can see the very far left bit (a.k.a. the most significant bit) has shifted so far, it has gone outside the byte space, this bit is sent to the carry flag as the carry bit, now the carry flag = 0 (it is now clear).



    The next instruction is branch if carry is clear, now it was cleared by the add instruction, so it branches back to "Recheck".



    Once again, it adds d0 to d0, 10 + 10 = 20:





    Code:
    C d0
    
    v v
    
    0 0001 0000
    < Shift left once <



    Code:
    C d0
    
    v v
    
    0 0010 0000


    Once again, 0 has shifted into the carry flag, so bcc branches back to "Recheck", adding again d0 to d0, 20 + 20 = 40:





    Code:
    C d0
    
    v v
    
    0 0010 0000
    < Shift left once <



    Code:
    C d0
    
    v v
    
    0 0100 0000


    Again, 0 has shifted into the carry flag, so bcc branches back to "Recheck", adding again d0 to d0, 40 + 40 = 80:





    Code:
    C d0
    
    v v
    
    0 0100 0000
    < Shift left once <



    Code:
    C d0
    
    v v
    
    0 1000 0000


    And again, 0 has shifted into the carry flag, so bcc branches back to "Recheck", adding again d0 to d0, 80 + 80 = 100:





    Code:
    C d0
    
    v v
    
    0 1000 0000
    < Shift left once <



    Code:
    C d0
    
    v v
    
    1 0000 0000

    This time, 1 has shifted into the carry flag, so now bcc will not branch as carry is set, it will now resume.
     
  8. Irixion

    Irixion Well-Known Member Member

    Joined:
    Aug 11, 2007
    Messages:
    670
    Location:
    Ontario, Canada
    Oh Jester, you can't expect him to completely understand that!


    I'd suggest reading up the basic commands of ASM here: http://info.sonicret...68000_assembly The guide assumes you know what hex is and how it basically works, and the guide will teach you the basics. It's all (usually) logical, and the more complex things aren't really related to ASM, but how the game itself is set up. At times this can be mind melting even for the best of us.


    Edit: Ninja'd, but seriously, go read it again.
     
    Last edited by a moderator: Jan 10, 2012
  9. DarkLeach

    DarkLeach Well-Known Member Member

    Joined:
    Jul 3, 2011
    Messages:
    193
    Location:
    In the middle of desert heat
    I'd read this but there is no text on the page. :eek: Is it broken? Oh and MarkeyJester your tutorial that someone linked to in this thread is great! I haven't finished it yet, I read it when I have some time and the 68k commands and the RAM stuff makes a lot more sense ( I think I'm on page 20 now). I know what Hex is and it isn't that hard once you understand. I'm taking Computer Science I (This year we're learning about Visual Basic) and this ASM stuff is making a lot more sense. (Obviously not the 68k commands and system calls but still ;) )
     
    Last edited by a moderator: Jan 10, 2012
  10. Irixion

    Irixion Well-Known Member Member

    Joined:
    Aug 11, 2007
    Messages:
    670
    Location:
    Ontario, Canada
    Seems SSRG mucked up the link--get rid of the period at the end of it. It was linked earlier in the topic but it's still a good read.
     
Thread Status:
Not open for further replies.