-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathspawn5.asm
More file actions
69 lines (56 loc) · 1.92 KB
/
spawn5.asm
File metadata and controls
69 lines (56 loc) · 1.92 KB
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
####################################################
# This program prints the numbers between 100 and 500
# in incrments of 100 to the console device.
# It spawns another process at each iteration of the
# loop.
###################################################
#Initialize the variables
SET r1 0 #counter
SET r2 100 #increment amount
SET r3 500 #limit
#begin loop
:loop
ADD r1 r2 r1
#Reserve the console device
SET r0 1 #device #1 (console output)
PUSH r0 #push device id on stack
SET r4 3 #OPEN sys call id
PUSH r4 #push sys call id on stack
TRAP #open the device
#Check for failure
POP r4 #get return code from the system call
SET r0 0 #Succes code
BNE r0 r4 exit #exit program on error
#print the current value in the count to the console
SET r4 1 #device id 1 = console
PUSH r4 #push device number
PUSH r0 #push address (arg not used by this device so any val will do)
PUSH r1 #push value to send to device
SET r4 6 #WRITE system call id
PUSH r4 #push the sys call id
TRAP #system call to print the value
#Check for failure
POP r4 #get return code from the system call
SET r0 0 #Succes code
BNE r0 r4 exit #exit program on error
#close the console device
SET r0 1 #device number 1 (console output)
PUSH r0 #push device number
SET r4 4 #CLOSE sys call id
PUSH r4 #push the sys call id onto the stack
TRAP #close the device
#Check for failure
POP r4 #get return code from the system call
SET r0 0 #Succes code
BNE r0 r4 exit #exit program on error
#spawn a new process
SET r4 7 #EXEC sys call id
PUSH r4 #push the sys call id onto the stack
TRAP #make the system call
#end of loop
BNE r1 r3 loop #repeat 5 times
#exit syscall
:exit
SET r4 0 #EXIT system call id
PUSH r4 #push sys call id on stack
TRAP #exit the program