-
Notifications
You must be signed in to change notification settings - Fork 0
/
bi_to_oct.s
83 lines (65 loc) · 1008 Bytes
/
bi_to_oct.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
81
82
83
.text
.globl __start
__start:
la $a0, buff1
li $a1, 20
li $v0, 8
syscall
move $s0, $a0
li $t0,0
li $s3, '\n'
li $s2,2
li $s1,1
li $s4,0
loop:
add $t1, $s0, $t0
lb $t1, 0($t1)
beq $t1, $s3, end
addi $t0, $t0, 1
j loop
end:
addi $t0, $t0, -1
loop2:
add $t1, $s0, $t0
lb $t1, 0($t1)
sub $t1, $t1, '0'
mul $t2, $t1, $s1
mul $s1, $s1, $s2
addi $t0, $t0, -1
add $s4, $s4, $t2
beq $t0, $zero, end2
j loop2
end2:
#li $v0,1
#move $a0, $s4
#syscall
li $t8, 8
la $s0, buff2
li $t0,0
loop3:
div $s4,$t8
mfhi $t2
mflo $s4
add $t1, $s0, $t0
sb $t2,0($t1)
addi $t0, $t0,1
beq $s4,$zero, end3
j loop3
end3:
addi $t0, $t0,-1
loop4:
add $t1, $s0, $t0
lb $t1, 0($t1)
move $a0, $t1
li $v0,1
syscall
addi $t0,$t0,-1
blt $t0, $zero, end4
j loop4
end4:
li $v0, 10
syscall
.data
buff1: .space 20
buff2: .asciiz " "
endl: .asciiz "\n"