-
Notifications
You must be signed in to change notification settings - Fork 0
/
power_of_10.s
80 lines (58 loc) · 1.01 KB
/
power_of_10.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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
.text
.globl __start
__start:
loop:
la $a0, givei
jal printstr
li $v0,5
syscall
move $t9, $v0
move $a0, $t9
jal printint
la $a0, endl
jal printstr
beq $t9,$zero,exit
li $t0, 10
li $t1, 0
move $s1, $t9
loop2:
div $s1, $t0
mfhi $t2
mflo $s1
sb $t2, spaces($t1)
addi $t1,$t1,1
bnez $s1, loop2
printres:
addi $t1, $t1,-1
lb $t3,spaces($t1)
move $a0, $t3
jal printint
la $a0, star
jal printstr
la $a0, deka
jal printstr
move $a0, $t1
jal printint
bnez $t1, printadd
la $a0, endl
jal printstr
j loop
exit: li $v0, 10
syscall
printadd: la $a0, adds
li $v0, 4
syscall
j printres
printstr: li $v0, 4
syscall
jr $ra
printint: li $v0,1
syscall
jr $ra
.data
spaces: .asciiz " " #32+\0
star: .asciiz "*"
deka: .asciiz "10^"
adds: .asciiz "+"
givei: .asciiz "Give an int: "
endl: .asciiz "\n"