COMP2120-Assignment5
File description: Assignment 5 of COMP2120 (24/25 Spring) with solutions.
Document status: LTS
Last modified: 2026-09-11 21:12 HKT
COMP2120 Computer Organisation
24/25 Semester 2
Assignment 5
1. Consider a Serial Interface (e.g. Modem), containing a Control & Status Register and two Buffer Registers , Input and Output
Buffer Register, residing in memory location SCSR, SBRI and SBRO, The SCSR has the following format:
Bit 0 =1 if Device Error
Bit 1 =1 if Device Ready
Bit 2 =0 if next operation is Write, 1, Read
Bit 3-5 =000 if speed = 4800 bps
=001 if speed = 9600 bps
=010 if speed = 19200 bps
=011 if speed = 57600 bps
=100 if spped = 115200 bps
Bit 6 =0 if odd parity, 1 if even parity
Write an assembly program, using any instructions set (you may invent your own instructions) to output an array of 10 characters
by Program I/O, to the serial port, using a speed of 115200 bps and even parity.
To simplify the problem, you may assume that the array of characters is stored in memory location LINE, with one character in
one word.
Only source program is needed.
Solution: In the following program, hexadecimal decimals are supported by prefixing with “0x”.
1 .data
2 base: .word 0x0
3 arrsize: .word 0xa
4 .text
5 main: ; entry point of the program
6 ld base, R1 ; R1 = 0, used as ctr
7 ld arrsize, R2 ; R2 = 10
8 ld 0x1, R3 ; const int r3 = 1;
9 dev_rdy: ld SCSR, R3
10 and R3, 0x2, R3 ; check if device ready
11 bz dev_rdy ; branch to dev_rdy if R3=0 (bit 1 =0, not rdy)
12 loop: ld LINE(R1), R4 ; load char from array
13 st R4, SBRO ; R4 = LINE[R1] (displacement addressing mode)
14 add R3, R1, R1 ; R1++
15 st 0x60, SCSR ; set speed and parity
16 st R4, SBRO ; output char to serial port
17 sub R2, R1, R5 ; R5 = R2 - R1
18 bnz loop ; branch to loop if R5 != 0
19 rtn
Page 1 of 2
Page 1 of 2
2. Given the data path of a CPU as in Assignment 4 with the modification that the MBR provides data to both S1-Bus and S2-Bus.
Consider another instruction set, which allows memory operands, and the addressing mode information is stored in the same byte
as the register operand. Describe the data transfer/transformation for the following 2-word instruction:
ADD OFF(R1), R2, R3
which will get the first operand from memory whose address is given by OFF+R1 (displacement addressing mode), add it to R2
and put the result in R3. OFF is stored in the word following the instruction:
ADD R1 (Disp mode) R2 R3
OFF
Solution:
MAR <- PC ; (IF)
PC <- PC + 4 ; PC points to OFF
MBR <- mem[MAR]
IR <- MBR
... ; (DI)
Read Register File for R1 at RFOUT1 ; (OF)
ALU_A <- RFOUT1
MAR <- PC ; MAR has address of 2nd word
PC <- PC + 4 ; PC points to next instruction
MBR <- mem[MAR] ; MBR has value of 2nd word
ALU_B <- MBR
ALU_C <-(via ALU)- ALU_A + ALU_B ; calculate R1 + OFF
MAR <- ALU_C
MBR <- mem[MAR] ; MBR has value at address R1 + OFF
ALU_A <- MBR
Read Register File for R2 at RFOUT2
ALU_B <- RFOUT2
ALU_C <-(via ALU)- ALU_A + ALU_B ; calculate mem[R1+OFF] + (R2)
RFIN <- ALU_C
Write Register File to R3 with value in RFIN
Page 2 of 2
Page 2 of 2
See also
-
COMP2120-Assignment1
Assignment 1 of COMP2120 (24/25 Spring) with solutions.
-
COMP2120-Assignment2
Assignment 2 of COMP2120 (24/25 Spring) with solutions.
-
COMP2120-Assignment3
Assignment 3 of COMP2120 (24/25 Spring) with solutions.
-
COMP2120-Assignment4
Assignment 4 of COMP2120 (24/25 Spring) with solutions.
-
COMP2120-Cheatsheet
An A4 double-sided cheatsheet for the COMP2120 final exam.
-
COMP2120-Notes
Revision notes for COMP2120.