Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Part B: Remainder by subtraction (pipb.asm) Pip does not have a remainder operat

ID: 3851676 • Letter: P

Question

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.

Explanation / Answer

For example, range(5, -1, -1) means list of numbers from 5 down to 0 (-1 is the exclusive boundary), step down by 1.

As to the while loop: