CS303 System Software
Simplified Instructional Computers(SIC)
Programming Exercises
Dr. Dhanya P.M,
Associate Professor, DCS, RSET
Dr. Dhanya P.M, Associate Professor, Dept of CSE, RSET
Assembler directives
Assembler directives(pseudo instructions) are not translated
into machine instructions. Instead they provide instructions
to the assemblers.
START Specify the name and starting address of the program
END Indicate the end of source program and specify the
first executable instruction in the program
BYTE Generate character or hexadecimal constant,
occupying as many bytes as needed to represent the
constant.
WORD Generate integer constant
RESB Reserve the indicated number of bytes for a data
area.
RESW Reserve the indicated number of words for a data
area.
Dr. Dhanya P.M, Associate Professor, Dept of CSE, RSET
Examples for Assembler directives
COPY START 1000 Name of the program is COPY
The start of the program is 1000
END FIRST Indicates the end of the program
Starting address of the program is 1000
COPY START 1000 MEMORY
FIRST STL RETADR 1000 STL RETADR
JSUB RDREC 1003 JSUB RDREC
:
:
:
:
END FIRST
Dr. Dhanya P.M, Associate Professor, Dept of CSE, RSET
BYTE CONSTANTS
BYTE Generates character or hexadecimal constants CHARZ Z
BYTE CHARZ BYTE C’Z’ NUM1 F1
(one-byte character constant)
STR1 T
E
NUM1 BYTE X’F1’
S
(hexadecimal constant)
T
STR1 BYTE C’TEST STRING’
S
(eleven byte constant) T
R
I
N
G
Dr. Dhanya P.M, Associate Professor, Dept of CSE, RSET
WORD
WORD Generates integer constants
WORD ALPHA WORD 3
ONE WORD 1
BETA WORD 100
MEMORY
ALPHA 3
ONE 1
BETA 100
Dr. Dhanya P.M, Associate Professor, Dept of CSE, RSET
Reserve Byte and Reserve Word
MEMORY
RESB ALPHA RESB 1 ALPHA
BETA RESB 5 BETA
RESW RETADR RESW 1
RETADR2 RESW 2
RETADR
RETADR2
Dr. Dhanya P.M, Associate Professor, Dept of CSE, RSET
SIC Programming Example
Data movement- Move integer data from memory location FIVE to memory location
ALPHA. Also move character data from memory location CHARZ to memory location C1.
LDA FIVE load 5 into A
STA ALPHA store in ALPHA
LDCH CHARZ load ‘Z’ into A
STCH C1 store in C1
.
.
.
ALPHA RESW 1 reserve one word space
FIVE WORD 5 one word holding 5
CHARZ BYTE C’Z’ one-byte constant
C1 RESB 1 one-byte variable
Dr. Dhanya P.M, Associate Professor, Dept of CSE, RSET
Program to do the arithmetic operation
BETA =ALPHA+INCR-1 and DELTA = GAMMA+INCR -1
LDA ALPHA
ADD INCR
SUB ONE
STA BETA
LDA GAMMA
ADD INCR
SUB ONE
STA DELTA
...
ONE WORD 1 one-word constant
ALPHA WORD 100 one-word variables
BETA RESW 1
GAMMA WORD 50
DELTA RESW 1
INCR WORD 5
Dr. Dhanya P.M, Associate Professor, Dept of CSE, RSET
SIC Programming Example
Looping and indexing: copy one string to another
LDX ZERO initialize index register to 0
MOVECH LDCH STR1,X load char from STR1 to reg A
STCH STR2,X
TIX ELEVEN add 1 to index, compare to 11
JLT MOVECH loop if “less than”
.
.
.
STR1 BYTE C’TEST STRING’
STR2 RESB 11
ZERO WORD 0
ELEVEN WORD 11
Dr. Dhanya P.M, Associate Professor, Dept of CSE, RSET
SIC Programming Example
Program to add two integer arrays ALPHA and BETA and store the result in GAMMA
LDA ZERO initialize index value to 0
STA INDEX
ADDLP LDX INDEX load index value to reg X
LDA ALPHA,X load word from ALPHA into reg A
ADD BETA,X
STA GAMMA,X store the result in a word in GAMMA
LDA INDEX
ADD THREE add 3 to index value
STA INDEX
COMP K300 compare new index value to 300
JLT ADDLP loop if less than 300
...
...
INDEX RESW 1
ALPHA RESW 100 array variables—100 words each
BETA RESW 100
GAMMA RESW 100
ZERO WORD 0 one-word constants
THREE WORD 3
K300 WORD 300
Dr. Dhanya P.M, Associate Professor, Dept of CSE, RSET
SIC Programming Example
Program for Input and output operations
INLOOP TD INDEV test input device
JEQ INLOOP loop until device is ready
RD INDEV read one byte into register A
STCH DATA
.
.
OUTLP TD OUTDEV test output device
JEQ OUTLP loop until device is ready
LDCH DATA
WD OUTDEV write one byte to output device
.
.
INDEV BYTE X’F1’ input device number
OUTDEV BYTE X’05’ output device number
DATA RESB 1
Dr. Dhanya P.M, Associate Professor, Dept of CSE, RSET
Dr. Dhanya P.M, Associate Professor, Dept of CSE, RSET