Midterma_S

Midterma_S - 0306-250-01 Assembly Language Programming 6...

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 6 problems, 6 pages Fall 2009 Midterm Exam Solution October 16, 2009 Instructions: This exam 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 exam in pencil, and do not separate the pages of the exam. 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 exam. By submitting this exam, you attest that you neither have given nor have received any assistance in answering the exam questions, and you further acknowledge that giving or receiving such assistance will result in a failing grade for this exam. Best wishes! Your Signature: X Your Name (please print) Solution 1 2 3 4 5 6 Total 25 15 20 20 10 10 100 1 0306-250-01 6 problems, 6 pages Assembly Language Programming Midterm Exam Solution Fall 2009 October 16, 2009 Problem 1 (5 parts, 25 points) For each of the following parts, provide a complete answer in one to three sentences. HCS12 Part A (5 points) Registers What is SP, and how is it used? SP is the system stack pointer, which always points to the top of the system stack. It is used implicitly by bsr/jsr and rts to save and restore the return address for a subroutine call, as well as by psh and pul to save and restore register contents. It may be used explicitly for storing and accessing data on the stack using mov, ld, and st instructions. Part B (5 points) What is Z, and how is it set and used? Condition Codes Z is the bit in the condition code register that indicates whether the previous result was zero: 1 if zero and 0 otherwise. Part C (5 points) Addressing Modes Explain the difference between register direct addressing and register indirect addressing. With register direct addressing, the desired data are found directly in the specified register. With register indirect addressing, the desired data are found in memory at the address stored in the specified register Part D (5 points) Operand Specification Give an example for each of these addressing modes: register direct and register indirect. Register direct: tfr x,d Register indirect: inc ,x Part E (5 points) What is polling (in the context of peripheral device I/O)? I/O In polled I/O, when the CPU wants to use a peripheral device, the CPU repeatedly checks the status of the device until the device is ready for the I/O operation. 2 0306-250-01 6 problems, 6 pages Assembly Language Programming Midterm Exam Solution Fall 2009 October 16, 2009 Problem 2 (3 parts, 15 points) Instructions Write one assembly language instruction to perform each of the following operations. Part A (5 points) After this instruction, execute the instruction labeled Next, no matter where it is located in memory. jmp Next Part B (5 points) Subtract one from B, and go to the instruction labeled Loop if B was not zero after subtraction. dbne b,Loop Part C (5 points) Go to the instruction labeled Case1, only if Z is set to 1. beq Case1 Problem 3 (20 points) Subroutine Write a properly commented subroutine StrLen to determine the length of a null-terminated string that starts in memory at the address in X. The null character (i.e., $00) should not be counted. The subroutine should return the length in B. On return, no other registers should be modified. StrLen: ;************************************************************** ; Returns in B the length of the null-terminated string ; in memory starting at the address in X. ; Input: X ; Output: B ; Modify: B, CCR ;************************************************************** pshx ; Save registers psha ; Note: X has StrPtr clrb ; length = 0 StrLenLoop: ldaa 1,x+ ; while (*(StrPtr++) <> 0) { beq StrLenEnd incb ; length++ bra StrLenLoop ; } StrLenEnd: pula ; Restore registers pulx rts ; return (length) 3 0306-250-01 Assembly Language Programming 6 problems, 6 pages Midterm Exam Solution Fall 2009 October 16, 2009 Problem 4 (20 points: 5 points each blank) Comparisons and Conditional Branching In this problem you will complete the assembly code fragment below to find the maximum of the elements of an array of 32 signed words, Array. The label ArrayPast refers to data memory at the first location beyond the end of Array. The word variable Maximum holds the maximum found so far. The registers used are described in the table below. Complete the code fragment by writing the missing instructions at these labels: Init—the instruction to initialize X; Compare—compare instruction; and Branch1 and Branch2—conditional branches. X Address of current array element D Value of current array element ldx #Array movw 2,x+,Maximum Loop: ldd 2,x+ Compare: cpd Maximum Branch1: ble Skip std Maximum Skip: cpx #ArrayPast Branch2: blo Loop MyData: Maximum: Array: ArrayPast: SECTION DS.W DS.W DS.B 1 32 1 Init: 4 0306-250-01 Assembly Language Programming 6 problems, 6 pages Midterm Exam Solution Fall 2009 October 16, 2009 Problem 5 (10 points) Computing Mechanisms Write a properly commented assembly language code fragment to implement the following highlevel language construct, where X refers to the register X, and where Var1, Var2, Var3, Var4, and Var5 refer to word variables in data memory that have been declared (DS.W ) with those respective labels. if (X == 3) { Var3 = Var2 } else if (X > Var4 = Var4 } else { Var5 = Var5 } If: Then: ElseIf: Else: EndIf: cpx bgt blt ldd addd std bra ldd subd std bra ldd addd std #3 ElseIf Else Var2 Var1 Var3 EndIf Var4 #2 Var4 EndIf Var5 #1 Var5 ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; + Var1; 3) { – 2; + 1; Set CCR from (X - 3) (X > 3) ? Goto ElseIf (X < 3) ; Goto Else (X == 3): D ß Var2 D ß Var2 + Var1 Var3 ß Var2 + Var1 end if-then (X > 3): D ß Var4 D ß Var4 - 2 Var4 ß Var4 - 2 end else if (X < 3): D ß Var5 D ß Var5 + 1 Var5 ß Var5 + 1 end else 5 0306-250-01 Assembly Language Programming 6 problems, 6 pages Fall 2009 Midterm Exam Solution October 16, 2009 Problem 6 (10 points) Circular FIFO Queue Operation To manage a circular FIFO queue, suppose we use the Enqueue and Dequeue subroutines developed in class. Starting with an initially empty queue, consider the three sequences (A, B, and C) of queue operations indicated below. Complete the memory table that follows to reflect the contents after each sequence. In the table, if an element is removed from the queue, write “—” in its memory location; otherwise, if a memory location remains unchanged, write “N/C.” At the bottom of the page, give the final values of the queue management structure fields at IN_PTR and OUT_PTR after the completion of all three sequences: A, B, and C. Here are the initial values of various queue management record fields. Initial Field Value BUF_STRT $1100 BUF_PAST $1105 Initial Field Value IN_PTR $1100 OUT_PTR $1100 Sequence A: Enqueue is called five (5) times with these parameters (in order): $A0, $0A, $2A, $FE, and $AB. Sequence B: Enqueue is called with parameter $CD; then Dequeue is called three (3) times. Sequence C: Enqueue is called with parameter $88; then Dequeue is called two (2) times. Contents After After After Address Sequence A Sequence B Sequence C Memory $1100 $A0 — $88 $1101 $0A — N/C $1102 $2A — N/C $1103 $FE N/C — $1104 $AB N/C — $1105 N/C N/C N/C “—” indicates sequence removed contents from queue. “N/C” indicates sequence did not change memory contents. Final value in field at IN_PTR = $1101 Final value in field at OUT_PTR = $1100 6 ...
View Full Document

Ask a homework question - tutors are online