Question: HW 3 - Binary Modulo icode Behaviors: icodeoperation 0 rA = rB 1 rA + = rB 2 rA & = rB 3 rA =
HW Binary Modulo
icodeBehaviors:
icodeoperationrA rB
rA rB
rA & rB
rA read from memory at addressrB
writerAto memory at addressrB
do different things for different values ofb:
bactionrA ~rArA rArA rArA pc
do different things for different values ofb:
bactionrA read from memory atpc rA read from memory atpc rA &read from memory atpc rA read from memory at the address stored atpc
In all cases, increasepcby not at the end of this instruction
ComparerAas an bit scomplement number to; ifrA setpc rB otherwise, incrementpclike normal.
Task
code should
Load the values in memory at addressesxandxinto registersNote: since we have not discussed ways to get other data into our memory yet, we will directly modify your code so that the second x and fourth x bytes are the input values.This means your first x and third x bytes instructions should be very specific operations.
Compute the modulo of those values iewhats at x mod whats at x
Store the product at address xD
Halt once it is done
For example, ifmodbinarybeginsthen when it is finished it should havein address xD; in decimal, that is mod which is IfmodbinarybeginsF Athen when it is finished it should havein address xD; in decimal, that is mod which is
Note: We should be able to change the second and fourth bytes of your program to do other modulo calculations too.
You may assume that neither value will be negative, but either may be zero.If either operand is your code should set the value at xD to x
Hints, tips, and suggestions
How to compute modulo
Modulo,amodnora n is defined as the remainder when dividingabyn As in our examples above with mod
where the quotient is and the remainder is Therefore, mod TheWikipedia pageon modulo has a more formal definition.
Hint: For the division operation, think along the lines of how many times can
fit into
You may wish to consider multiples of
Youdefinitelywant to make sure you can write working code for this in some language you know well before trying to convert that code into binary.
How to write binary
We suggest following these steps, carefully, saving the result of each in a file so you can go back and fix them if they were wrong:
Write pseudocode that does the desired task
Convert anyforloops towhileloops with explicit counters
Change anyiforwhileguards to the formsomething
a bbecomesab
a bbecomesa bbecomesab
a bbecomes babecomesba
a bbecomes babecomesba
a bbecomesab becomesabbecomesab
a bbecomesab becomesabbecomesab
Add more variables to split multioperation lines into a series of singleoperation lines
Add more operations to convert ones not in the instruction set into ones in the instruction set
Change each loop into a pair of instructions, opening with spotpc and closing with if gotospot
Count the number of variables neededIfit is skip to step
else continue with next step
Pick a memory address for each variable. Make these big enough your code is unlikely to get that big; for example, you might pickxthoughx number of variables
Convert each statement that uses variables intoregister load variables memory
original statement
store variables memory register
translate each instruction into numeric icodeab triples, possibly followed by aMpcimmediate value
turn icodeab into hex
Write all the hex intomodbinary
Debugging binary is hard. Thats part of why we dont generally write code in binary. If you get stuck, you should probably try pulling just the part you are stuck on separate from the rest and test it until it works, then put it back in the main solution.
Code:
D FF
Still producting errors.
Hints and Comments:
looped forever for example, try mod
wrong result for example, try mod
Please note the values are displayed in decimal, not hexadecimal.
Zero
Correct! mod gives
Zero
Correct! mod gives
Even divide
Correct! mod gives
Big difference
mod runs forever
mod gives but should give
Gives
mod gives but should give
Random
mod gives but should give
Random
mod gives but should give
Random
mod gives but should give
Random
mod runs forever
mod gives but should give
Random
mod gives but should give
Random
mod gives but should give
Random
mod gives b
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
