Upload
sukanya-cu
View
680
Download
2
Embed Size (px)
Citation preview
1
Machine-Dependent Assembler Features
Machine-dependent assembler features
2
Machine dependent assembler features
Instruction formats and addressing modes Program relocation• Generate an object program that can be
placed anywhere in the physical memory.
2
Machine-dependent assembler features
3
Review of instruction formats
SIC Format
Format 1 (1 byte)
Format 2 (2 bytes)
Format 3 (3 bytes)
Format 4 (4 bytes)
r2r1op448
dispepbxinop
121111116
addressepbxinop
201111116
opcode x address
8 1 15
op8 SIC/XE
Machine-dependent assembler features
4
Review of instruction formats (cont’d)
Register-to-register instructionsop r1,r2• Register-to-register instructions are shorter and do not
require another memory reference. Use register-to-register instructions instead of register-to-memory instructions whenever possible.
Extended format (4 bytes): +op• If the displacements required for both program-counter
relative and base relative addressing are too large to fit into a 3-byte instruction, then the 4-byte extended format must be used.
• The programmer has to specify this form of addressing when it is required.
3
Machine-dependent assembler features
5
Review of addressing modes
Immediate addressing: op #c; op #m• Using the immediate addressing, the operand is already present as part of the
instruction and need not be fetched from anywhere.• 55 LDA #3
Indirect addressing: op @m; op @c• The use of indirect addressing often avoids the need for another instruction.• 70 J @RETADR
PC-relative or Base-relative addressing: • Instructions that refer to memory are normally assembled using either
• the program-counter relative mode or • the base relative mode.
• The assembler directive BASE is used in conjunction with base relative addressing.
Index addressing: op m,X• 160 STCH BUFFER,X
Direct addressing:
Machine-dependent assembler features
6
Addressing modes for SIC/XEFlag bits
p bit=1: program-counter relative addressing mode
e bit=1: extended instruction format
Assembler language notationc indicates a constant between 0 and 4095.m indicates a memory address or a
constant value larger than 4095.
Note4 Format 4 instructionD Direct-addressing instructionA Assembler selects either program-
counter relative or base-relative modeS Compatible with instruction format for
standard SIC machine
4
Machine-dependent assembler features
7
“START 0”
It indicates a relocatable program.• The program will be translated exactly as if it
were to be loaded at machine address 0.
Machine-dependent assembler features
8
Register-to-register instructions
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.).
125RDREC CLEAR X B410
1
5
Machine-dependent assembler features
9
Register-to-memory instructionsMost 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.
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 4B101036125 RDREC CLEAR X
Machine-dependent assembler features
10
Register-to-memory instructions (cont’d)
If extended format is not specified, the assembler may first attempt to translate the instruction using program-counter relative addressing.
If the required displacement is out of range, the assembler then attempts to use base relative addressing.
If neither form of relative addressing is applicable, then the instruction cannot be properly assembled and the assembler must generate an error message.
6
Machine-dependent assembler features
11
Register-to-memory instructions (cont’d)
15 0006 CLOOP +JSUB RDREC 4B101036 ...
125 1036 RDREC CLEAR X B410
201111116
addressepbxinop
0000,0001,0000,0011,0110
100011010010
4B101036
Machine-dependent assembler features
12
A SIC/XE program (Fig. 2.5)
indirectaddressing
immediate operand
An assembler directive
4-byte instruction
a reloctable program
7
Machine-dependent assembler features
13
A SIC/XE program (cont’d)
register-to-register
instruction
Machine-dependent assembler features
14
A SIC/XE program (cont’d)
8
Machine-dependent assembler features
15
Program from Fig 2.5 with object code
Machine-dependent assembler features
16
Program from Fig 2.5 with object code (cont’d)
9
Machine-dependent assembler features
17
Program from Fig 2.5 with object code (cont’d)
Machine-dependent assembler features
18
Calculation for register-to-register instruction
125 1036 RDREC CLEAR X B410
150 1049 COMPR A,S A004
r2r1op448
0000000110110100
B410
r2r1op448
0100000010100000
A004
10
Machine-dependent assembler features
19
Displacement calculation for program-counter relative addressing
TA = (PC)+disp => disp = TA – (PC)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 0000FIRST 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.
dispepbxinop121111116
00000010110101001100010117202D
Machine-dependent assembler features
20
Displacement calculation for program-counter relative addressing (cont’d)
16 0006CLOOP+JSUB RDREC 4B101036...
40 0017 J CLOOP 3F2FEC
disp = TA-(PC) = 0006-001A= -0014 = (111111101100)2
dispepbxinop121111116
1111111011000100110011113F2FEC
using 2’s complement for negative numbers
11
Machine-dependent assembler features
21
Displacement calculation for base relative addressing
TA=(BASE)+disp=>disp = TA-(BASE)To compute displacements, the assembler must know the content of register B that must be specified by the programmer.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 features
22
Displacement calculation for base relative addressing (cont’d)
1050036 BUFFER RESB 4096160104E STCH BUFFER,X 57C003
dispepbxinop121111116
0000,0000,00110011110101,01 57C003
1. Try indexed and program-counter relative addressingdisp = TA – (PC)=0036 – 1050 = -101A16<-2048—out of range2. Try indexed and base relative addressingdisp = TA – (BASE)=0036 – 0033 =000316
12
Machine-dependent assembler features
23
Calculation for immediate addressing
Convert the immediate operand to its internal representation and insert it into the instruction.
55 0020 LDA #3 010003
133 103C +LDT #4096 75101000
dispepbxinop121111116
000000000011000010000000010003
201111116
addressepbxinop
0000,0001,0000,0000,0000
100010011101
75101000
Machine-dependent assembler features
24
Calculation for immediate addressing (cont’d)
20 0003 LDB #LENGTH 69202D...
100 0033 LENGTH RESW 1
Line 20 combines the program-counter relative addressing with immediate addressing.
disp = TA – (PC)=0033-0006=002D
dispepbxinop121111116
0000,0010,110101001001101069202D
the value of the symbol LENGTH is its address.
13
Machine-dependent assembler features
25
Calculation for indirect addressing
70 002A J @RETADR 3E2003...
95 0030 RETADR RESW 1
Line 70 combines the program-counter relative addressing with indirect addressing.
disp = TA-(PC)=0030-002D=0003dispepbxinop
121111116
0000,0000,00110100010011113E2003
Machine-dependent assembler features
26
Program relocation
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.
The task of adjusting object programs so they may be placed in arbitrary memory locations is called relocation.
14
Machine-dependent assembler features
27
Relocation problem
must be modified
No matter where the program is loaded, RDREC is always 1036 bytes past the starting address of the program.
Solution
•The assembler insert the address of RDREC relative to the start of the program.
•The assembler also produces a command for the loader, instructing it to add the beginning address of the program to the address field in the JSUB instruction at load time.
Machine-dependent assembler features
28
What parts of the program need to be modified?
The parts of the object program that require modification at load time are those that specify direct addresses.No modifications are needed for the operands • that are not memory references, or• specified by
• the program-counter addressing, and• base relative addressing.Relocatable is one advantage of relative addressing.
15
Machine-dependent assembler features
29
Relocatable program
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 features
30
The modification record
The assembler produces a modification record describing the address and length of an address field to be modified.The loader will add the beginning address of the loaded program to the address field specified by a modification record.
16
Machine-dependent assembler features
31
Modification record formatCol. 1 MCol. 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-
bytesIf the field contains an odd number of half-bytes, the startinglocation begins in the middle of the first byte.
15 0006 CLOOP +JSUB RDREC 4B101036M0000070535 0013 +JSUB WRREC 4B10105DM0000140565 0026 +JSUB WRREC 4B10105DM00002705
Machine-dependent assembler features
32
Object program with modification record
relocatable
same as the absolute program with starting address 0
modification records