ECE 332 Due: 09/27/2010 Homework 5 Fall 2010 1. Use the following assembly code and memory snapshots to answer the questions on the following page. # file: problem7.s # file: magic.s .include “system.inc” .text .text magic: .global magic _start: .global _start movia sp,STACK C: movi r17,801 srli r17,r17,4 andi r4,r17,0xf call magic mov r4,r2 call prints br . movia r8,LIST andi slli add ldw r9,r4,0xf r9,r9,2 r9,r8,r9 r2,0(r9) ret .data A: B: LIST: m0: m1: m2: m3: .end You can assume that the symbol _start is associated with memory address 0x20000. .word 0xaaaaaaaa .word m0, m1, m2, m3 .word 0xbbbbbbbb .string .string .string .string "dragon" "rat" "rabbit" "tiger" .word 0xcccccccc .end Note: The data section of magic.s is loaded at memory address 0x200e0. Figure 7.1. Partial memory snapshot of data section (word format) Figure 7.2. Partial memory snapshot of data section (byte format) Page 1 of 4 ECE 332 Due: 09/27/2010 Homework 5 Fall 2010 1. Based on the code and memory snapshots on the previous page: (answers in hex) a. What is the value of the symbol LIST? ______________ b. What is the value of the symbol m0? ______________ c. What is the value of the symbol m1? ______________ d. What memory address is referenced by the symbol LIST? ______________ e. What memory address is referenced by the symbol m0? ______________ f. ______________ What memory address is referenced by symbol m1? g. When the program counter (PC) is positioned to the location referenced by symbol A, what is the value of the ra register? ______________ h. When the program counter (PC) is positioned to the location referenced by symbol B, what is the value of the ra register? ______________ i. When the program counter (PC) is positioned to the location referenced by symbol C, what is the value of the ra register? ______________ j. (7 points) What is the sequence of bytes (hex) sent to the JTAG UART terminal? ______________ Page 2 of 4 ECE 332 Due: 09/27/2010 Homework 5 Fall 2010 Below is a screen capture from debugging a small C program. In the left pane is the C source, and on the right is the generated assembly language code. Inspect the generated assembly instructions, and compare them to assembly code that you have written in the past. In particular, note the translation of the c = a + b statement: Page 3 of 4 ECE 332 Due: 09/27/2010 Homework 5 Fall 2010 For this homework, you are asked to code specific C language statements to do some of the same things that were done previously using assembly language. For each problem write the C language code to produce the requested functionality, and then run the code and capture the generated assembly code as shown above. For example, consider the following. (While you are doing this assignment, keep in mind that this is not optimized code.) Provided with this assignment are files that you can use as the basis for instruction set simulation using the Nios II IDE environment. Copy the files N2SIM.ptf and N2SIM.sof to the workspace directory. Example: Produce code that increments a variable. Solution: C code Generated assembly code int i = 4; i++; int i = 4; 0x00020220 <main+12>: movi r2,4 0x00020224 <main+16>: stw r2,12(fp) i++; 0x00020228 <main+20>: ldw r2,12(fp) 0x0002022c <main+24>: addi r2,r2,1 0x00020230 <main+28>: stw r2,12(fp) For each of the problems listed below, use the value w0 as input data to manipulate. Provide screen capture the assembly code generated with your submittal. int main() { word w0 = 0x12345677; word w1, w2, w3, w4, w5, w6, w7, w8; w1 w2 w3 w4 w5 w6 w7 w8 = = = = = = = = ???; ???; ???; ???; ???; ???; ???; ???; // // // // // // // // one’ complement shift left 12 bits shift right 16 bits set bit 19 clear bit 18 toggle bit 12 get bits 19-16 of w0 Rotate w0 right 8 bits return 0; } 1. Set w1 to the one’s complement of w0. 2. Shift w0 left by 12 bits and assign to w2. 3. Shift w0 right by 16 bits and assign to w3. 4. Set bit 19 of w0 to a one and assign to w4. 5. Clear bit 18 of w0 and assign to w5. 6. Toggle bit 12 of w0 and assign to w6. 7. Get bits 19-16 of w0 (move to positions 3-0) and assign to w7 8. Rotate w0 right 8 bits and assign to w8. Page 4 of 4