This is a relatively simple project to develop your abilities to write loops, function calls, and function definitions in assembly language. There are three parts to this assignment.
In a file named proj1.s
write a function labelled ls1bPos1 that returns the bit number
of the least significant '1' bit in its argument. For this purpose we'll say that
the least significant bit position in a word has bit number 0 and the most significant
bit position has number 31. If the argument is zero, return -1. In writing your function
observe the register conventions for the MIPS machine that we have discussed in class.
For ls1bPos1 you are to compute the answer by repeatedly shifting
the argument right until there is a 1 in the least significant position, counting
as you go to obtain the answer.
Write another function labelled printInt that prints its integer
argument using a syscall, followed by a newline character, printed using
another syscall. The code
li $a0, '\n'
li $v0, 11
syscall
will print a newline character. Note the use of a li instruction. Again, follow the register
conventions for MIPS.
main:
lui $a0,0xF000
jal ls1bPos1
move $a0, $v0
jal printInt
lui $a0,0x0008
jal ls1bPos1
move $a0, $v0
jal printInt
li $a0,0xF400
jal ls1bPos1
move $a0, $v0
jal printInt
li $a0,1
jal ls1bPos1
move $a0, $v0
jal printInt
add $a0,$0,$0
jal ls1bPos1
move $a0, $v0
jal printInt
li $v0,10
syscall
printInt: # your code goes here
ls1bPos1: # your code goes here
# the following is used beginning in part 2 of the assignment
ls1bPos2: # your code goes here
# the following is used only in Part 3 of the assignment
.data
testVals:
# your test data goes here
ls1bPos2 that computes the same thing as
ls1bPos1 but uses the method of repeatedly shifting a 1-bit
mask to the left until it lines up with lowest-order 1 bit of the
argument. Extend the code for main so that it tests both of your functions.
main leaves a lot to be desired: it embeds
the values being tested in the program text and it has several lines of code
for each value to test. For this part of the assignment rewrite main
so that it tests both of your functions on an array of values stored at label
testVals: in the data segment. The array ends with a zero value.
The answer for the zero value must be printed. At testVals:
use the .word directive to store the same values that are tested in the given main
program above. This will require you to investigate the lui instruction that
we have not talked about in class. Note that you can store hex values using .word
by writing -1 and 0xFFFFFFFF result
in the same value value in memory.
proj1.s, containing your final code for ls1bPos1, ls1bPos2,
printInt,
and main. Please note in a comment in the source file itself which simulator
you used to test your code, SPIM or MARS.