-
Notifications
You must be signed in to change notification settings - Fork 30
/
lab3_ex5.s
59 lines (44 loc) · 1.69 KB
/
lab3_ex5.s
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
.data
source: .word 3, 1, 4, 1, 5, 9, 0
dest: .word 0, 0, 0, 0, 0, 0, 0
countmsg: .asciiz " values copied. "
.text
main: la $a0,source
la $a1,dest
# $v0 is not initialized
addiu $v0,$zero,0
lw $v1, 0($a0) # read next word from source
loop:
# increment count words copied
#add $a1,$v1,$zero # write to destination
sw $v1,($a1)
# int is size 4
addiu $a0, $a0, 4 # advance pointer to next source
addiu $a1, $a1, 4 # advance pointer to next dest
lw $v1, 0($a0) # read next word from source
addiu $v0, $v0, 1
bne $v1, $zero, loop# loop if word copied not zero
loopend:
move $a0,$v0 # $a0 <- count
jal puti # print it
la $a0,countmsg # $a0 <- countmsg
jal puts # print it
li $a0,0x0A # $a0 <- '\n'
jal putc # print it
finish:
li $v0, 10 # Exit the program
syscall
### The following functions do syscalls in order to print data (integer, string, character)
#Note: argument $a0 to syscall has already been set by the CALLEE
puti:
li $v0, 1 # specify Print Integer service
syscall # Print it
jr $ra # Return
puts:
li $v0, 4 # specify Print String service
syscall # Print it
jr $ra # Return
putc:
li $v0, 11 # specify Print Character service
syscall # Print it
jr $ra # Return