ITCS 321 Test ONE NOV 2018 KEY AAA

Download as pdf or txt
Download as pdf or txt
You are on page 1of 5

Name: Student id: #:

QUESTION # 1 2 3 4 TOTAL
MAX POINTS 14 16 16 18 63
POINTS EARNED

***************************************************************************************
UNIVERSITY OF BAHRAIN COLLEGE OF INFORMATION TECHNOLOGY
DEPARTMENT OF COMPUTER SCIENCE
ITCS 321: COMPUTER ORGAIZATION AND ASSEMBLY LANGUAGE
FIRST TEST FIRST SEMESTER 2018/2019 DATE: NOV 13, 2018
***************************************************************************************
QUESTION ONE
Part A: { 08 pts }
The 8-bit value 10111010 represents unsigned decimal value 186 and signed decimal value -70.

1) Using 36 bits to represent signed values, the largest decimal value is +235 - 1 and the smallest

decimal value is -235


2) The range of signed half word is from –215 to (+215 – 1)

3) If a computer has clock period = 0.2 ns, then its clock rate = 1/(0.2x10-9)= 5 GH.

4) Perform the following operation using 16’s complement: 5F2A – 7C9F.


5F2A – 7C9F = 5F2A + (–7C9F)
= 5F2A + 8361 = e28B
5) Using 8 bits to store numbers, show how the operation (23)10 – (87)10 is performed by the computer.
+23 = 0001 0111 0001 0111
+87 = 0101 0111  +1010 1001
-87 = 1010 1001 1100 0000
Part B: { 06 pts }
1) The program that translates high-level programs to machine code is called Compilers; The
program that translates Assembly programs to machine code is called Assembles
2) List three advantages of High-Level Languages:
 Program development in HLL is fast
 Programs written in HLL is easy to maintain.
 Programs written in HLL are portable
3) Briefly explain two reasons why learning Assembly language is important.
 Using Assembly language allows easy access to system hardware
 Assembly programs occupy less memory space and time efficient

ITCS 321 Test ONE NOV 2018 KEY Page# 1 AAA


QUESTION TWO

Part A: { 10 pts }
1) Briefly explain two differences between RISC and CISC computers.
 In RISC: all instructions have fixed size; In CISC: instructions have variable size
 In RISC: arithmetic operations are register to register; In CISC: arithmetic
operations are with any operands.
 In RISC: few instruction formats; In CISC: large number of instruction formats
2) Assume the CPU has just read a 32-bit MIPS instruction from the memory address 0x00400008. Then,
the address of the next instruction to be read by the CPU is 0x00400008+4=0x0040000c

3) Assuming the following data segment, and assuming that the first variable X is given the address
0x10010000, then the addresses for variables Y and Z will be 0x10010002 and 0x10010008

.data
X: .byte 1, 5
Y: .half 2, 3, 9
Z: .word 4

4) Given the array definitions arr: .byte 1, 2, -3, 4; After executing the following code, the
content of the three registers $t1, $t2, and $t3 will be:
la $t0, arr
lb $t1, 2($t0)
lh $t2, 2($t0)
lw $t3, 0($t0)

$t1= 0xfffffffd $t2= 0x000004fd ? $t3= 0x04fd0201

5) Assume that the instruction bne $t0, $t1, NEXT is at address 0x00400020 in the text segment, and
the label NEXT is at address 0x00400010. Then, the address stored in the assembled instruction for the
label NEXT is (0x00400010-(0x00400020+4))/4 = 0xfffb

Part B: Answer with T (TRUE) or F(FALSE) each of the following. { 06 pts }


1) _____T__The Instruction Set Architecture defines the interface between software and hardware.
2) __F_____ MIPS instruction have variable size.
3) __F_____ A flash memory is an example of volatile storage devices.
4) _____T__ In MIPS, the address of the next instruction is stored in PC register.
5) __F_____ Assembly Programs are portable among computers with different configurations.
6) _____T__The addressing mode used in beq $t3, $t2, L8 instruction is PC-relative.

ITCS 321 Test ONE NOV 2018 KEY Page# 2 AAA


QUESTION THREE

