OAMulator(打印最高分 7)

发布于 2025-01-19 14:54:50 字数 3879 浏览 0 评论 0原文

我正在尝试在岩体中编写一个反映该伪代码的程序。

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

这就是我想到的。我们必须使用7个分数,并获得最高分数,只打印出最高分数。我们还必须使用计数循环。我输入0作为控件,以启动输入以及其他7个分数。明确地说,我不是在寻找遮阳篷或解决方案。我希望了解为什么这是不起作用的以及如何使计数循环使用更高的循环工作。

INPUT LIST
0
60
70
80
90
83
76
95

然后,我尽可能地编写代码,但是我遇到的问题是计数和新的分数从累加器中流行。我尝试编写另一个循环以更改它,但是随后两个循环并不总是运行,计数被弄乱了,否则得分也不会正确。

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 

这是跟踪和内存

跟踪

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.

内存

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

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

岁月苍老的讽刺 2025-01-26 14:54:50

我发现了。我花了几个小时。差不多几天。

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

OAM组装语言上的互联网上似乎没有太大帮助,因此我将来向其他人发布了答案。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文