CMPEN 472 Sample EXAM II Name: Student ID number (last 4 digit): Please write your name on every page. Write your solutions clearly. You may use backside of each page for scratch but the solutions must be shown on the designated place near (or below) each problem. For any program you are asked to write, write it as short as possible. In most cases, a shorter program runs quicker and saves memory space; hence, it is more efficient. Any subroutine you write, make it transparent to its caller. Please ask if any of the problems (and assumptions) is not clear. PENALTY applies to long subroutines, its length greater than the suggested length. 1. (15pt) Write a short subroutine to convert the two digit decimal number input from a keyboard to a binary number and place the result in the accumulator A. Assume that the keyboard inputs are received through MC9S12C128 s SCI port and they are stored in the memory locations labeled TEN and ONE. The key-board inputs are always two digit decimal number from 00 to 99. Design your subroutine as short as possible. Your subroutine must be transparent to its caller. D EAMPLE: A $5B B X Y TEN ONE $39 $31 91 = $5B = %01011011
2. (15pt) Write a short subroutine to convert a number from the accumulator A for terminal display. The subroutine generates two byte ASCII characters for terminal display of the accumulator A content in HEX. Store the results in the memory locations labeled MSB and LSB. Design your subroutine as short as possible. Your subroutine must be transparent to its caller. D EXAMPLE A B $5B X Y MSB LSB $35 $42 5 B 91 = $5B = %01011011
3. (15pt) Three unsigned binary numbers are received from the port A of the MC9S12C128 and they are stored on the stack. The three numbers are needed to be sorted in ascending order. Given the main program below, write a short subroutine which will SORT the three numbers stored on the stack. MAIN: LDAA PSHA LDAA PSHA PORTA PORTA LDAA PSHA JSR PULA STAA PULA STAA PULA STAA PORTA SORT MIN mid MAX
4. (15pt) Show the memory contents of the stack after the Real Time Interrupt (RTI) has been occurred to HCS12. The RTI occurred during the execution of instruction at line 26. The interrupt handling has been initiated and the first instruction SWI has been executed. Show the memory contents of the stack during the beginning of the execution of the first instruction from the interrupt service routine at ISRSWI. 01 0037 CRGFLG EQU $0037 02 0038 CRGINT EQU $0038 03 003b RTICTL EQU $003B 04 3ff0 ORG $3FF0 05 3ff0 39 25 DC.W ISRRTI 06 3ff6 ORG $3FF6 07 3ff6 39 28 DC.W ISRSWI 08 09 3900 ORG $3900 10 3900 StackST 11 3900 cf 39 00 LDS #StackST 12 3903 4c 3b 39 bset RTICTL,%00111001 13 3906 4c 38 80 bset CRGINT,%10000000 14 3909 4c 37 80 bset CRGFLG,%10000000 15 390c cc ff 00 LDD #$FF00 16 390f b7 02 TAP 17 3911 ce f0 f0 LDX #$F0F0 18 3914 cd ab cd LDY #$ABCD 19 3917 10 ef cli 20 3919 16 39 20 JSR SUB1 21 391c a7 nop 22 391d a7 mloop nop 23 391e 20 fd bra mloop 24 25 3920 a7 SUB1: NOP 26 3921 a7 LOOP1: NOP 27 3922 20 fd BRA LOOP1 28 3924 3d RTS 29 30 3925 3f ISRRTI: SWI 31 3926 a7 NOP 32 *** 33 *** 34 3927 0b RTIEND: RTI 35 36 3928 a7 ISRSWI: NOP 37 *** 38 *** 39 3929 0b SWIEND: RTI 40 END $38F0 $38F8 $3900
5. (15pt) We want to generate square wave on bit 4 of the port B on the MC9S12C128 chip. The continuous square wave has the period of 0.5sec: 5V output for 0.25sec and 0V output for 0.25sec assuming 24MHz bus clock, 4MHz external resonator (same setting as the homework on CSM-12C128 board. Write the main program and the interrupt service routine for this task using the Real Time Interrupt feature. Use the memory locations starting at $3100 for your program and at $3000 for the data, if needed. Design your main.asm source file as a stand-alone program (same as the homework programs) including any necessary initialization.
6. (15pt) Write a short subroutine to add two 24 bit numbers in memory locations labeled N1 and N2. Store the result in N1. Design your subroutine as short as possible. Your subroutine must be transparent to its caller. N1: msb lsb N2: msb lsb
7. (15pt) Write a short subroutine 'putchar' to correctly send a byte data through MC9S12C128's SCI port. Use accumulator A for the data passing: A = character to send through the SCI port.
8. (15pt) Write a short subroutine 'printmsg' to print a line of text message on a Hyper Terminal connected to MC9S12C128's SCI port. Assume the message text always ends with ASCII null character 0 and the register X points to the first character to print. Also assume that your 'putchar' subroutine above is correctly working.
9. (15pt) When executing the MC9S12C128 program shown below, show the HyperTerminal window display. ORG $3100 LDS #$3100 LDAA #$65 LDAB #$43 LDX #256 IDIV TBA JSR putchar XGDX TBA JSR putchar Loop: BRA Loop
10. (15pt) Write a program to accept a user input up to 20 characters ending with an enter key and display the user input in the middle of the HyperTerminal window (eg. 5,15 position) with blue color. Write the main program and the subroutine. Use the memory locations starting at $3100 for your program and at $3000 for the data, if needed. Design your main.asm source file as a stand-alone program (same as the homework programs) including any necessary initialization.