0% found this document useful (0 votes)
25 views

Generate The Complete Object Program For Each Statement

generating object code for sic-xe machine

Uploaded by

srinivas
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
25 views

Generate The Complete Object Program For Each Statement

generating object code for sic-xe machine

Uploaded by

srinivas
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 7

1.

Generate the complete object program for each statement in the following SIC/XE program
(Jan 2006 – 14 marks)

SUM START 0000


FIRST LDX #0
LDA #0
+LDB #TABLE2
BASE TABLE2
LOOP ADD TABLE, X
ADD TABLE2, X
TIX COUNT
JLT LOOP
+STA TOTAL
RSUB
COUNT RESW 1
TABLE RESW 2000
TABLE2 RESW 2000
TOTAL RESW 1
END FIRST

Assume below opcodes (all in hexadecimal)

LDX – 04 LDA – 00 ADD – 18 TIX – 2C JLT – 38 STA – 0C RSUB – 4C LDB - 68

Line No.
5
LOCCTR SOURCE STATMENTS
SUM
cks
START 0000
OBJECT CODE
---------
10 0000 FIRST LDX #0 050000
15 0003 LDA #0 010000
20 0006 +LDB #TABLE2 69101790
25 --------- BASE TABLE2 -----------
30 000A LOOP ADD TABLE, X 1BA013
35 000D ADD TABLE2, X 1BC000
40 0010 TIX COUNT 2F200A
45 0013 JLT LOOP 3B2FF4
50 0016 +STA TOTAL 0F102F20
55 001A RSUB 4F0000
60 001D COUNT RESW 1 ---------
65 0020 TABLE RESW 2000 ---------
70 1790 TABLE2 RESW 2000 ---------
75 2F00 TOTAL RESW 1 ---------
80 2F03 END FIRST ---------
The assembly of instruction with immediate addressing is to convert the immediate
operand to its internal representation and insert it into the instruction.

10 0000 FIRST LDX #0

1) The operand stored in the instruction is 000.


2) Bit i = 1 to indicate immediate addressing.
OPCODE (LDX) = 04 = 0000 0100
Target address of operand is = 000

OPCODE n i x b p e Disp (12 bit)


0000 01 0 1 0 0 0 0 0000 0000 0000
0 5 0 0 0 0

15 0003 LDA #0

OPCODE (LDX) = 00 = 0000 0000


Target address of operand is = 000

OPCODE n
0000 00 0
i
1
cks
x
0
b
0
p
0
e
0 0000
Disp (12 bit)
0000 0000
0 1 0 0 0 0

20 0006 +LDB #TABLE2


OPCODE (LDB) = 68 = 0110 1000
Target address of operand (TABLE2) is = 1790

In this case, the operand (TABLE2) is too large to fit into the 12-bit displacement
field, so the extended instruction format is called for. (If the operand were too large even
for this 20-bit address field, immediate addressing could not be used.).

OPCODE n i x b p e Disp (20 bit)


0110 10 0 1 0 0 0 1 0000 0001 0111 1001 0000
6 9 0 0 1 7 9 0
30 000A LOOP ADD TABLE, X
OPCODE (ADD) = 18 = 0001 1000
Target address of operand (TABLE) is = 0020

Note that the program counter is advanced after each instruction is fetched and before it
is executed. While ADD is executed, PC will contain the address of the next instruction
(000D), where TABLE (line 65) is assigned the address 0020.
The displacement we need in the instruction is DISP = TA-[PC] that is
20 – 0D = 13,
Target address = (PC) + disp = 000D + 13 = 20.

Note that bits x and p are set to 1 to indicate indexed and PC relative addressing

OPCODE n i x b p e Disp (12 bit)


0001 10 1 1 1 0 1 0 0000 0001 0110
1 B A 0 1 3

35 000D

cks
ADD TABLE2, X
OPCODE (ADD) = 18 = 0001 1000
Target address of operand (TABLE2) is = 1790
Note that the program counter is advanced after each instruction is fetched and before it is
executed. While ADD is executed, PC will contain the address of the next instruction (0010),
where TABLE2 (line 70) is assigned the address 1790.

The displacement we need in the instruction is DISP = TA-[PC] that is


= 1790 – 0010
= 1780, this resulting displacement
will no longer fit in the 12 bit field in the instruction. Therefore the resulting displacement must
be small enough to fit in the 12-bit field in the instruction. This means that the displacement must
be between 0 and 4095 (for base relative mode) or between –2048 and +2047 (for program-
counter relative mode).

According to the BASE statement, register B = 1790 (the address of TABLE2) during execution.
The address TABLE2 is 1790.
Thus the displacement in the instruction must be DISP = TA - [B]
= 1790 – 1790 = 0000.
Note that bits x and b are set to 1 to indicate indexed and base relative addressing.

OPCODE n i x b p e Disp (12 bit)


