2. 1.Explain the SIC Machine Architecture.
2. Explain the SIC/ XE Machine Architecture.
3.Write an algorithm for pass1 and pass2 of assemblers and explain.
4.Explain the Fallowing1.LDA 2.Jsub 3.TIX 4.Symbol Table
5.Forward reference.
5. Define system software,. Differentiate system software and
application software with examples
6.What is an Assembler directive? Explain the fallowing directive
with example. (1).START (2).BYTE (3).WORD (4).RESB
System Programming
5. Assembler Directives
Assembler directives are pseudo instructions
◦ They will not be translated into machine instructions.
◦ They only provide instruction/direction/information to
the assembler.
Basic assembler directives :
◦ START :
Specify name and starting address for the program
Ex: COPY START 1000
◦ END :
Indicate the end of the source program, and (optionally)
the first executable instruction in the program.
Ex: END FIRST
BLDEA'S CET MCA
System Programming
6. Assembler Directives
(cont’d)
◦ BYTE :
Generate character or hexadecimal constant, occupying as
many bytes as needed to represent the constant.
Ex: EOF BYTE C’EOF’
◦ WORD :
Generate one-word integer constant
Ex: THREE WORD 3
◦ RESB :
Reserve the indicated number of bytes for a data area
Ex: BUFFER RESB 4096
◦ RESW :
Reserve the indicated number of words for a data area
Ex: LENGTH RESW 1
BLDEA'S CET MCA
System Programming
11. • Convert mnemonic operation codes to their machine language
equivalents.
Ex: translate STL to 14(line 10).
• Convert symbolic operands to their equivalent machine addresses
Ex: translate RETADR to 1033(line 10).
• Build the machine instructions in the proper format.
• Convert the data constants specified in the source program into their
to internal machine representations
Ex: translate EOF to 454F46 (Line 80).
• Write the object program and the assembly listing .
Steps to Generate Object code
BLDEA'S CET MCA
System Programming
12. Object Program Format
Header
Col. 1 H
Col. 2~7 Program name
Col. 8~13 Starting address of object program (hex)
Col. 14-19 Length of object program in bytes (hex)
Text
Col.1 T
Col.2~7 Starting address for object code in this record (hex)
Col. 8~9 Length of object code in this record in bytes (hex)
Col. 10~69 Object code, represented in hexa (2 col. per byte)
End
Col.1 E
Col.2~7 Address of first executable instruction in object program
(hex)
BLDEA'S CET MCA
System Programming
14. Three Main Data Structures
Operation Code Table (OPTAB)
Symbol Table (SYMTAB)
Location Counter (LOCCTR)
BLDEA'S CET MCA
System Programming
15. OPTAB (operation code
table)
Content
◦ The mapping between mnemonic and machine
code. Also include the instruction format, available
addressing modes, and length information.
Characteristic
◦ Static table. The content will never change.
Implementation
◦ Array or hash table. Because the content will never
change, we can optimize its search speed.
In pass 1, OPTAB is used to look up and
validate mnemonics in the source program.
In pass 2, OPTAB is used to translate
mnemonics to machine instructions.
BLDEA'S CET MCA
System Programming
16. Instruction Op code Addressing
modes
Length
(bytes)
ADD m 18 D 3
LDA m 00 D 3
BLDEA'S CET MCA
System Programming
17. Symbol Table (SYMTAB)
Content
◦ Include the label name and value (address) for
each label in the source program.
◦ Include type and length information (e.g., int64)
◦ With flag to indicate errors (e.g., a symbol
defined in two places)
Characteristic
◦ Dynamic table (I.e., symbols may be inserted,
deleted, or searched in the table) , The content
will change.
Implementation
◦ Hash table can be used to speed up search
◦ Because variable names may be very similar
(e.g., LOOP1, LOOP2), the selected hash
function must perform well with such non-
random keys.
COPY 1000
FIRST 1000
CLOOP 1003
ENDFIL 1015
EOF 1024
THREE 102D
ZERO 1030
RETADR 1033
LENGTH 1036
BUFFER 1039
RDREC 2039
BLDEA'S CET MCA
System Programming
18. Location Counter (LOCCTR)
This variable can help in the assignment of
addresses.
It is initialized to the beginning address
specified in the START statement.
After each source statement is processed,
the length of the assembled instruction and
data area to be generated is added to
LOCCTR.
Thus, when we reach a label in the source
program, the current value of LOCCTR gives
the address to be associated with that label.
BLDEA'S CET MCA
System Programming
32. Instruction Format and Addressing
Mode
SIC/XE
◦ PC-relative or Base-relative addressing: op m
◦ Indirect addressing: op @m
◦ Immediate addressing: op #c
◦ Extended format: +op
m
◦ Index addressing: op
m,x
◦ Rule Table……..
BLDEA'S CET MCA
System Programming
33. Addressing
modes
Simple n=1 i=1
@Indirect
addressing
n=1 i=0
#Immediate
addressing
n=0 i=1
Indexed
addressing
x=1
Base Relative b=1 p=0
Program
counter
Relative
b=0 p=1
Direct b=0 p=1
OPCODE e Address
6 bits 12 bits
n i x b p
1 1 1 1 1 1
BLDEA'S CET MCA
System Programming
34. Format3 vs Format4
OPCODE e Address
6 bits 12 bits
n i x b p
1 1 1 1 1 0
OPCODE e Address
6 bits 20 bits
n i x b p
1 1 1 1 1 1
Format3
Format4
BLDEA'S CET MCA
System Programming
35. A Case of Object Code Generation
Figure 2.6, Line 10
STL RETADR 17 20 2D
STL opcode 14
The mode bit p=1, meaning PC relative
addressing mode.
OPCODE e Address
6 bits 12 bits
n i x b p
0001 01 0 0000 0010 11011 1 0 0 1
17 2D20
TA=(PC)+Displacement
Displacement = TA-(PC)
Displacement= RETADR - PC = 30-3 = 2D
1 1 1 1 1 1
bits
BLDEA'S CET MCA
System Programming
36. # Immediate Address Translation
Immediate addressing
◦ 25 000D COMP #0 290000
◦ COMP opcode 28
◦ 2 9 0 0 0 0
◦ 55 0020 LDA #3 010003
OPCODE e Addressn i x b p
0010 10 0 0000 0000 00000 1 0 0 0
OPCODE e Addressn i x b p
0000 00 0 (003)160 1 0 0 0 BLDEA'S CET MCA
System Programming
37. # Immediate Address Translation
◦ 133 103C +LDT #4096
75101000
OPCODE e Addressn i x b p
0111 01 1 0000 0001 0000 0000 0000160 1 0 0 0
7 5 1 0 1 0 0 0
BLDEA'S CET MCA
System Programming
38. # Immediate Address Translation
(conti….) Immediate addressing
◦ 12 0003 LDB #LENGTH 69202D
The immediate operand is the symbol LENGTH
The address of this symbol LENGTH is loaded into register B
LENGTH=0033 PC=0006
TA=(PC)+Displacement
Displacement = TA-(PC)
Displacement= LENGTH - PC = 0033-0006 = 2D
OPCODE e Addressn i x b p
0110 10 0 0000 0010 11010 1 0 0 1
BLDEA'S CET MCA
System Programming
0 2 D296
39. @ Indirect Address
Translation
Indirect addressing
◦ Target addressing is computed as usual
(PC-relative or BASE-relative)
◦ Only the n bit is set to 1
◦ 70 002A J @RETADR
3E2003
J=3C , TA=RETADR=0030
TA=(PC)+disp=0030=002D+disp
disp=0030-002D=3
OPCODE e Addressn i x b p
0011 11 0 (003)161 0 0 0 1
BLDEA'S CET MCA
System Programming
41. Base relative Address
12 bits displacement (0 ~ 4095)
Base register is under the control of the programmer.
◦ The programmer must tell the assembler what the base
register will contain during execution of program.
Assembler directive
BASE: tell the assembler what the base register will contain
NOBASE: tell the assembler that the contents of the base
register can no longer be used for addressing.
When based register can be relied upon, the assembler can use
base relative, otherwise only the PC-relative can be used
The assembler first choose PC-relative; if displacement is not
enough, choose base relative BLDEA'S CET MCA
System Programming
42. Base relative :ex1
12 0003 LDB #LENGTH 69202D
13 BASE LENGTH
: :
100 0033 LENGTH RESW 1
105 0036 BUFFER RESB 4096
: :
160 104E STCH BUFFER,X 57C003
165 1051 TIXR T B850
BLDEA'S CET MCA
System Programming
43. Base relative
PC-relative is no longer applicable
(0036)-(1051) = -4123 < (-2048)
LDB loads the address of LENGTH into base
register during execution
BASE directive explicitly informs the assembler
that the base register will contain the address
of LENGTH
System Programming
BLDEA'S CET MCA
System Programming
45. Base-Relative Addressing
Modes Base-relative
◦ Base register is under the control of the programmer
◦ 1056 STX LENGTH
1 3 4 0 0 0
OPCODE e Addressn i x b p
0001 00 0 0000 0000 00001 1 0 1 0
TA=(B)+Displacement
Displacement = TA-(B)
Displacement= LENGTH- B = 0033-0033= 0000
BLDEA'S CET MCA
System Programming
46. PC-relative v/s Base Relative
1. Programmer must specify the extended
format (4-byte) by using the prefix +
2. If not, assembler first attempts PC-relative
3. If the required displacement is out of range,
use
base relative addressing can be use
4. Otherwise, generate an error message
BLDEA'S CET MCA
System Programming
47. Register-register Address Translation
Mnemonic Number Use
A 0 Accumulator; used for arithmetic operati
X 1 Index register; used for addressing
L 2 Linkage register; JSUB
PC 8 Program counter
B 3 Base register
S 4 General working register
T 5 General working register
F 6 Floating-point accumulator (48 bits)
BLDEA'S CET MCA
System Programming
48. Register-register instruction object
code
Convert the mnemonic name to their
number equivalents
Register name (A, X, L, B, S, T, F, PC,
SW) and their values (0, 1, 2, 3, 4, 5,
6, 8, 9)
May implement in a separate table or
preload the register names and values to
SYMTAB
BLDEA'S CET MCA
System Programming
49. OPCODE e RDREC (Address)n i x b p
0100 10 1 0000 0001 0000 0011 0110161 1 0 0 0
Program Relocation
+JSUB RDREC (Jump to the adress,1036)
opcode for JSUB =48
4 B 1 0 1 0 3 6
+JSUB WRREC (Jump to the adress,105D)
opcode for JSUB =48
OPCODE e WRREC(Address)n i x b p
0100 10 1 0000 0001 0000 0101 1101161 1 0 0 0
4 B 1 0 1 0 5 DBLDEA'S CET MCA
System Programming
51. Example Fig. 2.7
◦ Except for absolute address, the rest of the
instructions need not be modified
not a memory address (immediate addressing)
PC-relative, Base-relative
◦ The only parts of the program that require
modification at load time are those that specify
direct addresses
BLDEA'S CET MCA
System Programming
52. Relocatable Program
Modification record
◦ 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
BLDEA'S CET MCA
System Programming
60. Microsoft MASM Assembler
1.MASAM assembler is written for Pentium and other x86
systems.
2.Since x86 system views memory as a collection of
segments.
3.An MASM assembler language program is written as a
collection of segments.
4.Each segment is defined as belonging to a particular
class: CODE, DATA, CONST, STACK
System Programming
61. Microsoft MASM Assembler
SEGMENT
◦ a collection segments, each segment is defined as
belonging to a particular class, CODE, DATA,
CONST, STACK
◦ registers: CS (code), SS (stack), DS (data), ES, FS,
GS
System Programming
62. Microsoft MASM Assembler
Jump instructions are assembled in 2 different ways:
1.Near jump: jump to a target in the same code segment o
2- or 3-byte instruction
Ex:JMP SHORT TARGET
2. Far jump: jump to a target in a different code segment o
5-byte instruction
EX:JMP FAR PTR TARGET
Jump with forward reference
MASM assumes that a forward jump is a near jump
If it is a far jump, programmer must tell the assembler
E.g. JMP FAR PTR TARGET
System Programming
63. Sun Sparc Assembler
SPARC (Scalable Processor Architecture) IS originally developed
by Sun Microsystems.
Sections
.TEXT //Executable instructions
.DATA //Initialized read/write data
.RODATA //Read only data
.BSS //uninitialized data areas
System Programming