






Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
Main points of this past exam are: Single Instruction, Equivalent, Program, Supposed, Character Input, Wrong, Making a Single Change
Typology: Exams
1 / 12
This page cannot be seen from the preview
Don't miss anything!







Part A (4 points): What single instruction is equivalent to the following two LC-3 instructions? LEA R7, # JMP R Part B (6 points): The following LC-3 program is supposed to ask the user for a character input and output that character in quotes. However, it has a bug. BRIEFLY describe what is wrong and then fix the bug by making a single change. .ORIG x LEA R0, PROMPT PUTS GETC OUT STI R0, DATA LEA R0, OUTPUT PUTS HALT PROMPT .STRINGZ "Enter a character: " OUTPUT .FILL x0A ; The ASCII Line Feed character .FILL x22 ; The ASCII quote character (") DATA .FILL x22 ; Overwrite with key press .FILL x .FILL x .END
Part A (10 points): Many devices require that a processor attend to their needs within a certain amount of time. A typical keyboard, for example, does not have much storage of its own and cannot keep track of sequences of typed characters, only single keystrokes. If polling I/O is used, and the processor (for whatever reason) does not check for keyboard input during a period in which two or more keys are pressed, some of the keystrokes are lost. In this problem, you will address this issue by changing the GETC trap handler to make the monitor beep by sending an ASCII BEL character to the display whenever keystrokes are lost. To support your extension, assume that the KBSR contains an OVERFLOW bit (bit 0, with value 1) to indicate the loss of keystrokes to you. The OVERFLOW bit is set whenever the processor fails to read KBDR between two keystrokes, and is cleared after KBSR is read. Things you may find useful: the display status register (DSR) is mapped at address xFE04; the display data register (DDR) is mapped at address xFE06; the ASCII code for BEL (bell, or beep) is 7. Keep in mind that registers other than R0 are callee-saved ( i.e. , you must save them). .ORIG x GETC LDI R0,KBSR ; wait for a keystroke; note that BRzp GETC ; overflow can’t occur without one ; a. your new code goes here (write it below) GET_KEY LDI R0,KBDR ; read the last keystroke RET ; and return it KBSR .FILL xFE00 ; keyboard status register address KBDR .FILL xFE02 ; keyboard data register address ; b. also indicate any new data/storage that you need (which go here) .END a. b.
Part B (10 points): Use stacks to help you write a short LC-3 program to print out a list of strings in reverse. The strings are stored in memory exactly as in MP2: beginning at x5005, NUL terminated, and with an additional terminating NUL indicating the end of the list. There may be zero or more strings. You must print all strings in the reverse order that they were found; there is no error checking on the number of strings. Follow each string with a linefeed character (0x0A). You must make use of the three provided subroutines, whose semantics are described below. Assume they are already written for you and use the callee save convention. Also assume the stack is initially empty. FIND_NUL – Locates the first NUL in memory, beginning from the passed in address. Inputs: R0 – The address to begin looking for the next NUL character. Outputs: R0 – Unchanged. R1 – The address of the character past the first NUL found. R5 – Set to 1 if R0 pointed to a NUL character, 0 else. POP – Pops the top of the stack and returns it. Inputs: None Outputs: R0 – The data from the top of the stack. R5 – 1 if underflow occurred, 0 else. PUSH – Pushes data onto the top of the stack. Inputs: R0 – The data to be pushed. Outputs: None ( You may assume overflow will not occur .) .ORIG x
Part A (12 points): Which LC-3 instructions correspond to (give the instruction numbers shown in the comments): a. The initialization of the for loop? b. The test (middle part) of the for loop? c. The update (re-initialization) of the for loop? Part B (6 points): Using the LC-3 translation of Foo, write the body of the for loop here.
Part A (8 points): Fill in the blank below so that the program executes the code in the if statement as specified. if (_________________________________________________) { /* Execute this block of code if the
Part B (8 points): Now assume the program is written with your work in Part A being placed into a function called PlayRound. This function will play only a single round of the game. Give the declaration of PlayRound and show how it would be called. Explain your reasoning for this declaration. Note: Assume no variables are global.