DOC PREVIEW
NMT EE 308 - EE 308 – Homework 4

This preview shows page 1 out of 4 pages.

Save
View full document
View full document
Premium Document
Do you want full access? Go Premium and unlock all 4 pages.
Access to all documents
Download any document
Ad free experience
Premium Document
Do you want full access? Go Premium and unlock all 4 pages.
Access to all documents
Download any document
Ad free experience

Unformatted text preview:

EE 308 Spring 2012EE 308 – Homework 4Due Feb. 15, 20121. Find the values of the N, Z, C, and V bits of the CCR register, and the value of ACCA, afterexecution of each of the following instructions, given that (A) = $B7 and the condition flagsare N=1, C=1, Z=0, and V=1 before the instruction. (Assume these are the values beforeeach instruction starts e.g., do not use the flag state resulting from the instruction in part (a)as the initial state for part (b).)(a) ADDA #$7A(b) ADCA #$3A(c) LSRA(d) ASRA(e) ROLA(f) CMPA #$20(g) SUBA #$CC2. Suppose you started with the following register contents:PC=201A Y=1234 X=AA55 A=23 B=AC SP=1E56What address will be in the stack pointer, what values will be in the registers (A, B, X, Y,SP and PC), and exactly what is in the stack after the following instructions sequence isexecuted:PSHAPSHYPSHBPULXJSR $25723. Below are some data in the MC9S12 memory:0 1 2 3 4 5 6 7 8 9 A B C D E F1000 D6 05 35 CF E0 00 FE 08 20 A6 00 47 6A 05 08 531010 26 F7 34 C6 C8 CD 9C 40 03 26 FD 53 26 F7 3D 3F1020 07 C2 3A 68 F3 09 C2 67 9A 0F AA 55 08 40 CD CFIndicate the values in the registers after the MC9S12 executes the following instructions. Alsowrite down the number of cycles needed to execute each instruction. Show what will be in theregisters (in hex) after each of the instructions. If the instruction does not change a register,you may leave that entry blank. Note that the first instruction is located at address 0x2000.1EE 308 Spring 2012DInstruction A B X Y SP N Z V C Addressing EffectiveMode Address0A BB 1018 1028 0A00 1 0 1 0lds #$1010cpd $101Dpulxrolbstab $1013adda 2,-y4. Suppose that we have the following instruction sequence to be executed by the MC9S12,what will be the contents of the topmost four bytes of the s tack after the execution of theseinstructions?lds #$2000ldaa #$12ldab #$23std 2,-SPldx #$5678stx 2,-SP5. Write a subroutine to display a counting pattern on PORTB, and return the next number (thenumber passed to the subroutine plus 1). The number to display is passed in accumulatorA. Store this number into PORTB and return the next pattern in the sequence in accumulatorA. The subroutine should return with all registers expect A the same as when the subroutinewas called, so use the stack to save and restore any registers you need to use to implementthe subroutine.6. Write a subroutine to display the pattern shown be low on PORTB. There is an easy way to dothis. Start with two variables, one with a value of 0x80 and the other with a value of 0x01.OR the two variables together to get 0x81, the first pattern in the sequence. Then rotate thefirst variable to the right by one (to get 0x40), and rotate the second variable to the left byone (to get 0x02). ORing these two together to get 0x42, the se cond pattern in the sequence.Continue rotating the first variable to the right and the second to the left, and ORing thetwo togther.2EE 308 Spring 20127. Write a subroutine to generate the next pattern in the sequence for an eight-bit Johnsoncounter. The procedure to do this is as follows: Shift the present pattern to the right by onebit. The most significant bit of the next pattern is the inverse of the least significant bit ofthe present pattern. The number to convert is in accumulator A, and the next pattern inthe sequence is returned in accumulator A. The subroutine should return with all registersexpect A the same as when the subroutine was called, so use the stack to save and restoreany registers you need to use to implement the subroutine.8. Write a subroutine to take the next entry out of a table, write it to PORTB, and update theindex into the table. Here is an example of what the table might look like:table_len: equ (table_end-table)org datatable: dc.b $00, $01, $02, $04, $08, $10, $20, $40, $80table_end:The index of the number to be displayed is passed in accumulator A. Your code should writethe table entry corresponding to that index to PORTB. Return the index to the next tableelement in accumulator A. (For example, if accumulator A were 5, you would write the fifthelement of the table, $10, to PORTB, and return a 6.) Make sure that the index stays between0 and table_len - 1. The subroutine should return with all registers expect A the same aswhen the subroutine was called, so use the stack to save and restore any registers you needto use to implement the subroutine.The pattern to display is shown below:9. Write the program for Part 3 of Lab 2. The program will display four different patterns onthe LED display connected to Port B. You will use the state of bits 1 and 0 of the onboardDIP switch to select which of the four patterns to display. Write a program to set up PortB as an eight bit output port (be sure to disable the seven-segment displays, and to enablethe individual LEDs), and to implement (i) a binary up counter, (ii) a shifting bit, (iii) aJohnson counter, and (iv) a Ford Thunderbird style turn signal based on the state of the3EE 308 Spring 2012DIP switches. (These are the four subroutines from Problems 6 to 9.) Insert a 100 ms delaybetween updates of the display. Write the delay as a subroutine. Be sure to initialize thestack pointer in you program.Use variables to hold information on the four patterns. (You will need one variable for thebinary counter and Johnson counter patterns, two variables to genertate Pattern 2, and onevariable to hold the sequence number for the TBird Taillight pattern.) Initialize these fourvariables to the first pattern in the sequence.You should have a loop which checks the DIP switches connected to Port H. If bit 7 of theDIP switches is high, end the loop and exit back to DBug-12 with a SWI instruction. If bit 7of the DIP switches is low, check bits 0 and 1 to determine what pattern to display:PH1 PH0 Pattern0 0 Binary Up Counter0 1 Pattern 21 0 Johnson Counter1 1 TBird Turn SignalFor example, if bits 1 and 0 of Port H are 10, load accumulator A with the Johnson Countervariable, call the Johnson Counter subroutine, and save the returned accumulator A intothe Johnson Counter variable. Call the Delay subroutine, then loop back to check the DIPswitches


View Full Document

NMT EE 308 - EE 308 – Homework 4

Documents in this Course
Load more
Download EE 308 – Homework 4
Our administrator received your request to download this document. We will send you the file to your email shortly.
Loading Unlocking...
Login

Join to view EE 308 – Homework 4 and access 3M+ class-specific study document.

or
We will never post anything without your permission.
Don't have an account?
Sign Up

Join to view EE 308 – Homework 4 2 2 and access 3M+ class-specific study document.

or

By creating an account you agree to our Privacy Policy and Terms Of Use

Already a member?