Model for hw1 problem 1
countstring.s
#
countstring.s: count chars in a string in data
#
registers:
#
t0 - pointer to string
#
t1 - count of chars
#
t2 - current char
.globl main
.globl str2count
main: la $t0,
str2count # point to string
li
$t1, 0 # count = 0
loop: lb $t2,
0($t0) # load byte of string
beq
$t2, $0, done # check if byte = 0
addi
$t1,$t1,1 # inc count
addi
$t0, $t0, 1 # inc pointer
j loop # loop back
done: move $a0,
$t1 # count to print
li
$v0, 1 # print int
syscall
jr
$ra
# return
.data
str2count:
.asciiz "abcdefg"