Reputation: 457
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?
Upvotes: 0
Views: 1467
Reputation: 58467
"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.
Upvotes: 2