You are on page 1of 16

Machine-Dependent

Assembler Features

Machine dependent assembler


features
z Instruction formats and addressing
modes
z Program relocation
• Generate an object program that can be
placed anywhere in the physical memory.

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

Review of instruction formats (cont’d)


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

Machine-dependent assembler 4
features

2
Review of addressing modes

z 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
z Indirect addressing: op @m; op @c
• The use of indirect addressing often avoids the need for another instruction.
• 70 J @RETADR
z 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.
z Index addressing: op m,X
• 160 STCH BUFFER,X
z Direct addressing:

Machine-dependent assembler 5
features

Addressing modes for SIC/XE


Flag bits
p bit=1: program-counter relative
addressing mode
e bit=1: extended instruction format

Assembler language notation


c indicates a constant between 0 and 4095.
m indicates a memory address or a
constant value larger than 4095.

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”

z 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 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

Register-to-memory instructions (cont’d)


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

Machine-dependent assembler 10
features

5
Register-to-memory instructions (cont’d)

15 0006 CLOOP +JSUB RDREC 4B101036


...
125 1036 RDREC CLEAR X B410

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

A SIC/XE program (Fig. 2.5)


An assembler directive
a reloctable program

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

A SIC/XE program (cont’d)

Machine-dependent assembler 14
features

7
Program from Fig 2.5 with object
code

Machine-dependent assembler 15
features

Program from Fig 2.5 with object


code (cont’d)

Machine-dependent assembler 16
features

8
Program from Fig 2.5 with object
code (cont’d)

Machine-dependent assembler 17
features

Calculation for register-to-


register instruction

125 1036 RDREC CLEAR X B410


8 4 4
op r1 r2
10110100 0001 0000
B410
150 1049 COMPR A,S A004

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

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


using 2’s complement for
negative numbers

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

Displacement calculation for base


relative addressing (cont’d)

1050036 BUFFER RESB 4096


160104E STCH BUFFER,X 57C003

1. Try indexed and program-counter relative addressing


disp = TA – (PC)=0036 – 1050 = -101A16<-2048—out of range
2. Try indexed and base relative addressing
disp = TA – (BASE)=0036 – 0033 =000316
6 1 1 1 1 1 1 12
op n i x b p e disp
0101,0 1 1 1 1 0 0 0000,0000,0011
1 57C003

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

Calculation for immediate


addressing (cont’d)
the value of the symbol LENGTH is its address.
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
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

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=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

must be modified •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 27
features

What parts of the program need


to be modified?

z The parts of the object program that require


modification at load time are those that
specify direct addresses.
z 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.
Machine-dependent assembler 28
features

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

The modification record


z The assembler produces a modification
record describing the address and length
of an address field to be modified.
z The loader will add the beginning
address of the loaded program to the
address field specified by a modification
record.

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.

15 0006 CLOOP +JSUB RDREC 4B101036


M00000705
35 0013 +JSUB WRREC 4B10105D
M00001405
65 0026 +JSUB WRREC 4B10105D
M00002705
Machine-dependent assembler 31
features

Object program with


modification record

relocatable

same as the absolute program with starting


address 0

modification records

Machine-dependent assembler 32
features

16

You might also like