-
Notifications
You must be signed in to change notification settings - Fork 2
/
user_heap_test.s
72 lines (59 loc) · 1.34 KB
/
user_heap_test.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
# Tim Henderson & Steve Johnson
# Simple demo for multitasking & user heaps
.data
format_str: .asciiz " Process 2 count: "
.text
print_test:
{
#stackprint
addu $s0 $a0 $zero
la $a0 format_str
call print
addu $a0 $s0 $zero
call print_int
li $a0 10
call print_char
return
}
.globl main
.text
main:
{
@hcb_addr = $s0
@loopvar = $s5
li $v0 9 # system call code for sbrk
addi $a0 $0 4096 # amount
syscall # make the call
addu @hcb_addr $v0 $0
li $a1 1024
addu $a0 @hcb_addr $0
call initialize_heap
addu $a0 @hcb_addr $0
call putuserheap
addu @hcb_addr $0 $0
println_hex hcb_msg @hcb_addr
call getuserheap
addu @hcb_addr $v0 $0
println_hex hcb_msg @hcb_addr
li @loopvar 0
loop:
#stackprint
# sem_wait
addu $a0 @loopvar $zero
call print_test
addi @loopvar @loopvar 1
#stackprint
wait
# sem_signal
li $a0 10
beq @loopvar $a0 killme
b loop
killme:
call getuserheap
addu @hcb_addr $v0 $0
println_hex hcb_msg @hcb_addr
exit
.data
hcb_msg: .asciiz " hcb_addr = "
.text
}