Translating Assembly Language to Machine Language
An example program Read*Read a value from input unit to Data Reg CopyTo Data1*Put value in memory at label Data1 CopyFrom Extra*Value at mem. loc. Extra to Data Reg Add Data1* Sum of Data Reg and Data1 Print* Send Sum to output unit Stop Extra5* Value to sum Data10* Storage for input value Notes: Parts of lines appearing after "*" are comments Labels in left hand column are names associated with the corresponding value
Instructions and addresses 00000Read 00001CopyTo Data CopyFrom Extra 00011Add Data Print 00101Stop 00110Extra Data10 Notes: Each instruction will occupy one location in Woody's main memory Comments are ignored in the translation process, so they have been removed here
Pass 1: Create a symbol table 00000Read 00001CopyTo Data CopyFrom Extra 00011Add Data Print 00101Stop 00110Extra Data10 LabelAddress
Pass 1: Create a symbol table 00000Read 00001CopyTo Data CopyFrom Extra 00011Add Data Print 00101Stop 00110Extra Data10 LabelAddress Extra00110
Pass 1: Create a symbol table 00000Read 00001CopyTo Data CopyFrom Extra 00011Add Data Print 00101Stop 00110Extra Data10 LabelAddress Extra00110
Pass 1: Create a symbol table 00000Read 00001CopyTo Data CopyFrom Extra 00011Add Data Print 00101Stop 00110Extra Data10 LabelAddress Extra00110 Data100111
Pass 2: "Assemble" the machine code 00000Read 00001CopyTo Data CopyFrom Extra 00011Add Data Print 00101Stop 00110Extra Data10 LabelAddress Extra00110 Data Machine Code InstructionOp Code CopyFrom000 CopyTo001 Add010 Subtract011 Read100 Print101 IfNegGoto110 Stop111 1
Pass 2: "Assemble" the machine code 00000Read 00001CopyTo Data CopyFrom Extra 00011Add Data Print 00101Stop 00110Extra Data10 LabelAddress Extra00110 Data Machine Code InstructionOp Code CopyFrom000 CopyTo001 Add010 Subtract011 Read100 Print101 IfNegGoto110 Stop111 2
Pass 2: "Assemble" the machine code 00000Read 00001CopyTo Data CopyFrom Extra 00011Add Data Print 00101Stop 00110Extra Data10 LabelAddress Extra00110 Data Machine Code InstructionOp Code CopyFrom000 CopyTo001 Add010 Subtract011 Read100 Print101 IfNegGoto110 Stop111 3
Pass 2: "Assemble" the machine code 00000Read CopyTo Data CopyFrom Extra 00011Add Data Print 00101Stop 00110Extra Data10 LabelAddress Extra00110 Data Machine Code InstructionOp Code CopyFrom000 CopyTo001 Add010 Subtract011 Read100 Print101 IfNegGoto110 Stop111 4
Pass 2: "Assemble" the machine code 00000Read CopyTo Data CopyFrom Extra 00011Add Data Print 00101Stop 00110Extra Data10 LabelAddress Extra00110 Data Machine Code InstructionOp Code CopyFrom000 CopyTo001 Add010 Subtract011 Read100 Print101 IfNegGoto110 Stop111 5
Pass 2: "Assemble" the machine code 00000Read CopyTo Data CopyFrom Extra 00011Add Data Print 00101Stop 00110Extra Data10 LabelAddress Extra00110 Data Machine Code InstructionOp Code CopyFrom000 CopyTo001 Add010 Subtract011 Read100 Print101 IfNegGoto110 Stop111 6
Pass 2: "Assemble" the machine code 00000Read CopyTo Data CopyFrom Extra 00011Add Data Print 00101Stop 00110Extra Data10 LabelAddress Extra00110 Data Machine Code InstructionOp Code CopyFrom000 CopyTo001 Add010 Subtract011 Read100 Print101 IfNegGoto110 Stop111 7
Pass 2: "Assemble" the machine code 00000Read CopyTo Data CopyFrom Extra 00011Add Data Print 00101Stop 00110Extra Data10 LabelAddress Extra00110 Data Machine Code InstructionOp Code CopyFrom000 CopyTo001 Add010 Subtract011 Read100 Print101 IfNegGoto110 Stop111 8
Pass 2: "Assemble" the machine code 00000Read CopyTo Data CopyFrom Extra 00011Add Data Print 00101Stop 00110Extra Data10 LabelAddress Extra00110 Data Machine Code InstructionOp Code CopyFrom000 CopyTo001 Add010 Subtract011 Read100 Print101 IfNegGoto110 Stop111 9
Pass 2: "Assemble" the machine code 00000Read CopyTo Data CopyFrom Extra 00011Add Data Print 00101Stop 00110Extra Data10 LabelAddress Extra00110 Data Machine Code InstructionOp Code CopyFrom000 CopyTo001 Add010 Subtract011 Read100 Print101 IfNegGoto110 Stop111 10
Pass 2: "Assemble" the machine code 00000Read CopyTo Data CopyFrom Extra 00011Add Data Print 00101Stop 00110Extra Data10 LabelAddress Extra00110 Data Machine Code InstructionOp Code CopyFrom000 CopyTo001 Add010 Subtract011 Read100 Print101 IfNegGoto110 Stop111 11
Pass 2: "Assemble" the machine code 00000Read CopyTo Data CopyFrom Extra 00011Add Data Print 00101Stop 00110Extra Data10 LabelAddress Extra00110 Data Machine Code InstructionOp Code CopyFrom000 CopyTo001 Add010 Subtract011 Read100 Print101 IfNegGoto110 Stop111 12
Pass 2: "Assemble" the machine code 00000Read CopyTo Data CopyFrom Extra Add Data Print 00101Stop 00110Extra Data10 LabelAddress Extra00110 Data Machine Code InstructionOp Code CopyFrom000 CopyTo001 Add010 Subtract011 Read100 Print101 IfNegGoto110 Stop111 13
Pass 2: "Assemble" the machine code 00000Read CopyTo Data CopyFrom Extra Add Data Print 00101Stop 00110Extra Data10 LabelAddress Extra00110 Data Machine Code InstructionOp Code CopyFrom000 CopyTo001 Add010 Subtract011 Read100 Print101 IfNegGoto110 Stop111 14
Pass 2: "Assemble" the machine code 00000Read CopyTo Data CopyFrom Extra Add Data Print 00101Stop 00110Extra Data10 LabelAddress Extra00110 Data Machine Code InstructionOp Code CopyFrom000 CopyTo001 Add010 Subtract011 Read100 Print101 IfNegGoto110 Stop111 15
Pass 2: "Assemble" the machine code 00000Read CopyTo Data CopyFrom Extra Add Data Print 00101Stop 00110Extra Data10 LabelAddress Extra00110 Data Machine Code InstructionOp Code CopyFrom000 CopyTo001 Add010 Subtract011 Read100 Print101 IfNegGoto110 Stop111 16
Pass 2: "Assemble" the machine code 00000Read CopyTo Data CopyFrom Extra Add Data Print 00101Stop 00110Extra Data10 LabelAddress Extra00110 Data Machine Code InstructionOp Code CopyFrom000 CopyTo001 Add010 Subtract011 Read100 Print101 IfNegGoto110 Stop111 17
Pass 2: "Assemble" the machine code 00000Read CopyTo Data CopyFrom Extra Add Data Print 00101Stop 00110Extra Data10 LabelAddress Extra00110 Data Machine Code InstructionOp Code CopyFrom000 CopyTo001 Add010 Subtract011 Read100 Print101 IfNegGoto110 Stop111 18
Pass 2: "Assemble" the machine code 00000Read CopyTo Data CopyFrom Extra Add Data Print 00101Stop 00110Extra Data10 LabelAddress Extra00110 Data Machine Code InstructionOp Code CopyFrom000 CopyTo001 Add010 Subtract011 Read100 Print101 IfNegGoto110 Stop111 19
Pass 2: "Assemble" the machine code 00000Read CopyTo Data CopyFrom Extra Add Data Print 00101Stop 00110Extra Data10 LabelAddress Extra00110 Data Machine Code InstructionOp Code CopyFrom000 CopyTo001 Add010 Subtract011 Read100 Print101 IfNegGoto110 Stop111 20
Pass 2: "Assemble" the machine code 00000Read CopyTo Data CopyFrom Extra Add Data Print 00101Stop 00110Extra Data10 LabelAddress Extra00110 Data Machine Code InstructionOp Code CopyFrom000 CopyTo001 Add010 Subtract011 Read100 Print101 IfNegGoto110 Stop111 21
Pass 2: "Assemble" the machine code 00000Read CopyTo Data CopyFrom Extra Add Data Print 00101Stop 00110Extra Data10 LabelAddress Extra00110 Data Machine Code InstructionOp Code CopyFrom000 CopyTo001 Add010 Subtract011 Read100 Print101 IfNegGoto110 Stop111 22
Pass 2: "Assemble" the machine code 00000Read CopyTo Data CopyFrom Extra Add Data Print Stop 00110Extra Data10 LabelAddress Extra00110 Data Machine Code InstructionOp Code CopyFrom000 CopyTo001 Add010 Subtract011 Read100 Print101 IfNegGoto110 Stop111 23
Pass 2: "Assemble" the machine code 00000Read CopyTo Data CopyFrom Extra Add Data Print Stop 00110Extra Data10 LabelAddress Extra00110 Data Machine Code InstructionOp Code CopyFrom000 CopyTo001 Add010 Subtract011 Read100 Print101 IfNegGoto110 Stop111 24
Pass 2: "Assemble" the machine code 00000Read CopyTo Data CopyFrom Extra Add Data Print Stop 00110Extra Data10 LabelAddress Extra00110 Data Machine Code InstructionOp Code CopyFrom000 CopyTo001 Add010 Subtract011 Read100 Print101 IfNegGoto110 Stop111 25
Pass 2: "Assemble" the machine code 00000Read CopyTo Data CopyFrom Extra Add Data Print Stop 00110Extra Data10 LabelAddress Extra00110 Data Machine Code InstructionOp Code CopyFrom000 CopyTo001 Add010 Subtract011 Read100 Print101 IfNegGoto110 Stop111 26
Pass 2: "Assemble" the machine code 00000Read CopyTo Data CopyFrom Extra Add Data Print Stop Extra Data10 LabelAddress Extra00110 Data Machine Code InstructionOp Code CopyFrom000 CopyTo001 Add010 Subtract011 Read100 Print101 IfNegGoto110 Stop111 27
Pass 2: "Assemble" the machine code 00000Read CopyTo Data CopyFrom Extra Add Data Print Stop Extra Data10 LabelAddress Extra00110 Data Machine Code InstructionOp Code CopyFrom000 CopyTo001 Add010 Subtract011 Read100 Print101 IfNegGoto110 Stop111 28
Pass 2: "Assemble" the machine code 00000Read CopyTo Data CopyFrom Extra Add Data Print Stop Extra Data10 LabelAddress Extra00110 Data Machine Code Literal integer values are translated into binary using the signed magnitude representation 29
Pass 2: "Assemble" the machine code 00000Read CopyTo Data CopyFrom Extra Add Data Print Stop Extra Data10 LabelAddress Extra00110 Data Machine Code 5 10 = in 8 bit signed magnitude representation 30
Pass 2: "Assemble" the machine code 00000Read CopyTo Data CopyFrom Extra Add Data Print Stop Extra Data10 LabelAddress Extra00110 Data Machine Code 5 10 = in 8 bit signed magnitude representation 31
Pass 2: "Assemble" the machine code 00000Read CopyTo Data CopyFrom Extra Add Data Print Stop Extra Data10 LabelAddress Extra00110 Data Machine Code 32
Pass 2: "Assemble" the machine code 00000Read CopyTo Data CopyFrom Extra Add Data Print Stop Extra Data LabelAddress Extra00110 Data Machine Code 33
Pass 2: "Assemble" the machine code 00000Read CopyTo Data CopyFrom Extra Add Data Print Stop Extra Data LabelAddress Extra00110 Data Machine Code This sequence of values, stored in a file, forms the executable for this program.
Observations This is a very mechanical process. The program that does this job is called an assembler. Each different computer architecture (Intel Pentium, PowerPC, IBM Cell, etc.) has its own assembly language. The instructions in assembly language correspond one-to-one with instructions in the target architecture's machine language. An executable for a program consists of a file containing the machine language instructions for the program.