-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlab4_4.asm
35 lines (35 loc) · 841 Bytes
/
lab4_4.asm
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
#Laboratory Exercise 5, Sample Code3
.data
string: .space 50
Message1: .asciiz "Nhap xau"
Message2: .asciiz "Do dai la "
.text
main:
get_string: # TODO
li $v0, 54
la $a0, Message1
la $a1, string
la $a2, 40
syscall
get_length:
la $a0, string # a0 = Address(string[0])
xor $v0, $zero, $zero # v0 = length = 0
xor $t0, $zero, $zero # t0 = i = 0
check_char:
add $t1, $a0, $t0 # t1 = a0 + t0
#= Address(string[0]+i)
lb $t2, 0($t1) # t2 = string[i]
beq $t2, $zero, end_of_str # Is null char?
addi $v0, $v0, 1 # v0=v0+1->length=length+1
addi $t0, $t0, 1 # t0=t0+1->i = i + 1
j check_char
end_of_str:
end_of_get_length:
sub $t0,$t0,1
print_length: # TODO
la $a0,Message2
li $v0,4
syscall
li $v0,1
move $a0, $t0
syscall