Reputation: 1
I am trying to write a program in OAMulator that is reflective of this Pseudo-code.
Set highest to 0
Set count to 7
While count > 0
Get newScore
Print newScore
If newScore > highest
Set highest to newScore
Set count to count - 1
Print highest
Stop
This is what I've come up with. We have to use 7 scores and get the highest and print only the highest score. We also have to use a count loop. I entered 0 as a control to start the inputs along with 7 other scores. TO BE CLEAR I AM NOT LOOKING FOR THE AWNSER OR SOLUTION. i am looking to learn why this isnt working and how to make a count loop work with a higherthan loop.
INPUT LIST
0
60
70
80
90
83
76
95
Then I wrote the code as best as I could, but the issue I run into is the count and new score run off the Accumulator. I tried writing another loop to change it but then the two loops don't always run and the count gets messed up or the scores don't get tallied right.
SET 7 #set count to 7
count, STA 100 #store count to slot 100
loopstart, LDA 0 #start loop, load 0
STA 101 #store 0 in slot 101
LDA 0 #load 60
STA 102 #store in slot 102
LDA 101 #load 60
SUB 102 #subract 70
BRP loopstart #if pos then loop, if not go on.
LDA 100 #load count
DEC # count -1
BRP count #if count <0 loop to count
print, STA 102 #print highest
HLT
here is the trace and memory
TRACE
0: PC=1 IR=[?????] AR=? ACC=? B=?
1: PC=2 IR=[SET 7] AR=1 ACC=7 B=?
2: PC=3 IR=[STA 100] AR=100 ACC=7 B=?
3: PC=4 IR=[LDA 0] AR=0 ACC=0 B=?
4: PC=5 IR=[STA 101] AR=101 ACC=0 B=?
5: PC=6 IR=[LDA 0] AR=0 ACC=60 B=?
6: PC=7 IR=[STA 102] AR=102 ACC=60 B=?
7: PC=8 IR=[LDA 101] AR=101 ACC=0 B=?
8: PC=9 IR=[SUB 102] AR=102 ACC=-60 B=60
9: PC=10 IR=[BRP 3] AR=9 ACC=-60 B=60
10: PC=11 IR=[LDA 100] AR=100 ACC=7 B=60
11: PC=12 IR=[DEC] AR=11 ACC=6 B=60
12: PC=2 IR=[BRP 2] AR=12 ACC=6 B=60
13: PC=3 IR=[STA 100] AR=100 ACC=6 B=60
14: PC=4 IR=[LDA 0] AR=0 ACC=70 B=60
15: PC=5 IR=[STA 101] AR=101 ACC=70 B=60
16: PC=6 IR=[LDA 0] AR=0 ACC=80 B=60
17: PC=7 IR=[STA 102] AR=102 ACC=80 B=60
18: PC=8 IR=[LDA 101] AR=101 ACC=70 B=60
19: PC=9 IR=[SUB 102] AR=102 ACC=-10 B=80
20: PC=10 IR=[BRP 3] AR=9 ACC=-10 B=80
21: PC=11 IR=[LDA 100] AR=100 ACC=6 B=80
22: PC=12 IR=[DEC] AR=11 ACC=5 B=80
23: PC=2 IR=[BRP 2] AR=12 ACC=5 B=80
24: PC=3 IR=[STA 100] AR=100 ACC=5 B=80
25: PC=4 IR=[LDA 0] AR=0 ACC=90 B=80
26: PC=5 IR=[STA 101] AR=101 ACC=90 B=80
27: PC=6 IR=[LDA 0] AR=0 ACC=83 B=80
28: PC=7 IR=[STA 102] AR=102 ACC=83 B=80
29: PC=8 IR=[LDA 101] AR=101 ACC=90 B=80
30: PC=9 IR=[SUB 102] AR=102 ACC=7 B=83
31: PC=3 IR=[BRP 3] AR=9 ACC=7 B=83
32: PC=4 IR=[LDA 0] AR=0 ACC=76 B=83
33: PC=5 IR=[STA 101] AR=101 ACC=76 B=83
34: PC=6 IR=[LDA 0] AR=0 ACC=95 B=83
35: PC=7 IR=[STA 102] AR=102 ACC=95 B=83
36: PC=8 IR=[LDA 101] AR=101 ACC=76 B=83
37: PC=9 IR=[SUB 102] AR=102 ACC=-19 B=95
38: PC=10 IR=[BRP 3] AR=9 ACC=-19 B=95
39: PC=11 IR=[LDA 100] AR=100 ACC=5 B=95
40: PC=12 IR=[DEC] AR=11 ACC=4 B=95
41: PC=2 IR=[BRP 2] AR=12 ACC=4 B=95
42: PC=3 IR=[STA 100] AR=100 ACC=4 B=95
Error: Attempt to read missing input
43: PC=4 IR=[LDA 0] AR=0 ACC=? B=95
Abort: 43 instructions executed.
MEMORY
1. SET 7
2. STA 100
3. LDA 0
4. STA 101
5. LDA 0
6. STA 102
7. LDA 101
8. SUB 102
9. BRP 3
10. LDA 100
11. DEC
12. BRP 2
13. STA 102
14. HLT
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. 4
101. 76
102. 95
Upvotes: 0
Views: 23
Reputation: 1
I figured it out. It took me hours. almost days.
SET 8 #set count to 8
STA 100 #store in slot 100
SET 0
STA 102 #slot 0 as highest
loopstart, LDA 100 #Load count
DEC #count -1
BRZ print # if count is 0 print
STA 100 # if count is more than 1 store
LDA 0 #load ACC
STA 101 #store ACC in 101
LDA 101 #load Number
SUB 102 #subract highest
BRP while
BR loopstart
print, LDA 102
STA 0
HLT
while, LDA 101
STA 102 #if ACC is positive store as highest
BR loopstart
There doesn't seem to be much help on the internet for OAM assembly language so i posted the answer for others in the future.
Upvotes: 0