我正在尝试将我的python程序转换为汇编语言,但我不确定如何。这是python程序:
numberofscores=float(input("Please enter the number of test scores to be entered:"))
sumofscores = 0
count = 1
while count <= numberofscores :
score1=float(input("Please enter the test score:"))
sumofscores=sumofscores+score1
count=count+1
average=sumofscores/numberofscores
print average
答案 0 :(得分:1)
嗯,我从来没有听说过这个名为One Address Machine
的教学资源,它是基于网络的OAMulator
(1,2,3) 支持OAMPL
(OAM编程语言)和(编译)OAM Assembly
。
所以我作弊..
首先,我'解析'你的python代码(我也不知道python)并将其翻译为OAMPL
:
PRINT "Please enter the number of test scores to be entered:"
READ numberofscores
sumofscores = 0
LOOP numberofscores
PRINT "Please enter the test score:"
READ testscore
sumofscores = (+ sumofscores testscore)
END
PRINT "the answer is:"
PRINT (/ sumofscores numberofscores)
EXIT
注意:我没有翻译您的float
,因为它应该是int
(尽管每个得分都可以是浮点数)。经过一些测试后,我发现2.5
的输入“无论如何都是'读'。我也放弃了count
变量(因为LOOP
指令没有它工作)和average
变量(因为我不需要它)...
点击compile
呈现(这可能是您的回答):
# Emitted by the OAMPL compiler
1. BR 5 # branch to program block
# Variable storage allocation block
2. numberofscores, NOOP # variable numberofscores
3. sumofscores, NOOP # variable sumofscores
4. testscore, NOOP # variable testscore
# Begin OAM program block
# OAMPL: PRINT "Please enter the number of test scores to be entered:"
5. SET "Please enter the number of test scores to be entered:"
6. STA stdout
# OAMPL: READ numberofscores
7. LDA stdin
8. STA numberofscores
# OAMPL: sumofscores = 0
9. SET 0
10. STA sumofscores
# OAMPL: LOOP numberofscores
11. LDA numberofscores
12. BR L13
13. NOOP # loop counter
# OAMPL: PRINT "Please enter the test score:"
14. SET "Please enter the test score:"
15. STA stdout
# OAMPL: READ testscore
16. LDA stdin
17. STA testscore
# OAMPL: sumofscores = (+ sumofscores testscore)
18. LDA testscore
19. STA 21
20. BR 22
21. NOOP # intermediate value
22. LDA sumofscores
23. ADD 21
24. STA sumofscores
# OAMPL: END
25. LDA 13
26. DEC
27. L13, STA 13
28. BRP 14
# OAMPL: PRINT "the answer is:"
29. SET "the answer is:"
30. STA stdout
# OAMPL: PRINT (/ sumofscores numberofscores)
31. LDA numberofscores
32. STA 34
33. BR 35
34. NOOP # intermediate value
35. LDA sumofscores
36. DIV 34
37. STA stdout
# OAMPL: EXIT
38. HLT
鉴于input (one per line)
:
3
71.4
33
21.6
注意:问题的答案“3”要求测试分数的数量,然后回答“71.4”,“33”和“21 .6”的问题,询问个别考试成绩。 (这不是互动输入,让我离开了15分钟......这件事可能会因合并META II
)而受到重视
如果我execute
上面的OAM程序集(在编译!!之后)并将其输入上面的输入,那么输出呈现:
Please enter the number of test scores to be entered:
Please enter the test score:
Please enter the test score:
Please enter the test score:
the answer is:
42
...圣洁的.. 答案是42 ,这是一切的答案 ......
(这很酷..没有可用的文档,猜测编程语言......这是我回答的最酷的问题)
希望这有帮助!
PS:请在下面的评论中添加一些指向此OAMPL和OAM程序集的文档/语法的链接!!! 在线文档的(1,{{ 3}},2)我发现并没有真正的帮助(例如,来自'hello world'示例的WRITE
不起作用..等等我没有了解OAMPL支持的语法,而不是3)。