-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlargest_uint.asm
60 lines (48 loc) · 993 Bytes
/
largest_uint.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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
#Scan the biggest unsigned decimal number found in a string and display its value using
#print_int function.
.data
prompt: .asciz "Enter string:\n"
buf: .space 100
.text
.globl main
main:
li a7, 4
la a0, prompt
ecall
li a7, 8
la a0, buf
li a1, 100
ecall
li t0, '0'
li t1, '9'
li t4, 10
li a0, 0 # int to print
li t5, 0 # temp int
la t2, buf
lb t3, (t2)
beqz t3, end
loop:
blt t3, t0, reset_temp
bgt t3, t1, reset_temp
mul t5, t5, t4
sub t3, t3, t0
add t5, t5, t3
increment:
addi t2, t2, 1
lb t3, (t2)
bnez t3, loop
beqz a0, end
beqz t3, print_int
reset_temp:
bgt t5, a0, swap
j increment
swap:
add a0, t5, zero
li t5, 0
j increment
print_int:
li a7, 36
ecall
end:
li a7, 10
ecall