Question
5 instructions: if( x == 0 ) go to line L x = x - 1 x = x + 1 go to line L
5 instructions:
- if( x == 0 ) go to line L
- x = x - 1
- x = x + 1
- go to line L
- stop
We will ask you to write several programs using the above instructions. Note that you cant use anything else apart from these given instructions. But once you have implemented a new instruction, you will be allowed to use it in the next task.
EXAMPLE: Lets start with a simple example. Suppose we ask you to achieve x=0, i.e. to set the contents of a given location to 0. x=0 is not listed in the given instruction, so we must implement it ourselves. The solution is shown below.
(1) if(x == 0) goto (4)
(2) x = x-1
(3) goto (1)
(4) stop
As just mentioned, once we have written a code to achieve a new type of instruction, we will be allowed to use the new instruction in the following tasks. So from now on, x=0 is allowed to be used in our code.
Your task for this worksheet is to write programs with the given mini-assembler to perform the following functions.
- multiply x to y, i.e. x = x*y [4 marks]
- divide x by y, i.e. x = x/y. This is an integer division. The reminder should be stored in z. For example, after 10/3, x should be 3 and z should be 1. [4 marks]
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