[terminal]$ ./yis a.yo Stopped in 11 steps at PC = 0x2c. Status 'HLT', CC Z=1 S=0 O=0 Changes to registers: %eax: 0x00000000 0x00000004 %ebx: 0x00000000 0x00000005 %esp: 0x00000000 0x00000023 %ebp: 0x00000000 0x0000002f Changes to memory: 0x0020: 0x2c803fa0 0x27803fa0 0x0024: 0x20000000 0x05000000 0x0028: 0x905fb054 0x04000000 0x002c: 0x45205fa0 0x37000000 0x0030: 0x32200120 0x0d000000 0x0034: 0x00905fb0 0x00000000 [terminal]$ cat a.yo 0x000: | .pos 0 0x000: | init: 0x000: 30f437000000 | irmovl Stack, %esp 0x006: 2045 | rrmovl %esp, %ebp 0x008: 800e000000 | call Main 0x00d: 00 | halt | 0x00e: | Main: 0x00e: a05f | pushl %ebp 0x010: 2045 | rrmovl %esp,%ebp | 0x012: 30f004000000 | irmovl $4,%eax 0x018: a00f | pushl %eax 0x01a: 30f305000000 | irmovl $5,%ebx 0x020: a03f | pushl %ebx 0x022: 802c000000 | call Sum | 0x027: 2054 | rrmovl %ebp,%esp 0x029: b05f | popl %ebp 0x02b: 90 | ret | 0x02c: | Sum: 0x02c: a05f | pushl %ebp #right here 0x02e: 2045 | rrmovl %esp,%ebp | 0x030: 2001 | rrmovl %eax,%ecx 0x032: 2032 | rrmovl %ebx,%edx | 0x034: b05f | popl %ebp 0x036: 90 | ret 0x037: | Stack:
I'm using the yas simulator to compile and run my y86 assembly. I'm trying to understand why the program would halt at 0x2c, It does nothing except send 2 constants into a function (which aren't even used) that just moves the values that would be parameter into other registers.
You're overwriting parts of the code with stack contents.
You initialize esp
to Stack
, which is 0x37
. By the time you reach Sum
you'll have 5 DWORDs on the stack (3 * pushl
, and 2 * call
). Five DWORDs is 20 bytes (0x14), and 0x37 - 0x14 is 0x23 (remember, the stack grows backwards in memory). You can see this is the "Changes to registers" list: %esp: 0x00000000 0x00000023
.
As you can see in the "Changes to memory" list, the DWORD at 0x2C (which is where Sum
starts) has changed from 0x45205fa0 to 0x37000000. Assuming little-endian, that means the byte at address 0x2C is 0x00, which equals HALT
.
User contributions licensed under CC BY-SA 3.0