Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Problem 5. In the following assume a 16 MHz instruction clock. (a) For the follo

ID: 2248130 • Letter: P

Question

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?

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?

Explanation / Answer

Answer:-a) The final value in W2 is -1. As MOV #100, W2 loads W2 with 100. REPEAT W2 means repeat next innstruction (W2 + 1 ) times, so DEC W2, W2 would execute 101 times making one decrement in W2 each time. Hence when 101th decrement is done then value in W2 will be -1.

b) We have the instruction frequency is 16 MHz i.e one machine cycle(MC) is 0.0625 micro second.

MOV #100, W2 takes 1 MC, REPEAT W2, W2 takes 1 MC and DEC W2, W2 takes ( 1 x 101 ) MC, so a total of 103 MC i.e time taken is 103 x 0.0625 microsecond = 6.4375 microsecond.

c) W14 has address 0x200 and it's a 16-bit memory location having 16-bit value 0x000a given. At address 0x202, 16 -bit value is 0x1014. The given program runs in a loop till value at address in W14 i.e 0x000a becomes zero, note that every loop execution decreases 0x000a by 2. So finally when loop terminates after five iterations value 0x000a has changed to 0x0000.

Then MOV [W14], W1 copies value present at address in W14 (i.e at address 0x200) to W1, hence W1 has value 0x0000 i.e zero. W0 has value 0x0000 on last loop iteration.

MOV W1, [W14 + 2], in W1 value is 0x0000 now and W14 has address 0x200 adding 2 to this gives 0x202 and at this address i.e at 0x202 value from W1, 0x0000 is copied. Hence at address 0x202 value has been changed from 0x1014 to 0x0000.

d) All instructions are taking 1MC to execute but instruction inside loop is executiong 5 times since loop iterates 5 times only. So loop has four istruction each taking 1MC and executing 5 times hence total MC taken by loop is 5x4x1 = 20. After loop we have 2 MOV instruction taking 2 MC so a total of 22 MC i.e total time = 22 x 0.0625 microsecond = 1.375 microsecond.

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote