Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Brainfry The objective of this assignment is to put into practice the learnt assembly concepts and problemsolving skills in order to decompose and implement a
Brainfry
The objective of this assignment is to put into practice the learnt assembly concepts and problemsolving
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 esoteric
programming language called Brainfry reminiscent of a similar, notsoappropriatelynamed
language
Description
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
headwhich 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 jump to the corresponding command.
: if the value of the current memory cell is not 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.
Example
This loop is an "initial comment loop", a simple way of adding a comment
to a BF program such that you dont have to worry about any command
characters. Any and characters are simply
ignored, the and characters just have to be balanced. This
loop and the commands it contains are ignored because the current cell
defaults to a value of ; the value causes this loop to be skipped.
This is a comment
This is also a comment but
The instruction above got executed
~
You can now look at the second memory register, and you should see the value x in there.
Constraints and simplifications
Usually, Brainfrys tape is k elements long. However, to accommodate the limitations of
LC your tape does not have to be longer than k 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.
Act as all memory has been set to ; you do not need to preset it
Write the code for it in LC assembly
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started