Assembly code vs Machine code vs Object code?

后端 未结 10 2007
执笔经年
执笔经年 2020-11-27 09:11

What is the difference between object code, machine code and assembly code?

Can you give a visual example of their difference?

10条回答
  •  感动是毒
    2020-11-27 09:13

    One point not yet mentioned is that there are a few different types of assembly code. In the most basic form, all numbers used in instructions must be specified as constants. For example:

    $1902: BD 37 14 : LDA $1437,X
    $1905: 85 03    : STA $03
    $1907: 85 09    : STA $09
    $1909: CA       : DEX
    $190A: 10       : BPL $1902
    

    The above bit of code, if stored at address $1900 in an Atari 2600 cartridge, will display a number of lines in different colors fetched from a table which starts at address $1437. On some tools, typing in an address, along with the rightmost part of the line above, would store to memory the values shown in the middle column, and start the next line with the following address. Typing code in that form was much more convenient than typing in hex, but one had to know the precise addresses of everything.

    Most assemblers allow one to use symbolic addresses. The above code would be written more like:

    rainbow_lp:
      lda ColorTbl,x
      sta WSYNC
      sta COLUBK
      dex
      bpl rainbow_lp
    

    The assembler would automatically adjust the LDA instruction so it would refer to whatever address was mapped to the label ColorTbl. Using this style of assembler makes it much easier to write and edit code than would be possible if one had to hand-key and hand-maintain all addresses.

提交回复
热议问题