How are hex sequence translated to assembly without ambiguity?

前端 未结 9 2048
忘了有多久
忘了有多久 2021-01-06 14:59
8B EC 56 8B F4 68 00 70 40 00 FF 15 BC 82 40   

A senquence like above can be segmented in various ways,each segment can be translated to correspon

相关标签:
9条回答
  • 2021-01-06 15:56

    The sequence you listed shows exactly 1 number. In binary, it's 100010111110110001010110100010111111010001101000000000000111000001000000000000001111111100010101101111001000001001000000. In decimal, it's 726522768938664460674442126658667072. These are all just different ways of writing exactly the same value. A particular architecture's ISA will divide the bits into fields and assign them meaning. Most processors have easy to get manuals that describe the meaning assigned to each of the bits in those fields.

    0 讨论(0)
  • 2021-01-06 15:56

    There might also be some clues elsewhere about what is a valid starting address. There is always a reset vector address, and there are usually interrupt vector addresses, which all must be valid start points for blocks of code. More usefully, if you come across a jump or call instruction elsewhere which references an address in the block you are trying to decode, then that gives you another start address.

    I think I see your worry, and as far as I know its correct - if the program counter gets upset by one and that causes invalid instructions or unintended instructions to be executed, the program probably crashes. True, and also if you run into a data block and try to execute that. At least the latter can be avoided by using a Harvard architecture, where code and data are in seperate memory spaces and may be different bit widths.

    0 讨论(0)
  • 2021-01-06 16:00

    Knowing your starting point.

    In other words, given a specific starting byte of an instruction, it is unambiguous where the instruction ends, thus giving you the starting byte of the next instruction and allowing you to continue. Given an arbitrary block of memory it is impossible to break it up into individual instructions without knowing where the first instruction begins.

    From a more mathematical perspective, there is no valid instruction whose bytes are a prefix of another valid instruction. So if ab is valid, then you know that ab cd cannot be valid so ab must be one instruction and cd is the start of the next instruction.

    0 讨论(0)
提交回复
热议问题