SP1.2 Sic
SP1.2 Sic
Tzong-Jye Liu
Department of Information Engineering and Computer Science
Feng Chia University
tjliu@fcu.edu.tw
Outline
System Programming 2
Simplified Instructional Computer (SIC)
System Programming 3
n Memory
n 8-bit bytes
n 3 consecutive bytes form a word
n Addressed by the lowest number byte
n 215 (32768) bytes in the computer memory
A word (3 bytes)
…
0 1 2 3 4 5 6
n SIC does not have any stack. It uses the linkage register to store the
return address.
n It is difficult to write the recursive program. A programmer has to
maintain memory for return addresses when he write more than one
layer of function call.
System Programming 5
n Data formats
n Characters
n 8-bit ASCII codes
n Integers
n 24-bit binary numbers
n 2’s complement for negative values
n -N Û 2n – N
n Ex: -1 Û 25 – 1 = (11111)2 ,if n = 5.
System Programming 6
SIC machine architecture
n Instruction formats
n 24-bits format
opcode (8) x address (15)
n Addressing modes
Mode Indication Target address calculation
直接定址 Direct x=0 TA = address
索引定址 Indexed x=1 TA = address + (X)
(ex: array)
System Programming 7
ALPHA RESW 1
System Programming 9
Programming examples
- Data movement
Direct Addressing
LDA FIVE Û (A) ¬ (FIVE)
STA ALPHA Û (ALPHA) ¬ (A)
In Memory
00000 00 00 0F 0C 00 0C 50 00 12 54 00 13 00 00 00 00
00010 00 05 5A 00
System Programming 10
SIC machine architecture
n Instruction set
n Arithmetic instruction
n Involve register A and a word in memory
n ADD, SUB, MUL, DIV
n Ex: ADD ALPHA Û (A) ¬ (A) + (ALPHA)
System Programming 11
Programming examples
- Arithmetic
n Page 15, Figure 1.3 (a)
(BETA) ß (ALPHA) + (INCR) – (ONE)
(DELTA) ß (GAMMA) + (INCR) – (ONE)
LDA ALPHA LOAD ALPHA INTO REGISTER A
ADD INCR ADD THE VALUE OF INCR
SUB ONE SUBTRACT 1
練習: STA BETA STORE IN BETA
(ALPHA) LDA
ß (BETA)
GAMMA* (GAMMA)
LOAD GAMMA + (INCR)
INTO REGISTER A
ADD INCR ADD THE VALUE OF INCR
(ALPHA) SUB
ß (BETA)
ONE + (GAMMA)
SUBTRACT 1 * (INCR)
STA DELTA STORE IN DELTA
.
.
ONE WORD 1 ONE-WORD CONSTANT
. ONE-WORD VARIABLES
ALPHA RESW 1
BETA RESW 1
GAMMA RESW 1
DELTA RESW 1
INCR RESW 1 System Programming 12
SIC machine architecture
n Instruction set
n Comparison instruction
n Involve register A and a word in memory
n Save result in the condition code (CC) of SW
n COMP
Ex: COMP ALPHA Û CC ¬(<,=,>) of (A)?(ALPHA)
n TIX m
X ß (X) + 1; (X) ? (m)
n Conditional jump instructions
n according to CC
n JLT, JEQ, JGT
n Test CC and jump accordingly
System Programming 13
Programming examples
-Looping and indexing
Index addressing mode
n Page 16, Figure 1.4 (a)
LDX ZERO INITIALIZE INDEX REGISTER TO 0
MOVECH LDCH STR1, X LOAD CHARACTER FROM STR1 INTO REG A
STCH STR2, X STORE CHARACTER INTO STR2
TIX ELEVEN ADD 1 TO INDEX, COMPARE RESULT TO 11
JLT MOVECH LOOP IF INDEX IS LESS THAN 11
.
.
STR1 BYTE C'TEST STRING' 11-BYTE STRING CONSTANT
STR2 RESB 11 11-BYTE VARIABLE
.
ZERO WORD 0
ELEVEN WORD 11
op x address
LDCH STR1, X LDCH x=1 STR1
X
TA (Target Address) = disp + (X) è STR1 + (X)
Reg. A[Rightmost Byte] ß (TA) STR1
Reg. A[Rightmost Byte] ß STR[X]
System Programming 14
Programming examples
- Indexing and looping
n Page 17, Figure 1.5 (a)
LDA ZERO INITIALIZE INDEX VALUE TO 0
STA INDEX
ADDLP LDX INDEX LOAD INDEX VALUE INTO REGISTER X
LDA ALPHA,X LOAD WORD FROM ALPHA INTO REGISTER A
ADD BETA,X ADD WORD FROM BETA
STA GAMMA,X STORE THE RESULT IN A WORD IN GAMMA
SIC 中只有 A 可以運算 LDA INDEX ADD 3 TO INDEX VALUE
ADD THREE
STA INDEX
(A) ? (K300) COMP K300 COMPARE NEW INDEX VALUE TO 300
JLT ADDLP LOOP IF INDEX IS LESS THAN 300
.
INDEX RESW 1 ONE-WORD VARIABLE FOR INDEX VALUE
. ARRAY VARIABLES—100 WORDS EACH
ALPHA RESW 100
BETA RESW 100
GAMMA RESW 100
. ONE-WORD CONSTANTS
ZERO WORD 0
K300 WORD 300
THREE WORD 3 1 word = 3 bytes
System Programming 15
System Programming 16
Simple I/O example for SIC
System Programming 17
n Instruction set
n Subroutine linkage instructions
n JSUB
n Jump and place the return address in register L
n RSUB
n Return to the address in L
System Programming 18
Programming examples
- Subroutine call and record input
n Page 20, Figure 1.7 (a)
JSUB READ CALL READ SUBROUTINE
L .
. SUBROUTINE TO READ 100-BYTE RCORD
READ LDX ZERO INITAILIZE INDEX REGISTER TO 0
RLOOP TD INDEV TEST INPUT DEVICE
JEQ RLOOP LOOP IF DEVICE IS BUSY
RD INDEV READ ONE BYTE INTO REGISTER A
STCH RECORD,X STORE DATA BYTE INTO RECORD
TIX K100 ADD 1 TO INDEX AND COMPARE TO 100
JLT RLOOP LOOP IF INDEX IS LESS THAN 100
RSUB EXIT FROM SUBROUTINE
.
INDEV BYTE X’F1’ INPUT DEVICE NUMBER
RECORD RESB 100 100-BYTE BUFFER FOR INPUT RECORD
. ONE-WORD CONSTANTS
ZERO WORD 0
K100 WORD 100
System Programming 19
n Registers S and T are only for storing data. They can not use for
accumulator
n Ex: ADDR S, A A ¬ A+S
COMPR X, T
System Programming 21
System Programming 22
SIC/XE machine architecture
n Instruction formats
n Since the memory used by SIC/XE may be 220 bytes,
the instruction format of SIC is not enough.
8 1 15
n Solutions opcode x address
n Use relative addressing
n Extend the address field to 20 bits
System Programming 24
SIC/XE machine architecture
n Addressing modes
n Bits x, b, p, e: how to calculate the target address
n relative, direct, and indexed addressing
modes (e = 0/1, format 3/4)
n Bits i and n: how to use the target address (TA)
Mode Indication Operand value
Immediate addressing n=0, i=1 TA: TA is used as the operand value,
no memory reference
Indirect addressing n=1, i=0 ((TA)): The word at the TA is fetched.
Value of TA is taken as the address of
the operand value
Simple addressing n=0, i=0 Standard SIC
n=1, i=1 (TA): TA is taken as the address of the
operand value
System Programming 25
System Programming 26
Immediate n=0, i=1
(B) = 006000
(PC) = 003000 Machine instruction Target Value loaded
(X) = 000090 Hex op n i x b p e disp/address Address into register A
. . 032600 000000 1 1 0 0 1 0 0110 0000 0000 3600 103000
.
.
.
. 練習: Simple + PC relative disp = 600 TA = (PC) + disp (3600)
02C300 000000 1 0 1 1 0 0 0011 0000 0000 6390 003030
3030 003600 03C300 000000 1 1Indirect
1 1 0 0 0011 disp = 0000
0000 300 TA= 6000+90+300
6390 ((6390))
00C303
. . Simple + index + base relative disp = 300 TA = (B) + disp + (X) (6390)
. .
. .
012C30 000000 0
022030 000000 1 10 00 00 11 00 000011000011
00110000
0000 2C30
3030 002C30
103000
3600 103000 Immediate
Indirect + PC relative disp
disp = C30
= 030 TA
TA==3000
(PC) – 3D0
+ disp 2C30
((3030))
. .
. .
. . 010030 000000 0 1 0 0 0 0 0000 0011 0000 30 000030
. . Immediate disp = 030 TA = disp 30
. .
6390 00C303
003600 000000 0 0 0 0 1 1 0110 0000 0000 3600 103000
. . Simple (SIC) disp = 3600 TA = disp (3600)
. .
. .
0310C303 000000 1 1 0 0 0 1 0000 1100 0011 0000 0011 C303 003030
C303 003030
Simple disp = C303 TA = disp (C303)
. .
. .
. . System Programming 27
System Programming 28
SIC/XE machine architecture
n Instruction set
n Refer to Appendix A for all instructions (Page 496)
n Notations for appendix
n A ¬ (m..m+2): move word begin at m to A
n P: privileged instruction
n X: instruction available only in SIC/XE
n C: condition code CC
System Programming 29
System Programming 34
Programming examples (SIC/XE)
- Arithmetic
System Programming 36
Programming examples (SIC/XE)
- Indexing and looping
n Page 17, Figure 1.5 (b)
LDS #3 INITIALIZE REGISTER S TO 3
LDT #300 INITIALIZE REGISTER T TO 300
LDX #0 INITIALIZE INDEX REGISTER TO 0
ADDLP LDA ALPHA, X LOAD WORD FROM ALPHA INTO REGISTER A
ADD BETA, X ADD WORD FROM BETA
STA GAMMA, X STORE THE RESULT IN A WORD IN GAMMA
ADDR S, X ADD 3 TO INDEX VALUE
COMPR X, T COMPARE NEW INDEX VALUE TO 300
JLT ADDLP LOOP IF INDEX VALUE IS LESS THAN 300
.
.
. ARRAY VARIABLES—100 WORDS EACH
ALPHA RESW 100
BETA RESW 100
GAMMA RESW 100
System Programming 37
System Programming 38
Programming examples (SIC/XE)
- SWAP the values of two variables
BEGIN START 1000
LDS #ALPHASWAP ALPHAS <-- Address of ALPHA
BETA
LDT #BETA Parameter?T <-- Address of BETA
JSUB SWAP
LDS #DATA1SWAP DATA1 DATA2
LDT #DATA2Parameters?
JSUB SWAP
END BEGIN
ALPHA WORD 1
BETA WORD 2
DATA1 WORD 3
DATA2 WORD 4
System Programming 39
System Programming 40