|
|
|
 |
 |
 |
|
Mighty Cabbage Patch Micro
|
|
|  |
by Reg Hahne Atholton High School Columbia, Maryland
 |
|
|  |
More Nifty Assignments...
Assignment
The Mighty Cabbage Patch micro has a single register (called the accumulator) and six instructions:
LDA X -- Copies the contents of memory location X into the accumulator
STA X -- Copies the contents of the accumulator into memory location X
ADD X -- Adds the contents of memory location X to the accumulator
SUB X -- Subtracts the contents of memory location X from the accumulator
MUL X -- Multiplies the accumulator by the contents of memory location X
DIV X -- Divides the accumulator by the contents of memory location X
Write a program that reads an infix expression containing single-letter operands, the operators +, -, *, and /, and possibly parentheses. The program should print a sequence of instructions that will evaluate the expression and leave the result in the accumulator. Use variables of the form Tn as temporary variables (i.e., T0, T1, T2 . . ., T9).
| Infix expression: |
(V + W * X) / (Y - Z) |
| Postfix expression: |
(V + W * X) / (Y - Z) |
| Assembly language code: |
LDA W
MUL X
STA T0
LDA V
ADD T0
STA T1
LDA Y
SUB Z
STA T2
LDA T1
DIV T2
STA T3
|
Contribute
If you would like to contribute your suggestions for nifty assignments, please submit your ideas.
|
|
|
|
|
|