Part A: { 04 pts }
1) The pseudo-instruction neg $s2, $s1 is used to store in $s2 the 2’s complement of $t1.
Write ONE MIPS instruction to implement it.
subu $s2, $0, $s1
2) Write no more than TWO MIPS instructions to implement the following pseudo instruction
ble $s2, $s1, Next.
slt $at, $s1, $s2
beq $at, $0, Next
Part B: { 12 pts }
1) Assume that variables a, b, c, and d are stored in registers $s1, $s2, $s3, and $s4,
respectively. Write the needed MIPS instructions to implement the following if statement:
if ( (a == b) && (b < c ) ) then d = d +5;

bne $s1, $s2, exit


bge $s2, $s3, exit
addi $s4, $s4, 5
exit:

2) Assume that variables a, b, c, and d are stored in registers $s1, $s2, $s3, and $s4,
respectively. Write the needed MIPS instructions to implement the following if statement:
if ( (a ==b) || (b <= c ) && (c > d) ) then d=d +a;

beq $s1, $s2, equal


bgt $s2, $s3, done
ble $s3, $s4, done
equal: add $s4, $s4, $s1
done:
3) Write the needed MIPS instructions to allocate space for the matrix: mat = new int[12][10];
and stores its base address in $t9.
li $a0, 480 # $a0 = 10*12*4 = 480 bytes
li $v0, 9
syscall # allocate 480 bytes
move $t9, $v0 # $t9 = &mat

ITCS 321 Test ONE NOV 2018 KEY Page# 3 AAA


QUESTION FOUR

Part A: { 04 pts }
Given the following contents of memory. What will be in registers $t0 thru $t3 in hexadecimal
after executing each of the following MIPS instructions. The little endian byte ordering is used.
Assume $t8 = 0×10010020.

Address +0 +1 +2 +3 +4 +5 +6 +7
0×10010020 FA 20 10 C0 B0 5F 94 8A

lw $t0, 0($t8) $t0 = 0xC01020FA


lh $t1, 2($t8) $t1 = 0xFFFFC010
lhu $t2, 4($t8) $t2 = 0x00005FB0
lb $t3, 5($t8) $t3 = 0x0000005F
Part B: { 14 pts }
Given an array definition arr: .word 75, -19, 20, 88, -5, 45, -29, 99; Write a complete
program that stores in registers $v1 and $v0 the smallest value and its address respectively.

# MIPS program to find the smallest value and its address in a given array
# Date: NOV 13, 2018

.data
arr: .word 75, -19, 20, 88, -5, 45, -29, 99

.text
.globl main
main:
la $a0, arr
addi $a1, $a0, 28
move $v0, $a0
lw $v1, 0($v0)
move $t0, $a0
next: addi $t0, $t0, 4
lw $t1, 0($t0)
bge $t1, $v1, skip
move $v0, $t0
move $v1, $t1
skip: bne $t0, $a1, next
li $v0, 10 # syscall 10 = exit the program
syscall

ITCS 321 Test ONE NOV 2018 KEY Page# 4 AAA


Table of MIPS System calls
Service $v0 Arguments / Result

Print Integer 1 $a0 = integer value to print

Print Float 2 $f12 = float value to print


Print Double 3 $f12 = double value to print
Print String 4 $a0 = address of null-terminated string
Read Integer 5 Returns integer value in $v0
Read Float 6 Returns float value in $f0
Read Double 7 Returns double value in $f0
$a0 = address of input buffer
Read String 8
$a1 = maximum number of characters to read

Allocate Heap $a0 = number of bytes to allocate


9
memory Returns address of allocated memory in $v0
Exit Program 10
Print Char 11 $a0 = character to print
Read Char 12 Return character read in $v0

$a0 = address of null-terminated filename string $a1 =


flags (0 = read-only, 1 = write-only)
Open File 13
$a2 = mode (ignored)
Returns file descriptor in $v0 (negative if error)

$a0 = File descriptor


Read $a1 = address of input buffer
14
from File $a2 = maximum number of characters to read
Returns number of characters read in $v0

$a0 = File descriptor


Write to File 15 $a1 = address of buffer
$a2 = number of characters to write
Returns number of characters written in $v0
Close File 16 $a0 = File descriptor

ITCS 321 Test ONE NOV 2018 KEY Page# 5 AAA

You might also like