Presentation is loading. Please wait.

Presentation is loading. Please wait.

Translating Assembly Language to Machine Language.

Similar presentations


Presentation on theme: "Translating Assembly Language to Machine Language."— Presentation transcript:

1 Translating Assembly Language to Machine Language

2 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

3 Instructions and addresses 00000Read 00001CopyTo Data1 00010CopyFrom Extra 00011Add Data1 00100Print 00101Stop 00110Extra5 00111Data10 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

4 Pass 1: Create a symbol table 00000Read 00001CopyTo Data1 00010CopyFrom Extra 00011Add Data1 00100Print 00101Stop 00110Extra5 00111Data10 LabelAddress

5 Pass 1: Create a symbol table 00000Read 00001CopyTo Data1 00010CopyFrom Extra 00011Add Data1 00100Print 00101Stop 00110Extra5 00111Data10 LabelAddress Extra00110

6 Pass 1: Create a symbol table 00000Read 00001CopyTo Data1 00010CopyFrom Extra 00011Add Data1 00100Print 00101Stop 00110Extra5 00111Data10 LabelAddress Extra00110

7 Pass 1: Create a symbol table 00000Read 00001CopyTo Data1 00010CopyFrom Extra 00011Add Data1 00100Print 00101Stop 00110Extra5 00111Data10 LabelAddress Extra00110 Data100111

8 Pass 2: "Assemble" the machine code 00000Read 00001CopyTo Data1 00010CopyFrom Extra 00011Add Data1 00100Print 00101Stop 00110Extra5 00111Data10 LabelAddress Extra00110 Data100111 Machine Code InstructionOp Code CopyFrom000 CopyTo001 Add010 Subtract011 Read100 Print101 IfNegGoto110 Stop111 1

9 Pass 2: "Assemble" the machine code 00000Read 00001CopyTo Data1 00010CopyFrom Extra 00011Add Data1 00100Print 00101Stop 00110Extra5 00111Data10 LabelAddress Extra00110 Data100111 Machine Code InstructionOp Code CopyFrom000 CopyTo001 Add010 Subtract011 Read100 Print101 IfNegGoto110 Stop111 2

10 Pass 2: "Assemble" the machine code 00000Read 00001CopyTo Data1 00010CopyFrom Extra 00011Add Data1 00100Print 00101Stop 00110Extra5 00111Data10 LabelAddress Extra00110 Data100111 Machine Code InstructionOp Code CopyFrom000 CopyTo001 Add010 Subtract011 Read100 Print101 IfNegGoto110 Stop111 3

11 Pass 2: "Assemble" the machine code 00000Read100 00001CopyTo Data1 00010CopyFrom Extra 00011Add Data1 00100Print 00101Stop 00110Extra5 00111Data10 LabelAddress Extra00110 Data100111 Machine Code InstructionOp Code CopyFrom000 CopyTo001 Add010 Subtract011 Read100 Print101 IfNegGoto110 Stop111 4

12 Pass 2: "Assemble" the machine code 00000Read10000000 00001CopyTo Data1 00010CopyFrom Extra 00011Add Data1 00100Print 00101Stop 00110Extra5 00111Data10 LabelAddress Extra00110 Data100111 Machine Code InstructionOp Code CopyFrom000 CopyTo001 Add010 Subtract011 Read100 Print101 IfNegGoto110 Stop111 5

13 Pass 2: "Assemble" the machine code 00000Read10000000 00001CopyTo Data1 00010CopyFrom Extra 00011Add Data1 00100Print 00101Stop 00110Extra5 00111Data10 LabelAddress Extra00110 Data100111 Machine Code InstructionOp Code CopyFrom000 CopyTo001 Add010 Subtract011 Read100 Print101 IfNegGoto110 Stop111 6

14 Pass 2: "Assemble" the machine code 00000Read10000000 00001CopyTo Data1 00010CopyFrom Extra 00011Add Data1 00100Print 00101Stop 00110Extra5 00111Data10 LabelAddress Extra00110 Data100111 Machine Code InstructionOp Code CopyFrom000 CopyTo001 Add010 Subtract011 Read100 Print101 IfNegGoto110 Stop111 7

15 Pass 2: "Assemble" the machine code 00000Read10000000 00001CopyTo Data1001 00010CopyFrom Extra 00011Add Data1 00100Print 00101Stop 00110Extra5 00111Data10 LabelAddress Extra00110 Data100111 Machine Code InstructionOp Code CopyFrom000 CopyTo001 Add010 Subtract011 Read100 Print101 IfNegGoto110 Stop111 8

16 Pass 2: "Assemble" the machine code 00000Read10000000 00001CopyTo Data1001 00010CopyFrom Extra 00011Add Data1 00100Print 00101Stop 00110Extra5 00111Data10 LabelAddress Extra00110 Data100111 Machine Code InstructionOp Code CopyFrom000 CopyTo001 Add010 Subtract011 Read100 Print101 IfNegGoto110 Stop111 9

