1

This is a question that's giving me a lot of trouble, but which I need to understand for my Final Exam in 2 weeks. I don't know if it's the wording, but I have no idea how to arrive at a concrete answer. Here's the question:

"Bob plans to make changes to the mechanism of LC-3 TRAP instructions. He has two ideas: Make use of the bit [8:11] of TRAP instructions. The first instruction of the trap routine is stored at the address specified in the TRAP instruction, rather than the starting address of the trap routine. In his new design, he still wants to implement as many TRAP routines as the original LC-3 TRAP. Calculate on average how many lines of instructions each TRAP routine will have in his new design."

I know TRAP has 3 fundamental TRAP Vectors, x20, x25, and x23? What does the "how many lines of instructions" even mean?

Jolta
  • 2,620
  • 1
  • 29
  • 42
David Ayala
  • 13
  • 1
  • 2
  • 4

2 Answers2

0

Is your class using the Mc Graw Hill LC-3 Simulator? Because reading through their text on the TRAP command, bits [8:11] aren't even sent to the MAR to load from memory, they're just dropped. Only bits [7:0] are used because they point to a location in the Trap Vector Table.


copyright Mc Graw Hill

Memory locations x0000 through x00FF, 256 in all, are available to contain starting addresses for system calls specified by their corresponding trap vectors. This region of memory is called the Trap Vector Table.

The Vector table is only using 6 of its 256 available trap vectors, so you could make 250 of your own Trap calls.


After trying what "Bob" was trying to do I get the following error "1024 can not be represented as an 8 bit trap vector" and when I try and manually fill in my own trap call (ex. TRAP400 .FILL xF400 ;which is 1111 0100 0000 0000) It won't run its subroutine.


That being said, your question can only mean that Bob is making his own version of the LC-3 and would like to increase the amount of trap vectors he can use. If that's the case then using bits [11:0] he could have 4,095 trap commands or 4,089 if you do not include the original 6.

I hope that helps.

Chris M
  • 651
  • 6
  • 10
  • That's what I was thinking as well, yet I'm still not sure. The last line of the question still has me perplexed, because it's asking how many lines each TRAP routine will have. It may have been how they worded the question, but in that case, shouldn't it have read, "How many different TRAP routines are possible?" Anyways thanks a lot. I'll consult with some TA's and confirm the solution and get back to this as soon as I can. – David Ayala Apr 25 '15 at 16:08
0

That's pretty vague. A Trap subroutine is as large as it needs to be to execute a particular function. But if you're only counting the required lines needed in a subroutine then you would need at least 7 (or 1 if you only wanted your routine to return to the command that called it).

Looking at TRAP x21's routine we get:

.ORIG x0430 ; syscall address
    ST R7, SaveR7
    ST R1, SaveR1
TryWrite
    LDI R1, CRTSR
    BRzp TryWrite
WriteIt
    STI R0, CRTDR
Return
    LD R1, SaveR1
    LD R7, SaveR7
    RET
CRTSR   .FILL xFE04
CRTDR   .FILL xFE06
SaveR1  .FILL 0
SaveR7  .FILL 0
.END

We have to save the registers before we use them, and load them after running our routine. We need the variables to store those registers, and lastly we need a RET command to return to the command that called the routine.

Chris M
  • 651
  • 6
  • 10