Assemblers: Source Program Assembler Object Code Executable Code
Assemblers: Source Program Assembler Object Code Executable Code
http://www.intel.com/multi-core/demos.htm
Source Program Object Code
Assembler
Outline
2.1 Basic Assembler Functions
A simple SIC assembler Assembler tables and logic
Translation functions
Translate STL to 14. Translate RETADR to 1033. Build the machine instructions in the proper format (,X). Translate EOF to 454F46. Write the object program and assembly listing.
10
11
12
8 opcode
1 x
15 address m
(54)16
1 (001)2
(039)16
14
15
16
17
18
Build the machine instructions in the proper format Convert the data constants to internal machine representations Write the object program and the assembly listing
19
Pass 2
Assemble instructions (op code from OP table, address from SYMBOL table). Generate data values defined by BYTE, WORD. Perform processing of assembler directives not done during Pass 1. 20 Write the OP (Fig. 2.3) and the assembly listing (Fig. 2.2).
22
23
24
Pass 1
25
26
Pass 2
27
else if (found symbol==RSUB|| found symbol== || found symbol==) store 0 as operand address else store 0 as operand address set error flag assemble the object code inst.
28
Immediate operands
Adding the prefix # to operand (lines 12, 25, 55, 133).
Extended format
Adding the prefix + to OP code (lines 15, 35, 65).
30
31
32
33
Address translation
Most register-memory instructions use program counter relative or base relative addressing Format 3: 12-bit disp (address) field
PC-relative: -2048~2047 Base-relative: 0~4095
Register-register instructions
CLEAR & TIXR, COMPR
36
37
38
+OP, e=1 n=1, i=1, OPcode+3, @m, n=1, i=0, OPcode+2, #C, n=0, i=1, OPcode+1, xbpe 2: PC-relative 4: base-relative 8: index (m,X) 1: extended
39
0006 - 001A = disp = -14 Base (B), LDB #LENGTH, BASE LENGTH
160 104E STCH BUFFER, X 57C003
Extended instruction
15 0006 CLOOP +JSUB RDREC 4B101036
Immediate instruction
55 133 0020 103C LDA +LDT #3 #4096 010003 75101000
41
42
43
44
45
RDREC
46
WRREC
47
2.3.1 Literals
The difference between literal operands and immediate operands
=, # Immediate addressing, the operand value is assembled as part of the machine instruction, no memory reference. With a literal, the assembler generates the specified value as a constant at some other memory location. The address of this generated constant is used as the TA for the machine instruction, using PC-relative or base-relative addressing with memory reference.
Literal pools
At the end of the program (Fig. 2.10). Assembler directive LTORG, it creates a literal pool that contains all of the literal operands used since the previous
48
49
RDREC
50
WRREC
51
2.3.1 Literals
When to use LTORG (page 69, 4th paragraph)
The literal operand would be placed too far away from the instruction referencing. Cannot use PC-relative addressing or Base-relative addressing to generate Object Program.
52
2.3.1 Literals
Allow literals that refer to the current value of the location counter.
Such literals are sometimes useful for loading base registers. LDB =* ; register B=beginning address of statement=current LOC BASE * ; for base relative addressing
53
2.3.1 Literals
Literal table (LITTAB)
Contains the literal name (=CEOF), the operand value (454F46) and length (3), and the address (002D). Organized as a hash table. Pass 1, the assembler creates or searches LITTAB for the specified literal name. Pass 1 encounters a LTORG statement or the end of the program, the assembler makes a scan of the literal table. Pass 2, the operand address for use in generating OC is obtained by searching LITTAB.
54
56
ORG is used
http://home.educities.edu.tw/wanker742126/index.html SYMBOL is 6-byte, VALUE is 3-byte, and FLAGS is 2-byte.
57
Use LDA VALUE, X to fetch the VALUE field form the table entry indicated by the contents of register X.
58
59
Need 2 passes
60
1 1 1 1
Forward reference
Need 3 passes
2.3.3 Expressions
Allow arithmetic expressions formed
Using the operators +, -, , /. Division is usually defined to produce an integer result. Expression may be constants, user-defined symbols, or special terms. 106 1036 BUFEND EQU * Gives BUFEND a value that is the address of the next byte after the buffer area.
2.3.3 Expressions
107 1000 MAXLEN EQU BUFEND-BUFFER Both BUFEND and BUFFER are relative terms. The expression represents absolute value: the difference between the two addresses. Loc =1000 (Hex) The value that is associated with the symbol that appears in the source statement. BUFEND+BUFFER, 100-BUFFER, 3*BUFFER represent neither absolute values nor locations.
63
Program blocks
Refer to segments of code that are rearranged within a single object program unit.
Control sections
Refer to segments of code that are translated into independent object program units.
64
Main
66
RDREC
67
WRREC
68
70
71
72
73
Figure 2.13
Reflect the starting address of the block as well as the relative location of the code within the block.
Figure 2.14
Loader simply loads the object code from each record at the dictated. CDATA(1) & CBLKS(1) are not actually present in OP.
74
75
76
77
79
80
81
The LOC of all control section is started form 0 RDREC is an external reference. The assembler has no idea where the control section containing RDREC will be loaded, so it cannot assemble the address. The proper address to be inserted at load time. Must use extended format instruction for external reference (M records are needed).
190 0028 MAXLEN WORD BUFEND-BUFFER
82
83
84
85
87
89
90
The main problems to assemble a program in one pass involves forward references.
91
92
93
94
95
96
97
98
100
WRREC
101
102
Need 3 passes!
103
104
105
106
107
108