Lab 3


This lab will further familiarize you coding in MAL. One of the important points of the lab is getting familiar with the idea that memory is a contiguous chunk of storage, and that your program resides in memory while executing.

Submit: self-mod.mal, README

Problem: Write a program which does the following:

ArithmeticLoop:

(*) You will want to write a generic arithmetic operation as a placeholder in the the program until you know which operation you will want to perform. For example, you should code add $s1, $s2, $s3 on the arithmetic computation line. If the user enters / - or *, you can then change that line of code to:

Notice that since you must wait for the user's input to make the change in your code, you must write code that modifies itself - this is what is meant by the term self-modifying code. In order to change code in your program, you must do all the same things as you would to change any other part of memory. You must find the address of the location you need to write to, then get the value you want to write, and then write that value to the memory location.

Last Hints:
In machine code add/xor/or/and/sub each is one word of memory.
In machine code,
xor $s1, $s2, $s3 = 0x02538826
or $s1, $s2, $s3 = 0x02538825
and $s1, $s2, $s3 = 0x02538824
nor $s1, $s2, $s3 = 0x02538827
sub $s1, $s2, $s3 = 0x02538822

Notes/Requirements: Your Integer input/output routines should be general - they should work for values up to 2^31 - 1. You can use the routines you developed in lab 2.

Collaboration with other students is allowed on this lab assignment! Make SURE you give other students and tutors credit for any help you receive and any code you develop together. Even if you develop some code with someone else and give credit, it still must be your own! This means if you can't write it, you can't use it! Give credit to any help you receive. Rewrite all your code "in your own words" to guarantee that it really is yours. And give credit. Give credit.

Evaluation: your lab tutor will assign one of following grades: check +, check, check -, 0

NOTE: A BAD OR MISSING README WILL DROP YOUR SCORE BY ONE FULL GRADE!

Be sure that you're enrolled in the laboratory that you are attending; the lab tutors will have a list of those who are in their lab session.