Search code examples
assemblymachine-codeprogram-countery86

How to determine the program counter when decoding from assembly to machine code (Y86)?


Im having trouble understanding how the address location is determined when decoding from assembly to Y86. In the example,

0x030          
0x030: 6300                     # xorq %rax , %rax
0x032: 50030001000000000000     # mrmovq 0x100(%rax ) , %rbx
0x03c: 50010002000000000000     # mrmovq 0x200(%rax ) , %rcx

how does the address location go from 0x030 to 0x032 to 0x03c? What is the equation for determining how much the location is increased by?


Solution

  • How many bytes are there in 6300? Answer: 2 and 0x030 + 2 = 0x032. How many bytes are there in 50030001000000000000? Answer: 10 and 0x032 + 10 = 0x03c.

    So you just count the number of bytes in the machine code and add to the previous address to get the next address.