S-87.3190 ...
S-87.3190 Computer Architecture
Spring term 2009
Project work E5
22.4.2009
Ronja Addams-Moring, Ti-N, 36750E
ronja@iki.fi
Note to the course personnel: head assistant Vesa Turunen has kindly allowed me a time extension due to my reading disability, which makes coding in assembler quite hard. He has also OKed the non-standard use of temporary registers, which I have done to make it easier for me to see and remember which register is used for what.
1. Original assignment
# ASSIGNMENT E5
#
######################################################################
#
# Write a subroutine which calculates the number of `one' bits in an
# array.
#
# The arguments of the subroutine are passed as follows:
#
# $a0 contains the address of array
# $a1 contains the size of array in 32-bit words
#
# The C-prototype of the subroutine is as follows:
#
# int bitcount(long array[], int size);
#
# The subroutine should return the number of 1 bits in register $v0.
#
######################################################################
#
# Main program to test bitcount()
#
.text
.globl main
main:
# Create a stack frame for main program
subu $sp $sp,8
sw $ra 4($sp) # return address
sw $fp 0($sp) # old frame pointer
addu $fp $sp,8 # update frame pointer
# Get arguments into registers
la $a0 bitarray
li $a1 4
# ... and call the bitcount
jal bitcount
# Test data
.data
bitarray:
.word 0x5a5aa5a5 0xff0000ff 0x11224488 0xc639a55a
.text
# Check result
bne $v0,56 .failure1
# Insert your own tests here
# Tell user that bitcount works..
.data
.ok: .asciiz "The bitcount() passed all tests\n"
.text
li $v0 4
la $a0 .ok
syscall
# Exit from test program
.exit:
li $v0 10
syscall
# Test failed
.failure1:
.data
.fail1: .asciiz " The bitcount() failed test 1.\n"
.text
li $v0 4
la $a0 .fail1
syscall
j .exit
######################################################################
#
# The subroutine bitcount - write your own subroutine here
#
.text
.globl bitcount
bitcount:
XXX
jr $ra
.end
2. What the subroutine does
The subroutine bitcount analyzes an array and claculates how many of the bits in the array have the value one.
Outer functionality:
uses as its parameters the values in registers $a0 (the address of the array) and $a1 (the size of the array)
normal function: returns, as the value of the register $v0, the number of bits in the whole array that have the value ...