-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathproj4.mem
More file actions
108 lines (87 loc) · 2.07 KB
/
proj4.mem
File metadata and controls
108 lines (87 loc) · 2.07 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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
proj4.mem (Project 4 Memory)
Michael Leonhard (mleonhar)
CS366 Fall 2005, Professor Khokhar
TA Mani Radhakrishnan
2005-11-15
Program Pseudocode
r2 <- address of parameters
r0 <- Mem[r2] multiplicand
r1 <- Mem[r2+1] multiplier
r3 <- 0 initialize counter
r2 <- 0 initialize result
LOOP
if r1 == r3 goto DONE
r3 <- r3 + 1 (increment counter)
r2 <- r2 + r0 (add multiplicand to result)
goto LOOP
DONE
r0 <- r2 (move result)
r2 <- address of parameters
Mem[r2+3] <- r0 (save result to memory)
halt
%
// initialize r2 to the address of the parameters
// LI r2 <- const8
0: 26
1: 000001 10
// load the multiplicand into r0
// LDM r0 <- Mem[r2 + 0]
2: 10 00 0000
3: 000111 00
// load the multiplier into r1
// LDM r1 <- Mem[r2 + 1]
4: 10 00 0001
5: 000111 01
// initialize counter r3 to 0
// LI r3 <- const8
6: 0
7: 000001 11
// initialize result r2 to 0
// LI r2 <- const8
8: 0
9: 000001 10
///////////////////////////////////////////////////////////////////////////////
// LOOP
///////////////////////////////////////////////////////////////////////////////
// check if counter has reached multiplier, jump out of loop
// BE if r1 == r3 then r7 <- r7 + 6
10: 01 11 0110
11: 000100 00
// increment counter
// ADDI r3 <- r3 + 1
12: 11 00 0001
13: 001011 11
// add the multiplicand to the result
// ADD r2 <- r2 + r0
14: 10 00 0000
15: 000011 10
// goto LOOP
// JI -8
16: 11111000
17: 000101 00
///////////////////////////////////////////////////////////////////////////////
// DONE
///////////////////////////////////////////////////////////////////////////////
// move result to r0
// MOVE r0 <- r2
18: 10 00 0000
19: 001100 00
// set r2 to the address of the parameters
// LI r2 <- const8
20: 26
21: 000001 10
// store the result from r0 to memory
// SWM r0 -> Mem[r2 + 2]
22: 10 00 0010
23: 001000 00
// HALT
24: 0
25: 000000 00
///////////////////////////////////////////////////////////////////////////////
// Data
///////////////////////////////////////////////////////////////////////////////
// Parameters
26: 11 // Multiplicand
27: 10 // Multiplier
28: 0 // Result
// end of proj4.mem