17 Pass 2: "Assemble" the machine code 00000Read10000000 00001CopyTo Data100100111 00010CopyFrom Extra 00011Add Data1 00100Print 00101Stop 00110Extra5 00111Data10 LabelAddress Extra00110 Data100111 Machine Code InstructionOp Code CopyFrom000 CopyTo001 Add010 Subtract011 Read100 Print101 IfNegGoto110 Stop111 10

18 Pass 2: "Assemble" the machine code 00000Read10000000 00001CopyTo Data100100111 00010CopyFrom Extra 00011Add Data1 00100Print 00101Stop 00110Extra5 00111Data10 LabelAddress Extra00110 Data100111 Machine Code InstructionOp Code CopyFrom000 CopyTo001 Add010 Subtract011 Read100 Print101 IfNegGoto110 Stop111 11

19 Pass 2: "Assemble" the machine code 00000Read10000000 00001CopyTo Data100100111 00010CopyFrom Extra 00011Add Data1 00100Print 00101Stop 00110Extra5 00111Data10 LabelAddress Extra00110 Data100111 Machine Code InstructionOp Code CopyFrom000 CopyTo001 Add010 Subtract011 Read100 Print101 IfNegGoto110 Stop111 12

20 Pass 2: "Assemble" the machine code 00000Read10000000 00001CopyTo Data100100111 00010CopyFrom Extra000 00011Add Data1 00100Print 00101Stop 00110Extra5 00111Data10 LabelAddress Extra00110 Data100111 Machine Code InstructionOp Code CopyFrom000 CopyTo001 Add010 Subtract011 Read100 Print101 IfNegGoto110 Stop111 13

21 Pass 2: "Assemble" the machine code 00000Read10000000 00001CopyTo Data100100111 00010CopyFrom Extra000 00011Add Data1 00100Print 00101Stop 00110Extra5 00111Data10 LabelAddress Extra00110 Data100111 Machine Code InstructionOp Code CopyFrom000 CopyTo001 Add010 Subtract011 Read100 Print101 IfNegGoto110 Stop111 14

22 Pass 2: "Assemble" the machine code 00000Read10000000 00001CopyTo Data100100111 00010CopyFrom Extra00000110 00011Add Data1 00100Print 00101Stop 00110Extra5 00111Data10 LabelAddress Extra00110 Data100111 Machine Code InstructionOp Code CopyFrom000 CopyTo001 Add010 Subtract011 Read100 Print101 IfNegGoto110 Stop111 15

23 Pass 2: "Assemble" the machine code 00000Read10000000 00001CopyTo Data100100111 00010CopyFrom Extra00000110 00011Add Data1 00100Print 00101Stop 00110Extra5 00111Data10 LabelAddress Extra00110 Data100111 Machine Code InstructionOp Code CopyFrom000 CopyTo001 Add010 Subtract011 Read100 Print101 IfNegGoto110 Stop111 16

24 Pass 2: "Assemble" the machine code 00000Read10000000 00001CopyTo Data100100111 00010CopyFrom Extra00000110 00011Add Data1 00100Print 00101Stop 00110Extra5 00111Data10 LabelAddress Extra00110 Data100111 Machine Code InstructionOp Code CopyFrom000 CopyTo001 Add010 Subtract011 Read100 Print101 IfNegGoto110 Stop111 17

25 Pass 2: "Assemble" the machine code 00000Read10000000 00001CopyTo Data100100111 00010CopyFrom Extra00000110 00011Add Data1010 00100Print 00101Stop 00110Extra5 00111Data10 LabelAddress Extra00110 Data100111 Machine Code InstructionOp Code CopyFrom000 CopyTo001 Add010 Subtract011 Read100 Print101 IfNegGoto110 Stop111 18

26 Pass 2: "Assemble" the machine code 00000Read10000000 00001CopyTo Data100100111 00010CopyFrom Extra00000110 00011Add Data1010 00100Print 00101Stop 00110Extra5 00111Data10 LabelAddress Extra00110 Data100111 Machine Code InstructionOp Code CopyFrom000 CopyTo001 Add010 Subtract011 Read100 Print101 IfNegGoto110 Stop111 19

27 Pass 2: "Assemble" the machine code 00000Read10000000 00001CopyTo Data100100111 00010CopyFrom Extra00000110 00011Add Data101000111 00100Print 00101Stop 00110Extra5 00111Data10 LabelAddress Extra00110 Data100111 Machine Code InstructionOp Code CopyFrom000 CopyTo001 Add010 Subtract011 Read100 Print101 IfNegGoto110 Stop111 20

28 Pass 2: "Assemble" the machine code 00000Read10000000 00001CopyTo Data100100111 00010CopyFrom Extra00000110 00011Add Data101000111 00100Print 00101Stop 00110Extra5 00111Data10 LabelAddress Extra00110 Data100111 Machine Code InstructionOp Code CopyFrom000 CopyTo001 Add010 Subtract011 Read100 Print101 IfNegGoto110 Stop111 21

