-1
$\begingroup$

Yes, this is a homework question, I've tried working it out and was hoping I could get pointed in the right direction.

Here's the question:

You are designing the instruction set for a new type of computer. The computer has 64 instructions, 16 general-purpose registers. It supports a byte-addressable memory of up-to 32MB. Answer the following questions. a. For a 3-operand ADD instruction that only uses register addressing mode, how long (number of bits) should the instruction be? b. For a 2-operand ADD instruction, in which one of the operands is a memory location with direct addressing mode, how long (number of bits) should the instruction be?

I know the question's been asked recently but both questions and answers weren't helpful.

I know that with 64 instructions and 16 registers, there must be 4 bits per register. I don't exactly know the usage for the 32MB memory right now.

A similar example of part (a) exists on wikipedia, where it states 4 instructions are needed for a 3-operand register addressing mode (load reg1 into a, load reg2 into b, add reg1 and reg2 to reg3, store reg3 in c). Because it mentions 4 instructions, I thought that would be 1 bit, but that's a really small amount. There are 3 registers used in the instruction, which would be 12 bits.

For part (b), I believe one is a memory location with direct addressing mode (as stated) and the other is like part (a), using register addressing mode. There are only two operands, but only one is using register addressing mode, meaning only one register is used? In that case, the length of the instruction should be 4 bits.

I would appreciate any help! If I'm misunderstanding some of the terms please let me know! Thanks!

$\endgroup$
  • $\begingroup$ im kind of confused, I also need the problem, so for part a there is 64 instruction, 16 registers and 32 MB, and the part a is asking for 3 opperand add. so would that be 3(log2(64) +log2(16) + 25(which is from 32MB))? is that right? so that would be 3(6+4+25) = 105? $\endgroup$ – Oscar Jan 28 '14 at 20:02
3
$\begingroup$

Hint: If there are $X$ of some resource, then it takes $\log_2 X$ bits to encode which of them you chooses. This includes instructions, registers, and memory locations. If you are encoding $N$ copies of the resource, you will need $N\log_2 X$ bits. The instruction should contain an encoding of everything needed to specify it, including the instruction itself.

(Real life CPUs don't quite behave this way. For example, common instructions could have shorter length.)

Example: A computer has $956$ instructions. The instruction NOP takes $\lceil \log_2 956 \rceil = 10$ bits.

Another example: A computer has $13$, and $100$ I/O ports. The instruction IN , which reads a byte from the port into the accumulator, takes $\lceil \log_2 13 \rceil + \lceil \log_2 100 \rceil = 11$ bits.

Yet another example: A (useless) computer has a single instruction but $10000$ registers. The single instruction takes $10$ of them and does something really complicated. It takes $\lceil \log_2 1 \rceil + 10 \lceil \log_2 10000 \rceil = 140$ bits to encode.

$\endgroup$
  • $\begingroup$ Ah, so in part a we are considering 3 registers and 1 ADD instruction, making it 1(log2(64))+3(log2(16)) = 18 bits. In part b we consider 1 ADD instruction and 1 register since one operand is from memory, so it takes 1(log2(64)) + 1(log2(16)) = 10 bits. Thank you Yuval! $\endgroup$ – user3238833 Jan 27 '14 at 5:03

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.