0

So in this class we are dealing a lot with the LC-3 assembly language. For the problems on one of our homework assignments we are given this:

"Suppose we have 16 general-purpose registers, 60 opcodes, an instruction size of 20 bits, and 64K bytes of memory space available. a) If we want a LD DR, offset instruction, how many bits are available for the offset?"

How would I go about finding this? In class, we work with LC-3 which I already know has an instruction size of 16 bits, where the opcodes are 4 bits, the memory locations are 3 bits (R0 - R7), and the offset can be figured out. We never learned how to calculate these on our own though... So I have no idea how to figure out how long the opcodes for the instructions will be in this language that has an instruction size of 20 bits, or even how many bits the memory locations are. Can anyone please help?

GenericUser01
  • 337
  • 3
  • 11
  • 27

1 Answers1

2

"Suppose we have 16 general-purpose registers, 60 opcodes, an instruction size of 20 bits, and 64K bytes of memory space available. a) If we want a LD DR, offset instruction, how many bits are available for the offset?"
How would I go about finding this?

Let's break it down:

LDR    DR,    offset
^      ^      
|      general-purpose register
opcode

The question says that there are 60 possible opcodes, so you need ceil(log2(60)) == 6 bits to be able to encode all possible opcodes.
It then says that there are 16 GPRs, and you'd need ceil(log2(16))== 4 bits to be able to encode the use of any of those.

After having used up 6 + 4 == 10 bits for the opcode and GPR, that leaves us the remaining 10 bits to encode anything else. In this particular case, "anything else" appears to be just the offset, so you've got 10 bits available for the offset.

Michael
  • 57,169
  • 9
  • 80
  • 125
  • Wow, thank you so much! That helps a lot. So basically you just look at the ceiling value of powers of 2? So for instance, there are 60 opcodes, so take the ceiling value of some power of 2 that is closest to 60? – GenericUser01 Sep 02 '15 at 15:01
  • Sort of, yes. log2 can be used to find the number of bits required to represent a given number, because the definition of the logarithm of x to base b is such that if b^y = x, then logb(x) = y. In our case b=2 and x=60, so y = log2(60), which is approximately 5.91. And since most computers don't deal with fractional bits we apply the ceiling function to that, and get 6. – Michael Sep 02 '15 at 15:09