Jump to page content Jump to navigation

College Board

AP Central

AP Exam Reader
Siemens Awards for Advanced Placement

APAC 2010
Print Page
Home > AP Courses and Exams > Course Home Pages > Mighty Cabbage Patch Micro

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.





  ABOUT MY AP CENTRAL
    Course and Email Newsletter Preferences
  AP COURSES AND EXAMS
    Course Home Pages
    Course Descriptions
    The Course Audit
    Sample Syllabi
    Teachers' Resources
    Exam Calendar and Fees
    Exam Questions
    FAQs
  PRE-AP
    Teachers' Corner
    Workshops
  AP COMMUNITY
    About Electronic Discussion Groups
    Become an AP Exam Reader

Back to top