# test_02.s
#
# A testcase for Asm 2.
.data
.globl fib
fib:
.word 20
.globl square
.globl square_size
.globl square_fill
square:
.word 0
square_size:
.word 10
square_fill:
.byte ‘H’
.globl runCheck
runCheck:
.word 0
.globl intArray_len
.globl intArray
intArray_len:
.word 7
intArray:
.word -10
.word -4
.word 0
.word 1
.word 8
.word 34
.word 43
.globl countWords
countWords:
.word 0
.globl revString
revString:
.word 0
.globl str
str: .asciiz ” Hello world\n Hello world”
# ———– main() ———–
.text
.globl main
main:
# call the student code
jal studentMain
.data
MAIN_HEAD_MSG:
.asciiz “— Dumping out all of the variables, after the student code ran:\n”
MAIN_LABEL_fib: .asciiz “fib: ”
MAIN_LABEL_square: .asciiz “square: ”
MAIN_LABEL_square_size: .asciiz “square_size: ”
MAIN_LABEL_square_fill: .asciiz “square_fill: ”
MAIN_LABEL_runCheck: .asciiz “runCheck: ”
MAIN_LABEL_countWords: .asciiz “countWords: ”
MAIN_LABEL_revString: .asciiz “revString: ”
MAIN_LABEL_str: .asciiz “str: \””
MAIN_LABEL_intArray_len: .asciiz “intArray_len: ”
MAIN_LABEL_intArray: .asciiz “intArray[]: ”
MAIN_TAIL_MSG:
.asciiz “— Testcase end—\n”
.text
# print_str(HEAD_MSG)
addi $v0, $zero,4
la $a0, MAIN_HEAD_MSG
syscall
# print_str(LABEL_fib)
addi $v0, $zero,4
la $a0, MAIN_LABEL_fib
syscall
# print_int(fib)
addi $v0, $zero,1
la $a0, fib
lw $a0, 0($a0)
syscall
# print_chr(‘\n’)
addi $v0, $zero,11
addi $a0, $zero,’\n’
syscall
# print_str(LABEL_square)
addi $v0, $zero,4
la $a0, MAIN_LABEL_square
syscall
# print_int(square)
addi $v0, $zero,1
la $a0, square
lw $a0, 0($a0)
syscall
# print_chr(‘\n’)
addi $v0, $zero,11
addi $a0, $zero,’\n’
syscall
# print_str(LABEL_square_size)
addi $v0, $zero,4
la $a0, MAIN_LABEL_square_size
syscall
# print_int(square_size)
addi $v0, $zero,1
la $a0, square_size
lw $a0, 0($a0)
syscall
# print_chr(‘\n’)
addi $v0, $zero,11
addi $a0, $zero,’\n’
syscall
# print_str(LABEL_square_fill)
addi $v0, $zero,4
la $a0, MAIN_LABEL_square_fill
syscall
# print_int(square_fill)
addi $v0, $zero,1
la $a0, square_fill
lb $a0, 0($a0)
syscall
# print_chr(‘\n’)
addi $v0, $zero,11
addi $a0, $zero,’\n’
syscall
# print_str(LABEL_runCheck)
addi $v0, $zero,4
la $a0, MAIN_LABEL_runCheck
syscall
# print_int(runCheck)
addi $v0, $zero,1
la $a0, runCheck
lw $a0, 0($a0)
syscall
# print_chr(‘\n’)
addi $v0, $zero,11
addi $a0, $zero,’\n’
syscall
# print_str(LABEL_countWords)
addi $v0, $zero,4
la $a0, MAIN_LABEL_countWords
syscall
# print_int(countWords)
addi $v0, $zero,1
la $a0, countWords
lw $a0, 0($a0)
syscall
# print_chr(‘\n’)
addi $v0, $zero,11
addi $a0, $zero,’\n’
syscall
# print_str(LABEL_revString)
addi $v0, $zero,4
la $a0, MAIN_LABEL_revString
syscall
# print_int(revString)
addi $v0, $zero,1
la $a0, revString
lw $a0, 0($a0)
syscall
# print_chr(‘\n’)
addi $v0, $zero,11
addi $a0, $zero,’\n’
syscall
# print_str(LABEL_str)
addi $v0, $zero,4
la $a0, MAIN_LABEL_str
syscall
# print_int(str)
addi $v0, $zero,4
la $a0, str
syscall
# print_chr(‘”‘)
addi $v0, $zero,11
addi $a0, $zero,'”‘
syscall
# print_chr(‘\n’)
addi $v0, $zero,11
addi $a0, $zero,’\n’
syscall
# print_str(LABEL_intArray_len)
addi $v0, $zero,4
la $a0, MAIN_LABEL_intArray_len
syscall
# print_int(intArray_len)
addi $v0, $zero,1
la $a0, intArray_len
lw $a0, 0($a0)
syscall
# print_chr(‘\n’)
addi $v0, $zero,11
addi $a0, $zero,’\n’
syscall
# Dump out intArray[]
#
# for (int i=0; i
# print_chr(‘ ‘) – twice
addi $v0, $zero,11
addi $a0, $zero,’ ‘
syscall
syscall
sll $t8, $t2,2 # t8 = i*4
add $t8, $t0,$t8 # t8 = &intArray[i]
# print_int(intArray[i])
addi $v0, $zero,1
lw $a0, 0($t8)
syscall
# print_chr(‘\n’)
addi $v0, $zero,11
addi $a0, $zero,’\n’
syscall
addi $t2, $t2,1 # i++
j MAIN_LOOP
MAIN_LOOP_DONE:
# print_str(TAIL_MSG)
addi $v0, $zero,4
la $a0, MAIN_TAIL_MSG
syscall
# sys_exit()
addi $v0, $zero,10
syscall