Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

The aim of this task is to show that we can use a Turing Machine equivalent language, a mini-assembler, starting from a very small and

image text in transcribed
The aim of this task is to show that we can use a Turing Machine equivalent language, a mini-assembler, starting from a very small and simple set of instructions, building up more and more complex operations. We also hope that you will improve your problem solving and programming skills through this excercise. . Assume that we have an abstract machine that provides five instructions shown in the box below: Note that a variable x refers to a memory 5 instructions: location, and the value of x refers to the current if(1-0) go to line L value held in that memory location. I=I-1 You can use as many variables as you wish. II+1 Initially all memory locations hold a go to line L random positive integer. For the sake of stop simplicity, we assume that the machine can't handle negative numbers. We will ask you to write several programs using the above instructions. Note that you can't 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. Let's start with a simple example. Suppose we ask you to achieve "Y=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) I-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. (a) copy y to x (at the end, contents of y should be unchanged), ie x-y [4 marks] (b) add y to x, i.e. x - x+y (again contents of y should be unchanged) [4 marks] (c) work out the difference between x and y, i.e. z= abs(x-y) [4 marks] (d) if(x >y) goto L1 else goto L2 [4 marks) (e) multiply x to y, i.e. x=x*y [4 marks] (f) 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

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Put Your Data To Work 52 Tips And Techniques For Effectively Managing Your Database

Authors: Wes Trochlil

1st Edition

0880343079, 978-0880343077

More Books

Students also viewed these Databases questions

Question

=+7. What lifestyle traits does your key public have?

Answered: 1 week ago