0001 10 1 1 1 1 0 0 0000 0000 0000
1 B C 0 0 0
40 0010 TIX COUNT

OPCODE (TIX) = 2C = 0010 1100


Target address of operand (COUNT) is = 001D

Note that the program counter is advanced after each instruction is fetched and before it
is executed. While TIX is executed, PC will contain the address of the next instruction
(0013), where COUNT (line 60) is assigned the address 001D.
The displacement we need in the instruction is DISP = TA - [PC] that is
= 001D – 0013
= 00A,
Target address = (PC) + disp = 0013 + 000A = 001D.

OPCODE n i x b p e Disp (12 bit)


0010 11 1 1 0 0 1 0 0000 0000 1010
2 F 2 0 0 A

45 0013 JLT LOOP


cks
OPCODE (JLT) = 38 = 0110 1000
Target address of operand (LOOP) is = 000A

Note that the program counter is advanced after each instruction is fetched and before it
is executed. While JLT is executed, PC will contain the address of the next instruction
(0016), where LOOP (line 30) is assigned the address 000A.
The displacement we need in the instruction is DISP = TA-[PC] that is
000A – 0016 = - 00C,
In SIC/XE the negative numbers are represented using 2’s complement therefore

- 00C = 0000 0000 1100

1111 1111 0011


+ 1
1111 1111 0100 = FF4

OPCODE n i x b p e Disp (12 bit)


0011 10 1 1 0 0 1 0 1111 1111 0100
3 B 2 F F 4
50 0016 +STA TOTAL

OPCODE (STA) = 0C = 0000 1100


Target address of operand (TOTAL) is = 2F20

In this case, the operand (TOTAL) is too large to fit into the 12-bit displacement
field, so the extended instruction format is called for. (If the operand were too large even
for this 20-bit address field, immediate addressing could not be used.).

OPCODE n i x b p e Disp (20 bit)


0000 11 1 1 0 0 0 1 0000 0010 1111 0010 0000
0 F 1 0 2 F 2 0

55 001A RSUB

OPCODE (RSUB) = 4C = 0100 1100

OPCODE n
0100 11 1
4 F
i
1 cks
x
0
b
0
0
p
0
e
0 0000
0
Disp (12 bit)
0000
0
0000
0

SYMTAB
LABEL VALUE
FIRST 0000
LOOP 000A
COUNT 001D
TABLE 0020
TABLE2 1790
TOTAL 2F00

OBJECT PROGRAM
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
H ^ S U M ^ 0 0 0 0 0 0 ^ 0 0 2 F 0 2

T^ 0000000 ^1D ^ 050000^010000^69101790^1BA013^1BC000^2F200A^3B2FF4^0F102F20^4F0000

E^000000
2. Generate the complete object program for each statement in the following SIC/XE program.
(JUNE 2010 14 MARKS)

Line No. LOCCTR SOURCE STATMENTS OBJECT CODE


5 WRREC START 105D ---------
10 105D CLEAR X B410
15 105F LDT LENGTH 7721A5
20 1062 WLOOP TD OUTPUT E32011
25 1065 JEQ WLOOP 332FFA
30 1068 LDCH BUFFER, X 53A00C
35 106B WD OUTPUT DF2008
40 106E TIXR T B850
45 1070 JLT WLOOP 3B2FEF
50 1073 RSUB 4F0000
55 1076 OUTPUT BYTE X’05’ 05
60 1077 BUFFER RESB 400 --------
65 1207 LENGTH RESW 2 --------
70 120D END WRREC --------

CLEAR – B4 LDT – 74 TD – E0 TIXR – B8 JLT – 38 LDCH – 50 RSUB – 4C


WD – DC X- 1 T-5

cks
3. Generate the complete object program for each statement in the following SIC/XE program
(Jan 2005 – 14 marks)

SUM START 0
FIRST CLEAR X
LDA #0
+LDB #TOTAL
BASE TOTAL
LOOP ADD TABLE, X
TIX COUNT
JLT LOOP
STA TOTAL
COUNT RESW 1
TABLE RESW 2000
TOTAL RESW 1
END FIRST

Assume below opcodes (all in hexadecimal)

CLEAR – B4 LDA – 00 ADD – 18 TIX – 2C JLT – 38 STA – 0C LDB - 68


Line No. LOCCTR SOURCE STATMENTS OBJECT CODE
5 SUM START 0 ---------
10 0000 FIRST CLEAR X B410
15 0002 LDA #0 0100000
20 0005 +LDB #TOTAL 69101788
25 -------- BASE TOTAL -----------
30 0009 LOOP ADD TABLE, X 1BA00C
35 000C TIX COUNT 2F2006
40 000F JLT LOOP 3B2FF7
45 0012 STA TOTAL 0F4000
50 0015 COUNT RESW 1 --------
55 0018 TABLE RESW 2000 --------
60 1788 TOTAL RESW 1
65 178B END FIRST --------

cks

You might also like