Results 1 to 10 of 12

Thread: Example of Self modifying ASM code :P

Hybrid View

  1. #1
    Member
    Join Date
    Aug 2008
    Location
    Arizona
    Posts
    1,073
    Blog Entries
    2

    Default Example of Self modifying ASM code :P

    Here's a simple code that modifies one of its instructions when certain conditions are met. (like changing an add instruction to a subtract)
    I dunno I was just bored XD

    Press L+R to add to your bells if less than 99,900. If it is more than 99,900, it'll start subtracting instead, until it reaches 100 or less. It'll keep going back and forth :P

    Code:
    023FF090 012FFF11
    E0000000 00000040
    E28F2001 E12FFF12
    8800480A 01122230
    D10D4210 68214C08
    42A94D08 2339DB01
    2964E002 2331DC02
    7053A200 60213164
    00004770 04000130
    021D891C 0001863C
    023FF090 E3520003
    ASM source:


    It works a lot easier in ARM mode, but...it's just an example.
    Always willing to help with anything, code-related or not. :]

  2. #2

    Default

    From the looks of the source, I'm assuming 'adr' points to AddOrSubtract label.
    3DS Friend Code: 4699-6293-3106

  3. #3

    Default

    Neat. So it kind of cycles through to the amount you need?

  4. #4

    Default

    I think his code adds 100 bells to your current amount until you reach 99,000. After that, the code subtracts 100 bells until you get to 100 bells then it adds back up to 99,000 bells and keeps repeating itself.
    3DS Friend Code: 4699-6293-3106

  5. #5
    Member
    Join Date
    Aug 2008
    Location
    Arizona
    Posts
    1,073
    Blog Entries
    2

    Default

    In regular ARM mod, you could just the pc to overwrite any instruction. In THUMB it says it's not allowed (cause the pc is r15)
    (the pc stands for program counter, it basically tells where the next instruction to be executed is)
    In ARM everything is 32 bit though, including the instructions, so it'd take up more room, but it's definitely more powerful.
    Like, let's say in ARM you wanted to overwrite the very next instruction. Let's say r5 has the instruction you wanna write. To overwrite the very next instruction you'd put....
    str r5, [pc, #-0x4]

    to overwrite the instruction after that instead
    str r5, [pc]
    etc.
    Always willing to help with anything, code-related or not. :]

  6. #6
    Chris (Administrator) Vash's Avatar
    Join Date
    Sep 2007
    Location
    Teh Interwebz
    Posts
    1,992
    Blog Entries
    27

    Default

    I don't know about "self-modifying". Makes it sound like polymorphism. It's more like an ASM switch case.
    Animal Crossing: City Folk
    ACToolkit - NPC_Tool - PattView

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •