-
Notifications
You must be signed in to change notification settings - Fork 0
/
sysspim.s
80 lines (57 loc) · 943 Bytes
/
sysspim.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
# system calls for Tiger, when running on SPIM
#
# $Id: sysspim.s,v 1.1 2002/08/25 05:06:41 shivers Exp $
.globl malloc
.ent malloc
.text
malloc:
# round up the requested amount to a multiple of 4
add $a0, $a0, 3
srl $a0, $a0, 2
sll $a0, $a0, 2
# allocate the memory with sbrk()
li $v0, 9
syscall
j $ra
.end malloc
.data
.align 4
getchar_buf: .byte 0, 0
getchar:
# read the character
la $a0, getchar_buf
li $a1, 2
li $v0, 8
syscall
# return it
lb $v0, ($a0)
j $ra
.data
.align 4
putchar_buf: .byte 0, 0
.text
putchar:
# save the character so that it is NUL-terminated
la $t0, putchar_buf
sb $a0, ($t0)
# print it out
la $a0, putchar_buf
li $v0, 4
syscall
j $ra
.text
# just prints the format string, not the arguments
printf:
li $v0, 4
syscall
j $ra
.text
# CUSTOM FUNCTION: prints an integer found in $a0
putint:
li $v0, 1
syscall
j $ra
.text
exit:
li $v0, 10
syscall