# Problem 4 using the programmers reference manual for

• Homework Help
• 2
• 50% (2) 1 out of 2 people found this document helpful

This preview shows page 1 - 2 out of 2 pages.

Problem 4 . Using the Programmer’s Reference Manual for the PIC24, hand-assemble each of the following individual instructions. (a) mov w3, [w14] (b) add #-121, w0 (c) bra LE, 0x2d8 Problem 5. In the following assume a 16 MHz instruction clock. (a) For the following code fragement, what is the final value of w2 ? mov #100, w2 repeat w2 dec w2, w2 (b) How long does the code fragment in (a) take to execute? (c) Assume w14 contains 0x200 , and the four sequential addresses of data memory bytes, starting at address 0x200 , contain 0x0a , 0x00 , 0x14 , contain 0x10. Immediately after this code executes what will be the values of w0 , w1 , w14 , and these four sequential memory addresses?
EE2361 Fall 2017 loop: dec2 [w14], [w14] mov [w14], w0 cp0 w0 bra gt, loop mov [w14], w1 mov w1, [w14+2] (d) With the initial conditions given in (c) how long does the code in (c) take to execute? Problem 6 . The following fragment of C code i=0; while(i<100) { i++;} compiles to the following assembly code 0x314: CLR W0 0x316: MOV W0, [W14+6] 0x318: BRA 0x320 0x31A: MOV [W14+6], W0 0x31C: INC W0, W0 0x31E: MOV W0, [W14+6] 0x320: MOV [W14+6], W1 0x322: MOV #0x63, W0 0x324: SUB W1, W0, [W15] 0x326: BRA LE, 0x31A Each line begins with the program memory address on the left followed by the assembly code instruction at that address. (a) How many bytes of physical program memory does this code occupy? (b) How long does it take this code to execute? (c) The assembly code shown above uses the stack. Here W14 is the frame pointer and W15 is the stack pointer. The assembly code can be simplified if we don’t use the stack. Rewrite the assembly code shown to eliminate W14 and W15 .