Question: Lab 5 - Binary Fibonacci This lab you will write binary code ( using our Toy ISA ) you will run your code on our
Lab Binary Fibonacci
This lab you will write binary code using our Toy ISA you will run your code on our online simulator
The Instructions
The instructions from our machine are below for reference.
icode Behaviors:
icode operation
rA rB
rA rB
rA & rB
rA read from memory at address rB
write rA to memory at address rB
do different things for different values of b:
b action
rA ~rA
rA rA
rA rA
rA pc
do different things for different values of b:
b action
rA read from memory at pc
rA read from memory at pc
rA & read from memory at pc
rA read from memory at the address stored at pc
In all cases, increase pc by not at the end of this instruction
Compare rA as an bit scomplement number to ; if rA set pc rB otherwise, increment pc like normal.
Running programs
You should create two files
One you work with, that has comments and notes to keep you sane. Call this anything you like.
One you run and submit, which contains nothing by hex bytes separated by white space. Youll submit this as a file named fib.binary
To our online simulator and click the file upload button at the top of the page to load your fib.binary into the simulators memory.
Your Task
Create a binary program ie a file containing hex bytes that runs in this language; name the file fib.binary.
When run in a simulator homeworkfilestoyisasim.html fib.binary should change the contents of memory for all addresses i C placing in address i the ixCth Fibonacci number modulo since these are bytes
Once xC through xFF are set, halt by running an instruction with the reserved bit set.
The file fib.binary itself must not contain more than C hexadecimal bytes.
It should be the case that running your simulator on fib.binary for many cycles should result in output ending with the following:
xccf: d e db
xddf: d d cf f b dd
xeef: e e c b a cb d a dd f e
xfff: e ad f a d d e bb
Your code should not change the byte stored in address x during its run. Your code must finish within clock cycles.
Hints, tips, and suggestions
How to compute Fibonacci numbers
Keep track of two numbers, current and previous. Start them both off at
Let next be the sum of current and previous.
Rename current previous, next current in that order
Repeat
You definitely want 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 any for loops to while loops with explicit counters
Change any if or while guards to the form something
a b becomes ab
a b becomes a b becomes ab
a b becomes ba becomes ba
a b becomes ba becomes ba
a b becomes ab becomes ab becomes ab
a b becomes ab becomes ab becomes ab
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 spot pc and closing with if goto spot
Count the number of variables needed
If it 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 pick x though x number of variables
Convert each statement that uses variables into a register load variables memory b original statement c store variables memory register
translate each instruction into numeric icode a b triples, possibly followed by a Mpc immediate value
turn icode a b into hex
Write all the hex into fib.binary
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. Please know that your TAs are here in lab to help as well!
Please show me how to code this my code doesn't work.
My code: C
Feedback:
Check submitted files
Missing fib.binary
If you submitted a file named "fib.binary.txt you may ignore this message,
butfor future labs you will have to rename and resubmit.
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
