Fri, 4 Sep 2020, 20:31
My students, A student writes, and I think my answers may be useful to others in the class. So I will respond to all of you. I will take each of his questions in turn:> Good Night Dr. Patt, > > I was looking back at our Interrupt lab from EE 306 last fall, and had 4 > questions about how the assembler assembles this file. I've also > attached the specific program for reference. > > Firstly, this lab has 3 .ORIG pseudo-ops, and 2 .END pseudo-ops. One set is > to mark the start and end of the "OS" code that initializes the vector > table and enables interrupts. Another set marks the start and end of our > user program. The final set marks the ISR for keyboard interrupts. *What > does having multiple sets of .ORIG and .END statements look like in the > assembled version of the program? *Normally, the first line of the program > is the starting address. But in this case, there are 2 starting addresses.
The reason for the multiple .ORIG was a jury-rigged solution to get the various pieces of code in the right places in memory for that particular EE306 assignment. For this assignment you can assume one .ORIG, one .END, and all your code inbetween.> Second, *do we need to account for programs with multiple .ORIG and .END > statements in Programming Lab 1? *
No.> Third, *do we have access to the labels from one part of the program (For > example the 'OS' in other parts of the program (For Example the User > Space)? *
In general yes, via the .EXTERNAL pseudo-op. In this case, and in 460N in general, it is not necessary.> We also put labels on the same line as a .STRINGZ operator. In this case, > the label pointed to the start of the string. My fourth question, asks *where > a label would point if it was placed before the first .ORIG statement of a > program. *
Nothing is placed before the .ORIG pseudo-op. If you do, you should get an assemble-time error.> Thank you for your response, > <<name withheld to protect the student who is thinking about EE306>>
Good luck with Lab 1 and the rest of the course. YNP> ; Unfortunately we have not YET installed Windows or Linux on the LC-3, > ; so we are going to have to write some operating system code to enable > ; keyboard interrupts. The OS code does three things: > ; > ; (1) Initializes the interrupt vector table with the starting > ; address of the interrupt service routine. The keyboard > ; interrupt vector is x80 and the interrupt vector table begins > ; at memory location x0100. The keyboard interrupt service routine > ; begins at x1000. Therefore, we must initialize memory location > ; x0180 with the value x1000. > ; (2) Sets bit 14 of the KBSR to enable interrupts. > ; (3) Pushes a PSR and PC to the system stack so that it can jump > ; to the user program at x3000 using an RTI instruction. > > .ORIG x800 > ; (1) Initialize interrupt vector table. > LD R0, VEC > LD R1, ISR > STR R1, R0, #0 > > ; (2) Set bit 14 of KBSR. > LDI R0, KBSR > LD R1, MASK > NOT R1, R1 > AND R0, R0, R1 > NOT R1, R1 > ADD R0, R0, R1 > STI R0, KBSR > > ; (3) Set up system stack to enter user space. > LD R0, PSR > ADD R6, R6, #-1 > STR R0, R6, #0 > LD R0, PC > ADD R6, R6, #-1 > STR R0, R6, #0 > ; Enter user space. > RTI > > VEC .FILL x0180 > ISR .FILL x1000 > KBSR .FILL xFE00 > MASK .FILL x4000 > PSR .FILL x8002 > PC .FILL x3000 > .END > > .ORIG x3000 > ; *** Begin user program code here *** > LEA R0, string > loop PUTS > JSR delay > Br loop > delay LD R1, int > adder ADD R1,R1,#-1 > Brnp adder > RET > int .FILL xFFFF > string .STRINGZ "====================\n* * *******\n* * *\n* * *\n* * *\n **** *\n**** **** ****\n* * *\n**** * ****\n* * *\n**** **** ****\n====================\n" > ; *** End user program code here *** > .END > > .ORIG x1000 > ; *** Begin interrupt service routine code here *** > ST R0, zero > LD R0, newLine > OUT > LDI R0, KBDR > LD R2, above > ADD R2, R2, R0 > Brnz done > LD R3, below > ADD R3, R3, R0 > Brzp done > ADD R2,R2,#-1 > iloop Brz actual > ADD R2,R2,#-1 > OUT > Br iloop > > done OUT > LEA R0, badInput > PUTS > actual LD R0, newLine > OUT > LD R0, zero > RTI > zero .BLKW #1 > KBDR .FILL xFE02 > above .FILL #-47 > below .FILL #-58 > badInput .STRINGZ " is not a decimal digit." > newLine .FILL x0A > ; *** End interrupt service routine code here *** > .END