This program needs to be completed using LC3 into a single .asm file.
Brainfry
The objective of this assignment is to put into practice the learnt assembly concepts and problem- solving skills in order to decompose and implement a complex task (by the standards of assembly programming) while testing your ingenuity. You will be implementing a compiler for an eso- teric programming language called Brainfry (reminiscent of a similar, not-so-appropriately-named language).
Brainfry is an esoteric programming language that uses a small set of simple commands to manipulate a virtual tape of memory cells. The tape is represented as an array of memory cells, each of which can hold a single data byte. The commands in Brainfry manipulate the tape by moving the tape head (which is a pointer to the current memory cell) left or right, incrementing or decrementing the value of the current memory cell, and accepting or outputting the value of the current memory cell.
The commands in Brainfry are:
>: move the tape head to the right.
<: move the tape head to the left.
+: increment the value of the current memory cell.
-: decrement the value of the current memory cell.
.: output the value of the current memory cell as an ASCII character.
,: input a value from the user and store it in the current memory cell.
[: if the value of the current memory cell is 0, jump to the corresponding ] command.
]: if the value of the current memory cell is not 0, jump to the corresponding [ command.
All other input characters are ignored. The program written in Brainfry is executed by an interpreter that reads the commands one by one and executes them to manipulate the (contents on the) tape.
Constraints and simplifications
Usually, Brainfrys tape is 65k (65,000) elements long. However, to accommodate the limitations of LC3, your tape does not have to be longer than 5k, and its guaranteed that the programs that we submit to your compiler will not go into negative tape indexes.
Additionally, a normal Brainfry program would stop when it reads the EOF (End of File) symbol, however, to simplify this, we have decided to add a ~ character to symbolise End of Program. What follows after this symbol is the input to the Brainfry program. Note that all programs are built to read deterministic code.
Furthermore, for this assignment, all memory has been set to 0; you do not need to preset it.
Examples:
Input1:
+>>
This code runs at pointer offset two and unknown bit width; don’t
assume you have more that eight bits
======= DEMO CODE =======
First just print “Hello”
Notice that I reset the cells despite knowing that they are zero
this is a test for proper functioning of the ability to skip over
a loop that’s never executed but isn’t actually a comment loop
Secondly there’s a NOP movement between the two ‘l’ characters
Also there’s some commented out code afterwards
>[-]<[-]++++++++[->+++++++++<]>.—-[–<+++>]<-.+++++++.><.+++.
[-][[-]>[-]+++++++++[<+++++>-]<+...--------------.>++++++++++[<+
++++>-]<.+++.-------.>+++++++++[<----->-]<.-.>++++++++[<+++++++>
-]<++.-----------.--.-----------.+++++++.----.++++++++++++++.>++
++++++++[<----->-]<..[-]++++++++++.[-]+++++++[.,]-]
===== END DEMO CODE =====
<<-
~
Output1:
Loaded program in memory
+>>
This code runs at pointer offset two and unknown bit width; don’t
assume you have more that eight bits
======= DEMO CODE =======
First just print “Hello”
Notice that I reset the cells despite knowing that they are zero
this is a test for proper functioning of the ability to skip over
a loop that’s never executed but isn’t actually a comment loop
Secondly there’s a NOP movement between the two ‘l’ characters
Also there’s some commented out code afterwards
>[-]<[-]++++++++[->+++++++++<]>.—-[–<+++>]<-.+++++++.><.+++.
[-][[-]>[-]+++++++++[<+++++>-]<+...--------------.>++++++++++[<+
++++>-]<.+++.-------.>+++++++++[<----->-]<.-.>++++++++[<+++++++>
-]<++.-----------.--.-----------.+++++++.----.++++++++++++++.>++
++++++++[<----->-]<..[-]++++++++++.[-]+++++++[.,]-]
===== END DEMO CODE =====
<<-
~Hello
===
HALT detected
Input2:
++++++++[>+>++++<<-]>++>>+<[-[>>+<<-]+>>]>+[
–<<<[
->[+[-]+>++>>>-<<]<[<]>>++++++[<<+++++>>-]+<<++.[-]<<
]>.>+[>>]>+
]
~
Output2:
Loaded program in memory
++++++++[>+>++++<<-]>++>>+<[-[>>+<<-]+>>]>+[
–<<<[
->[+[-]+>++>>>-<<]<[<]>>++++++[<<+++++>>-]+<<++.[-]<<
]>.>+[>>]>+
]
~ *
* *
* *
* * * *
* *
* * * *
* * * *
* * * * * * * *
* *
* * * *
* * * *
* * * * * * * *
* * * *
* * * * * * * *
* * * * * * * *
* * * * * * * * * * * * * * * *
* *
* * * *
* * * *
* * * * * * * *
* * * *
* * * * * * * *
* * * * * * * *
* * * * * * * * * * * * * * * *
* * * *
* * * * * * * *
* * * * * * * *
* * * * * * * * * * * * * * * *
* * * * * * * *
* * * * * * * * * * * * * * * *
* * * * * * * * * * * * * * * *
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
===
HALT detected
I have a zip folder of all the inputs and expected outputs.