computer science and coding

Watch this thread
Badges: 2
? You'll earn badges for being active around the site. Rep gems come when your posts are rated by other community members.
Report Thread starter 3 years ago
can someone help me and provide me the code for this.

this is the coursework:

Running the script and model output
Your script should be named (validate the syntax of given MIPS instructions and
split the contents of the input file in two output files, one containing correct instructions and
the other incorrect ones). It should be run with three arguments: the input file and the two
files to store the correct and incorrect instructions. All three files and the script should be
created in your home directory, under CS1420/coursework. An example of how to run the
script from the shell is:
./ input.txt correct.txt incorrect.txt
The contents of the input file is included below. Note the minor difference between the input
file contents and the official MIPS syntax, namely the omission of the comma between
instruction arguments. This is done to simplify string processing. Also, to make things
easier, each instruction starts on a new line.
1 # input . txt
2 add $s0 $s1 $s2
3 sub $s2 $t0 $t3
4 add $s0 $s1 $z2
5 lw $t1 8( $t2 )
6 addi $t3 $s0 -9
7 sw $s3 4( $t0 )
8 lw $t11 70000( $s0 )
After running, the following output is expected:
add $s0 $s1 $z2
Unrecognised register name z. Use s or t.
lw $t11 70000( $s0 )
Incorrect register no. Temporary registers are numbered 0 to 9.
Out of bounds immediate . Should be between -32768 and 32767.
The first error message is triggered by the third instruction in the input file, where the
second source operand is a register that does not exist, namely z. The second and third
error messages correspond to the last input instruction, where number 11 is used for a
temporary register, even though there are only 9 of those, and 70000 is listed as the offset,
a value that cannot be expressed on the 16 available bits. Bear in mind that your script
should be able to detect a wider range of syntax errors than the ones illustrated in this
example (see next section for a full list).

The script should also separate the correct instructions from the incorrect ones. The two
output files are shown below.
1 # correct . txt
2 add $s0 $s1 $s2
3 sub $s2 $t0 $t3
4 lw $t1 8( $t2 )
5 addi $t3 $s0 -9
6 sw $s3 4( $t0 )
8 # incorrect . txt
9 add $s0 $s1 $z2
10 lw $t11 70000( $s0 )
4 Requirements
Your script must provide the functionality described in the list below.
R1 The number of arguments when running must be 3 (the input file and the
two output ones). Otherwise, an error message should be displayed notifying the user
that default files will be considered, namely input.txt (that you must create yourself
in the working directory - see section 3 for what it needs to contain), correct.txt and
R2 The instructions in input.txt are read one by one. For each of those, the checks
listed below must be performed (in separate functions). In case an instruction fails
one (several) of the checks, the appropriate error message(s) will be displayed.
R2.1 The instruction mnemonic should be one of add, sub, addi, lw and sw.
R2.2 The number of parameters following the mnemonic must be 3 for add, sub, addi
instructions and 2 for lw, sw instructions. Note that instruction parameters are
separated by a white space in the input file (see the content of input.txt in
section 3).
R2.3 The syntax of each register must be: the $ character, followed by either s or t
and a legal register number (check the lecture slides to remind yourself of how
many store registers and temporary ones are available in the MIPS architecture).
R2.4 Immediates (the second source operand of the addi instruction and the offset in
the lw and sw instructions) are represented on 16 bits. The script should check
that the immediate value is within the representable range (check the lecture
slides for details on immediate representation).
R2.5 The second parameter for lw and sw instructions contains both an immediate and
a register. The check function for this should call the functions associated to
R2.4 and R2.3.
R3 When an instruction is found to be correct (all checks associated to R2 pass), it
should be written to file correct.txt (or the file specified in the second
argument). The remaining instructions should be stored in file incorrect.txt (or the

file given as the third argument). The input file should not be modified.
The errors (if any) should be displayed in the terminal (not in any of the files).
Badges: 19
? You'll earn badges for being active around the site. Rep gems come when your posts are rated by other community members.
Report 3 years ago
(Original post by Ahmed5411)
can someone help me and provide me the code for this.

this is the coursework:
Nobody is going to just do your coursework for you. Make a good faith attempt at solving your problem first, then if you get stuck, ask about specific problems with whatever you've tried so far, describe the actual problem(s) you're having and what your understanding of those problem is.
Last edited by winterscoming; 3 years ago

Quick Reply

Attached files
Write a reply...
new posts
to top
My Feed

See more of what you like on
The Student Room

You can personalise what you see on TSR. Tell us a little about yourself to get started.


How did your AQA A-level Psychology Paper 1 go?

Loved the paper - Feeling positive (262)
The paper was reasonable (257)
Not feeling great about that exam... (53)
It was TERRIBLE (44)

Watched Threads

View All