Hmm, I never heard of this teaching resource called One Address Machine
and it's web-based OAMulator
(1, 2, 3) that supports the OAMPL
(OAM Programming Language) and (that compiles) to OAM Assembly
.
So I cheated..
First, I 'parsed' your python-code (I don't know python either) and translated it to 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
Note: I didn't translate your float
because it should be an int
(although each score could be a float). After some testing I found that an input of 2.5
is 'read' as a float anyway. I also discarded the count
variable (since the LOOP
instruction worked without it) and average
variable (since I didn't need it)...
Clicking compile
renders (this is probably your answer):
# 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
Given the input (one per line)
:
3
71.4
33
21.6
Note: answers '3' to the question that asks for the number of test scores and subsequently answers '71.4', '33' and '21.6' to the question that asks for the individual test scores. (this is no interactive input, that threw me off for 15 minutes... this thing might seriously benefit from incorporating META II
)
If I execute
the above OAM assembly (after compiling!!) and feeding it the above input, then the output renders:
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
... holy c.. the answer is 42, it's the answer to everything...
(That's cool.. without usable documentation, guessing a programming language... this is somehow the coolest question I've answered)
Hope this helps!
PS: Please, add some links to the documentation/syntax of this OAMPL and OAM Assembly in the comments below!!! The online doc's (1, 2, 3) I could find didn't really help (for example, WRITE
from the 'hello world' example didn't work.. etc. and I have no idea what syntax OAMPL supports, other than the cheat-sheet found here).