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

Instructions: CSCE 212: Exam 1 Fall 2009

This document contains instructions for a closed book exam with 60 total points. It includes 3 questions: 1) Write MIPS code to reverse the bit sequence in a register (20 points). 2) Show how a "die" instruction could be implemented (10 points). 3) Write a MIPS subroutine to check if a number is divisible by 8 (20 points). The final question is to convert a hexadecimal instruction sequence to MIPS assembly (10 points).

Uploaded by

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

Instructions: CSCE 212: Exam 1 Fall 2009

This document contains instructions for a closed book exam with 60 total points. It includes 3 questions: 1) Write MIPS code to reverse the bit sequence in a register (20 points). 2) Show how a "die" instruction could be implemented (10 points). 3) Write a MIPS subroutine to check if a number is divisible by 8 (20 points). The final question is to convert a hexadecimal instruction sequence to MIPS assembly (10 points).

Uploaded by

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

CSCE 212: Exam 1

Name (please print):_________________________________

Fall 2009

Total points: ___/60

Instructions
This is a CLOSED BOOK and CLOSED NOTES quiz. However, you may use
calculators, scratch paper, and the green MIPS reference card from your textbook. Ask
the instructor if you have any questions. Good luck!
1. (20 points) Write a snippet of MIPS code that reverses the bit sequence stored in
register $s0. You may use the following algorithm (substitute symbolic registers with
actual registers):
1)
2)
3)
4)
5)
6)
7)
8)

set register A to 0 (used as counter)


set register B to 0 (used as result)
right-shift $s0 by A bits, put result into temporary register C
left-shift C by 31 bits
right-shift C by A bits
perform a bit-wise OR between register B and C, put result in B
increment A
if A < 32, go to line 3

li $t0,0
li $t1,0
loop: srlv $t2,$s0,$t0
sll $t2,$t2,31
srlv $t2,$t2,$t0
or $t1,$t1,$t2
addi $t0,$t0,1
blt $t0,32,loop

2. (10 points) Assume theres a pseudo-instruction named die, which causes the
machine to lock up by creating an infinite loop. Show how this instruction could be
translated (using assembly code).
loop: beq $0,$0,loop

3. (20 points) Write a MIPS subroutine called div8 that returns 1 in register $v0 if the
argument in register $a0 is evenly divisible by 8 (and 0 otherwise). Hint: the check
can be performed using a shift instruction and a beqz or bnez instruction.
The subroutine must not change any of the callers registers (except for $v0),
meaning that it must use the stack to save the original values of any registers that it
uses.
div8:

skip:

addi $sp,$sp,-4
sw $s0,0($sp)
li $v0,1
sll $s0,$a0,29
beqz $s0,skip
li $v0,0
lw $s0,0($sp)
addi $sp,$sp,4
jr $ra

4. (10 points) Convert the following sequence of machine instructions, represented as


hexadecimal values, into assembly language.
3c010010
34300001
01105006
lui $1,16
ori $16,$1,1
srlv $10, $16, $8

You might also like