29 Pass 2: "Assemble" the machine code 00000Read10000000 00001CopyTo Data100100111 00010CopyFrom Extra00000110 00011Add Data101000111 00100Print 00101Stop 00110Extra5 00111Data10 LabelAddress Extra00110 Data100111 Machine Code InstructionOp Code CopyFrom000 CopyTo001 Add010 Subtract011 Read100 Print101 IfNegGoto110 Stop111 22

30 Pass 2: "Assemble" the machine code 00000Read10000000 00001CopyTo Data100100111 00010CopyFrom Extra00000110 00011Add Data101000111 00100Print101 00101Stop 00110Extra5 00111Data10 LabelAddress Extra00110 Data100111 Machine Code InstructionOp Code CopyFrom000 CopyTo001 Add010 Subtract011 Read100 Print101 IfNegGoto110 Stop111 23

31 Pass 2: "Assemble" the machine code 00000Read10000000 00001CopyTo Data100100111 00010CopyFrom Extra00000110 00011Add Data101000111 00100Print10100000 00101Stop 00110Extra5 00111Data10 LabelAddress Extra00110 Data100111 Machine Code InstructionOp Code CopyFrom000 CopyTo001 Add010 Subtract011 Read100 Print101 IfNegGoto110 Stop111 24

32 Pass 2: "Assemble" the machine code 00000Read10000000 00001CopyTo Data100100111 00010CopyFrom Extra00000110 00011Add Data101000111 00100Print10100000 00101Stop 00110Extra5 00111Data10 LabelAddress Extra00110 Data100111 Machine Code InstructionOp Code CopyFrom000 CopyTo001 Add010 Subtract011 Read100 Print101 IfNegGoto110 Stop111 25

33 Pass 2: "Assemble" the machine code 00000Read10000000 00001CopyTo Data100100111 00010CopyFrom Extra00000110 00011Add Data101000111 00100Print10100000 00101Stop 00110Extra5 00111Data10 LabelAddress Extra00110 Data100111 Machine Code InstructionOp Code CopyFrom000 CopyTo001 Add010 Subtract011 Read100 Print101 IfNegGoto110 Stop111 26

34 Pass 2: "Assemble" the machine code 00000Read10000000 00001CopyTo Data100100111 00010CopyFrom Extra00000110 00011Add Data101000111 00100Print10100000 00101Stop111 00110Extra5 00111Data10 LabelAddress Extra00110 Data100111 Machine Code InstructionOp Code CopyFrom000 CopyTo001 Add010 Subtract011 Read100 Print101 IfNegGoto110 Stop111 27

35 Pass 2: "Assemble" the machine code 00000Read10000000 00001CopyTo Data100100111 00010CopyFrom Extra00000110 00011Add Data101000111 00100Print10100000 00101Stop11100000 00110Extra5 00111Data10 LabelAddress Extra00110 Data100111 Machine Code InstructionOp Code CopyFrom000 CopyTo001 Add010 Subtract011 Read100 Print101 IfNegGoto110 Stop111 28

36 Pass 2: "Assemble" the machine code 00000Read10000000 00001CopyTo Data100100111 00010CopyFrom Extra00000110 00011Add Data101000111 00100Print10100000 00101Stop11100000 00110Extra5 00111Data10 LabelAddress Extra00110 Data100111 Machine Code Literal integer values are translated into binary using the signed magnitude representation 29

37 Pass 2: "Assemble" the machine code 00000Read10000000 00001CopyTo Data100100111 00010CopyFrom Extra00000110 00011Add Data101000111 00100Print10100000 00101Stop11100000 00110Extra5 00111Data10 LabelAddress Extra00110 Data100111 Machine Code 5 10 = 00000101 2 in 8 bit signed magnitude representation 30

38 Pass 2: "Assemble" the machine code 00000Read10000000 00001CopyTo Data100100111 00010CopyFrom Extra00000110 00011Add Data101000111 00100Print10100000 00101Stop11100000 00110Extra500000101 00111Data10 LabelAddress Extra00110 Data100111 Machine Code 5 10 = 00000101 2 in 8 bit signed magnitude representation 31

39 Pass 2: "Assemble" the machine code 00000Read10000000 00001CopyTo Data100100111 00010CopyFrom Extra00000110 00011Add Data101000111 00100Print10100000 00101Stop11100000 00110Extra500000101 00111Data10 LabelAddress Extra00110 Data100111 Machine Code 32

40 Pass 2: "Assemble" the machine code 00000Read10000000 00001CopyTo Data100100111 00010CopyFrom Extra00000110 00011Add Data101000111 00100Print10100000 00101Stop11100000 00110Extra500000101 00111Data1000000000 LabelAddress Extra00110 Data100111 Machine Code 33

41 Pass 2: "Assemble" the machine code 00000Read10000000 00001CopyTo Data100100111 00010CopyFrom Extra00000110 00011Add Data101000111 00100Print10100000 00101Stop11100000 00110Extra500000101 00111Data1000000000 LabelAddress Extra00110 Data100111 Machine Code This sequence of values, stored in a file, forms the executable for this program.

42 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.


Download ppt "Translating Assembly Language to Machine Language."

Similar presentations


Ads by Google