Documente Academic
Documente Profesional
Documente Cultură
Assembler Features
Machine-dependent assembler 2
features
1
Review of instruction formats
8 1 15
z SIC Format
opcode x address
8 SIC/XE
z Format 1 (1 byte) op
8 4 4
z Format 2 (2 bytes) op r1 r2
6 1 11 1 1 1 12
z Format 3 (3 bytes)
op n i x b p e disp
6 1 11 1 1 1 20
z Format 4 (4 bytes)
op n i x b p e address
Machine-dependent assembler 3
features
Machine-dependent assembler 4
features
2
Review of addressing modes
Machine-dependent assembler 5
features
Note
4 Format 4 instruction
D Direct-addressing instruction
A Assembler selects either program-
counter relative or base-relative mode
S Compatible with instruction format for
standard SIC machine
Machine-dependent assembler 6
features
3
“START 0”
Machine-dependent assembler 7
features
Register-to-register instructions
z The translation of register-to-register
instructions must convert the register
mnemonics to numbers.
• The register mnemonics can be stored in a predefined
table, or
• in the SYMTAB.
• SYMTAB would be preloaded with the register names
(A,X, etc.) and their values (0, 1, etc.).
125 RDREC CLEAR X B410
1
Machine-dependent assembler 8
features
4
Register-to-memory instructions
z Most of register-to-memory instructions are assembled using
either
• program-counter relative addressing or
• TA=(PC)+displacement (12-bit)
• The displacement must be between –2048 and +2047.
• base relative addressing.
• TA=(BASE)+displacement (12-bit)
• The displacement must be between 0 to 4095.
z If the required displacement is too large, then the 4-byte
extended instruction format must be used.
• The programmer must specify the 4-byte format by adding the
prefix + to the operation code in the source statement.
15 CLOOP +JSUB RDREC 4B101036
125 RDREC CLEAR X
Machine-dependent assembler 9
features
Machine-dependent assembler 10
features
5
Register-to-memory instructions (cont’d)
6 1 1 1 1 1 1 20
op n i x b p e address
010010 1 1 0 0 0 1 0000,0001,0000,0011,01
10
4B101036
Machine-dependent assembler 11
features
4-byte
instruction
immediate
operand
indirect
addressing
Machine-dependent assembler 12
features
6
A SIC/XE program (cont’d)
register-to-
register
instruction
Machine-dependent assembler 13
features
Machine-dependent assembler 14
features
7
Program from Fig 2.5 with object
code
Machine-dependent assembler 15
features
Machine-dependent assembler 16
features
8
Program from Fig 2.5 with object
code (cont’d)
Machine-dependent assembler 17
features
8 4 4
op r1 r2
10100000 0000 0100
A004
Machine-dependent assembler 18
features
9
Displacement calculation for program-
counter relative addressing
z TA = (PC)+disp => disp = TA – (PC)
z The program counter is advanced after each instruction is
fetched and before it is executed.
• PC will contain the address of the next instruction.
10 0000 FIRST STL RETADR 17202D
...
95 0030 RETADR RESW 1
• After fetching the instruction in line 10, PC becomes 0003. Hence, disp=0030-
(PC)=0030-0003=002D.
• p bit is set to 1 to indicate program-counter relative addressing.
• Bits n and i are both set to 1, indicating neither indirect nor immediate
addressing.
6 1 1 1 1 1 1 12
op n i x b p e disp
000101 1 1 0 0 1 0 000000101101
17202D
Machine-dependent assembler 19
features
6 1 1 1 1 1 1 12
op n i x b p e disp
001111 1 1 0 0 1 0 111111101100
3F2FEC
Machine-dependent assembler 20
features
10
Displacement calculation for base
relative addressing
z TA=(BASE)+disp=>disp = TA-(BASE)
z To compute displacements, the assembler must know the content
of register B that must be specified by the programmer.
z The assembler directive “BASE” tells the assembler the content of
the base register B.
• 13 BASE LENGTH
• This statement informs the assembler that the base register will contain the
address of LENGTH.
• 12 LDB #LENGTH
• This statement stores the address of LENGTH to register B.
• When register B is used for another purpose, the programmer can use
the assembler directive “NOBASE” to inform the assembler that the
content of the base register can no longer be relied upon for
addressing.
Machine-dependent assembler 21
features
Machine-dependent assembler 22
features
11
Calculation for immediate
addressing
z Convert the immediate operand to its internal
representation and insert it into the instruction.
55 0020 LDA #3 010003
6 1 1 1 1 1 1 12
op n i x b p e disp
000000 0 1 0 0 0 0 000000000011
010003
133 103C +LDT #4096 75101000
6 1 1 1 1 1 1 20
op n i x b p e address
011101 0 1 0 0 0 1 0000,0001,0000,0000,00
00
75101000
Machine-dependent assembler 23
features
disp = TA – (PC)=0033-0006=002D
6 1 1 1 1 1 1 12
op n i x b p e disp
011010 0 1 0 0 1 0 0000,0010,1101
69202D
Machine-dependent assembler 24
features
12
Calculation for indirect
addressing
disp = TA-(PC)=0030-002D=0003
6 1 1 1 1 1 1 12
op n i x b p e disp
001111 1 0 0 0 1 0 0000,0000,0011
3E2003
Machine-dependent assembler 25
features
Program relocation
z The object program cannot be assigned
to a fixed address.
• To take full advantage of hardware, we must
be able to load programs into memory
wherever there is room for it.
z The task of adjusting object programs so
they may be placed in arbitrary memory
locations is called relocation.
Machine-dependent assembler 26
features
13
Relocation problem
No matter where the program is
loaded, RDREC is always 1036 bytes
past the starting address of the
program.
Solution
14
Relocatable program
z The assembler can identify for the loader
those parts of the object program that
need modification.
• An object program that contains the
information necessary to perform this kind of
modification is called a relocatable program.
Machine-dependent assembler 29
features
Machine-dependent assembler 30
features
15
Modification record format
Col. 1 M
Col. 2-7 Starting location of the address field to be modified,
relative to the beginning of the program
Col. 8-9 Length of the address field to be modified, in half-
bytes
If the field contains an odd number of half-bytes, the starting
location begins in the middle of the first byte.
relocatable
modification records
Machine-dependent assembler 32
features
16