2
votes

In an assignment to instruction set, we are told to write a sequence of instructions for arithmetic operations needed in different architecture models: accumulator, stack, load/store, memory/memory.

Given:

  • Opcode - 8 bits
  • Memory addresses - 16 bits
  • All registers are coded with 4 bits
  • All data operands - 32 bits
  • All instructions must be of an even number of bytes, i.e. 8 x N bits, where N is a natural number.

AND! Addresses of registers can be packed together

Question 1: When do we pack two registers together? How does the system know it's not one register coded into 4 bits? Could you please give me an example?

Say, we are given A = B + C. Instructions needed in the load/store model for this operation:

1. load r2, B;
2. load r3, C;
3. add r1, r2, r3;
4. store r1, A.

The 1st instruction is 28 bits long, so we need additional 4 bits.

Question 2: Does it make difference where to put the 4 bits in form of 0000? How would you make the instruction of a whole number of bytes?

I'll appreciate your help very much.

1
That'd be up to you on how you design your instruction set. Perhaps you need a NOP operator which is a do-nothing 4bit instructions you can stuff anywhere you end up with a non-32bit size. - Marc B
Thank you for the reply. Could you please tell me, when do we want to pack two registers in one? F.e., I use registers r1 and r2 and encoded they look like 0001 and 0010. Can I write them both with only 4 bits? How would they look like? Something like 0110? I'm totally confused. - Ina
Like I said, that's up to you. it's your instruction set, and up to you to decide how to represent it. - Marc B

1 Answers

1
votes

Although the question seems a bit vague, I'll risk an answer and maybe generate a useful discussion.

Question 1: When do we pack two registers together? How does the system know it's not one register coded into 4 bits? Could you please give me an example?

The ID (Instruction Decoder) in the CPU will read the opcode first. This means that once it knows the instruction it has to decode, it knows how to interpret the following bits. You can code your registers on 4 bits, meaning that you have 16 registers. But imagine you have an instruction that is restricted to operate only on 2 registers from a subset of 4 registers. In this case you can use only 4 bits to identify the 2 registers. In this way you packed in 4 bits the "identificators" of 2 registers.

Question 2: Does it make difference where to put the 4 bits in form of 0000? How would you make the instruction of a whole number of bytes?

It counts where you put the 4 bits. Depending on each opcode, the instruction decoder knows where to get the address of the register it uses. For example, for load instruction, if you designed the instruction to have the 4 bits just after the opcode, when the decoder identifies load, if will interpret the next 4 bits as register identifiers.

I don't believe you are constrained to use a whole number of bytes in the sense that every bit in the instruction has a meaning. The instruction can be a whole number of bytes by just containing some unused bits (usually at the end).