quiz2a_s - 0306-250-01 Assembly Language Programming 8...

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: 0306-250-01 Assembly Language Programming 8 problems, 4 pages Fall 2009 Quiz Two Solution November 6, 2009 Instructions: This quiz is closed book and closed note. Calculators and computers are not permitted. If you have a question, raise your hand, and I will come to you. Please work the quiz in pencil, and do not separate the pages of the quiz. For maximum credit, show your work. If you need extra space for your work, raise your hand, and I will provide additional paper, which you will submit with your quiz. By submitting this quiz, you attest that you neither have given nor have received any assistance in answering the quiz questions, and you further acknowledge that giving or receiving such assistance will result in a failing grade for this quiz. Best wishes! Your Signature: X Your Name (please print) Quiz Two Solution 1 2 3 4 5 6 7 8 Total 10 20 10 10 10 10 15 15 100 1 0306-250-01 8 problems, 4 pages Assembly Language Programming Quiz Two Solution Problem 1 (10 points) Fall 2009 November 6, 2009 Debugger Suppose you ask your lab instructor for help debugging your program, and he wants to look at the contents of the stack. Explain how you would show the contents of the stack using the CodeWarrior simulator/debugger. Go to the Memory window, right-click, select Address, enter “1100,” and scroll up to view the stack contents, starting at the bottom of the stack. Problem 2 (2 parts, 20 points) SCI Interrupts Part A (10 points) Transmit How does the SCI transmit interrupt work? For example, in Lab Exercise Eight (serial driver), how do you know that the SCI interrupt is for transmit, and what causes a transmit interrupt? When SCI transmit interrupts are enabled, the SCI automatically generates a transmit interrupt to the CPU whenever the transmit data register is empty. An SCI interrupt is for transmit if the TDRE bit of the ACIA status register is set (i.e., TDRE = 1). Part B (10 points) Clearing When an SCI interrupt occurs, how is it cleared in the SCI interrupt service routine (ISR) so that the next interrupt can be detected? List the necessary instructions for both receive and transmit. SCI receive: For an SCI receive (input) interrupt, read the SCI status register and then the SCI data register. brclr SCI0SR1,#mSCI0SR1_RDRF,NotReceive ldab SCI0DRL SCI transmit: For an SCI transmit (output) interrupt, read the SCI status register and then write to the SCI data register. brclr SCI0SR1,#mSCI0SR1_RDRF,NotReceive stab SCI0DRL Problem 3 (10 points) Timer (ECT) Interrupts In Lab Exercise Nine (timer driver stopwatch), when a timer interrupt occurs, how is it cleared in the timer ISR so that the next interrupt can be detected? List the necessary instruction(s). To clear the channel 7 output compare interrupt, set the C7F bit in the TFLG1 register. movb #%10000000,TFLG1 2 0306-250-01 Assembly Language Programming 8 problems, 4 pages Quiz Two Solution Fall 2009 November 6, 2009 Problem 4 (10 points) Polled I/O Write HCS12 assembly language code to input using polling from (a) the SCI and (b) the ATD. (a) SCI polling: ;mRDRF: EQU %00100000 RxPoll: brclr SCI0SR1,#mRDRF,RxPoll ldab SCI0DRL (b) ATD polling: ;ATDCh3: EQU 3 ;mSCF: EQU %10000000 movb #ATDCh3,ATD0CTL5 APoll: brclr ATD0STAT0,#mSCF,APoll ldd ATD0DR0 Problem 5 (10 points) Timer Operation In Lab Exercise Nine (timer driver stopwatch), the Count variable increases by 1 whenever ECT channel 7 output compare generates an interrupt. Give two conceptually different ways to hold Count’s value unchanged. Concept one: Use a flag (e.g., RunStopWatch from lab) to determine whether Count gets incremented at a output compare interrupt. Concept two: Hold the timer in its present state by clearing bit 7 of ECT TSCR1 (TEN=0). Problem 6 (10 points) Subroutine Debugging In Lab Exercise Four (polled serial I/O), somebody wrote the GetChar subroutine below (to get a character from the keyboard); however the subroutine does not work correctly. Identify the most serious problem, and provide a correction to fix the subroutine. GetChar: Back: pshb ldab andb beq ldab pulb rts B should be the output parameter, but its value is left unchanged on return because of the psh and pul instructions. Omit pshb and pulb. SCI0SR1 #mSCI0SR1_RDRF Back SCI0DRL 3 0306-250-01 Assembly Language Programming 8 problems, 4 pages Quiz Two Solution Problem 7 (15 points) Fall 2009 November 6, 2009 SCI Debugging In Lab Exercise Eight (serial driver), somebody wrote the following code in the main program. The intent was to put all entered characters into the transmit queue (TxQ) until a carriage return character (CR) was entered and then send them to the screen. Will this code produce the desired results on the screen? If not, what happens instead, and how would you correct the problem (in terms of algorithmic logic rather than specific instructions)? MainLoop: * Disable transmit interrupt, * and wait until <Enter> is pressed * to write to screen. movb #%00101100,SCI0CR2 Loop: jsr GetChar ldx #TxQStruct jsr Enqueue cmpb #$0D bne Loop jmp MainLoop No characters will be printed to the screen because transmit interrupts are disabled. Transmit interrupts need to be enabled after CR is detected, and then the program needs to wait for the transmit queue to empty before looping to MainLoop. Thus, these lines need to be added after bne Loop. movb #%10101100,SCI0CR2 ldx #TxQStruct Loop2: tst NUM_ENQD,x bne Loop2 Problem 8 (15 points) Timing In Lab Exercise Nine (timer driver stopwatch), the timer channel 7 output compare interrupt occurs every 10 ms. How would you make Count increment only every 1.5 s? (Describe your idea and provide specific instructions to implement it.) (Note: the maximum channel 7 output compare register value is $FFFF = 65535.) The ECT can not be set to generate an interrupt every 1.5 s. The output compare value for an interrupt every 10 ms is 2500. 1.5 seconds have 150 ´ 10 ms, so an output compare value of 375000 would be required; however, the largest compare value is 65535. Instead, implement a secondary software timer with the same ECT configuration. Start the word value Count at 0. Create a byte variable, CS (centiseconds), which starts at 150 and decrements on each 10-ms interrupt. When CS = 0, increment Count. Start: movw movb Count #150, CS dec bne movb ldd incd std ECT_DONE: rti CS ECT_DONE #150,CS Count ECT_ISR: Count 4 ...
View Full Document

This note was uploaded on 05/06/2010 for the course EECC 0306-250 taught by Professor Roymelton during the Fall '10 term at RIT.

Ask a homework question - tutors are online