forked from thuongtruong1009/computer-architecture
-
Notifications
You must be signed in to change notification settings - Fork 0
/
lab4_1_2.s
61 lines (53 loc) · 861 Bytes
/
lab4_1_2.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
#Code by https://github.com/thuongtruong1009
.data
prompt: .asciiz "Input interger: "
output: .asciiz "Hexadecimal: "
error: .asciiz "Input must be in range (0-15)\n"
annotation: .asciiz "0x"
.text
.globl main
main:
jal printHex
li $v0, 10
syscall
printHex:
la $a0, prompt
li $v0, 4
syscall
li $v0, 5
syscall
move $t0, $v0
la $a0, output
li $v0, 4
syscall
addi $sp, $sp, -4
sw $ra, 0($sp)
bgt $t0, 15, printError
blt $t0, 0, printError
blt $t0, 10, printNum
j printChar
lw $ra, 0($sp)
addi $sp, $sp, 4
jr $ra
printNum:
la $a0, annotation
li $v0, 4
syscall
move $a0, $t0
li $v0, 1
syscall
jr $ra
printChar:
la $a0, annotation
li $v0, 4
syscall
addi $t0, $t0, 55
move $a0, $t0
li $v0, 11
syscall
jr $ra
printError:
la $a0, error
li $v0, 4
syscall
jr $ra