0

For academic purposes, I am being asked to translate this statement

assign x the value 5

Into a machine code that is made up by an author of a computer science book, called brookshear machine code. I am given a hint that is

(HINTS: Assume that the value of x is to be stored into main memory location 47. Your program would begin by loading a value into a register. You do not need to specify the memory locations of your program. Don't forget to end the program with the HALT instruction.)

I am wondering if anyone knows the best way to approach this? He makes it clear to end with the halt instruction but I am unsure what exactly I should be doing.

0iii - No-operation
1RXY - Load register R with contents of location XY
2RXY - Load register R with value XY
3RXY - Store contents of register R at location XY
4iRS - Move contents of register R to register S
5RST - Add contents of registers S and T as binary numbers, place result in register R
6RST - Add contents of registers S and T as floating-point numbers, place result in register R
7RST - OR together the contents of registers S and T , place result in register R
8RST - AND together the contents of registers S and T , place result in register R
9RST - XOR together the contents of registers S and T , place result in register R
ARiZ - Rotate the contents of register R one bit to the right, Z times
BRXY - Jump to instruction at XY if contents of register R equal contents of register 0
Ciii - Halt
DRXY - Jump to instruction at XY if contents of register R are greater than contents of register 0
R,S,T - Register numbers
XY - A one-byte address or data value
Z - A half-byte value
i - Ignored when the instruction is de-coded: usually entered as 0

Above is the machine language I am expected to use.

1 Answer 1

1

If only there were an instruction:

 EABXY - Store value XY at location AB

If that command existed, your program would be:

 E4705   # store '05' at address '47'
 C000    # halt

But, that instruction doesn't exist -- partly because it takes five half-byte characters, and the instructions are meant to fit into four.

So you're going to have to simulate the 'E' instruction using two steps.

You can't specify a value to put into an address directly.

  • There is one instruction that lets you specify a value and put it somewhere.
  • There is one instruction that copies a value from somewhere, into an address

That's really enough clues.

Sign up to request clarification or add additional context in comments.

6 Comments

Thank you for responding, so I am still in "guessing" mode here because I dont understand how to break up "assign x" and "the value 5" into two 4 digit codes. I would say 1R58 - 58 because 58 in hex is the letter X THEN 2558 - 2 because this is step 2 5 because i want 58 to go into register 5 THEN c000
I would start with the op-code which would be 1 right? after that is where I get lost.
THANK you Slim. I will look this over and figure it out.
1R05 3R47 C000 Is what I got
Wonderful! Thank you I am now being asked assign halfway the value length + width Is there another way we can talk other than the comment box? I could really use your help if you are up for it =)
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.