Two Pip programs
This is a pair assignment worth 15 points.
The objective of this assignment is to
write Pip programs that use jumps to approximate a Python if-else
statement and a while statement.
should begin with comments (starting with ';') including your names,
a brief description of what the program does and information on any
help you received on
the project. If it
is entirely your own
work, say so. If
anyone helped either of you,
identify them by name and describe how they helped.
Remember to turn in your work online. Have one member turn in the files for the work
and each turn in logs, as for the last assignment.
You are to write two separate chunks of Pip code. Call the files
pipa.asm and pipb.asm, and test each separately in
pipGUI.py. Initial skeletons for pipa.asm and pipb.asm are
in pipFiles. Add the initial required comments at the top of the
first file. Remember, in assember comment lines start with a
Do not have initial statements to set values for the variables.
Instead set memory values in the simulator before each test of
your chunk of code. (This saves time.)
Part A An if-else construction (pipa.asm)
Write Pip assembler code equivalent to the Python below. The easiest way and most encouraged way is using symbolic code labels as needed (followed by a colon) and symbolic data names, as understood by pipGUI.py. You may do it with numeric
data addresses and/or numeric jump addresses as in the book or the
book's applet, but in that case, do make a comment as to what memory
locations represent the x, y, and z of the Python version!
if x < 0:
y = y + 2
y = x
z = y + z
You are encouraged to
- write to a file pipa.asm. (You can start with the stub pipa
- load it into pipGUI.py,
- give values manually to x, y, and z,
- run to test the results.
- Press INIT and go back to set new x, y, z values and test some more...
Part B: Remainder by subtraction (pipb.asm)
Pip does not have a remainder operation as in Python. One way to simulate y = y % x with positive x and y is
while y >= 0:
y = y - x
y = y + x
After the loop, y < 0 for the first time. After the last line
it is back to the proper range for the remainder: 0 <= y < x. Play computer to see that this works!
Convert that code to Pip assembler file pipb.asm and test as in part
A. The while loop condition translation is trickier here than in
the earliest while translation example.
The pipb.asm starter file has a hint!