Sample OAM/OAMPL assignments

by Alberto Maria Segre and Filippo Menczer

  1. Consider the following somewhat nonsensical OAM program:
    	 1.  LDA 0
    	 2.  STA 5
    	 3.  INC
    	 4.  BR  5
    	 5.  DEC
    	 6.  LDA 0
    	 7.  MLT 5
    	 8.  STA 0
    	 9.  DEC
    	 10. BRZ 11
    	 11. BR  7
    	 12. HLT
    Assume any inputs required by the program are taken, in order, from the input sequence {2,2,4,4,6,6,...}. What output, if any, would you observe as this program is executed? Also, what is left in each of the registers (PC, IR, AR, ACC, and B) once the program halts? Finally, how would the program's behavior differ if statement 11 read BR 8 instead?
  2. Here is the OAM code produced by the OAMulator compiler for the first example in the tutorial:
    	 1.  SET "Input a B value."
    	 2.  STA 0
    	 3.  LDA 0
    	 4.  STA 6
    	 5.  BR 6
    	 6.  NOOP
    	 7.  SET "Input an A value."
    	 8.  STA 0
    	 9.  LDA 0
    	 10. STA 12
    	 11. BR 12
    	 12. NOOP
    	 13. LDA 12
    	 14. STA 16
    	 15. BR 16
    	 16. NOOP
    	 17. LDA 6
    	 18. MLT 16
    	 19. STA 21
    	 20. BR 21
    	 21. NOOP
    	 22. LDA 12
    	 23. SUB 21
    	 24. STA 12
    	 25. LDA 12
    	 26. STA 28
    	 27. BR 28
    	 28. NOOP
    	 29. LDA 12
    	 30. MLT 28
    	 31. STA 33
    	 32. BR 33
    	 33. NOOP
    	 34. SET "The value of (A - AB) squared is"
    	 35. STA 0
    	 36. LDA 33
    	 37. STA 0
    	 38. HLT
    Study the OAM and OAMPL code side by side and ask yourself the following questions.
    1. What is the correspondance between OAMPL and OAM statements? That is, which OAM statements result from which OAMPL statements? Partition the OAM code and label each ``chunk'' accordingly.
    2. Label each NOOP place holder with a description of the data stored therein. For example, if the NOOP stores a variable value, write the name of the variable beside it.
    3. Are any OAM statements produced that don't correspond to some OAMPL statement? Which ones and why?
    4. Study the OAM code carefully. Are there any optimizations you might suggest to shorten the code? Why do you think these are difficult to identify automatically?
  3. Here is a CGI script written in OAMPL. Find 6 bugs. Are these OAMPL, HTTP, or HTML bugs?
    	 ASSIGN N 2
    	 WRITE "Content-type: text/html\n"
    	 WRITE "<HTML>"
    	 WRITE "<TITLE>List</TITLE>"
    	 WRITE "<H1>Here is a list:"
    	 LOOP (N + 1)
    	 WRITE "<LI>Ho!"
    	 END
    	 WRITE "</HTML>"