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

Consider a service routine that responds to a timer interrupt. Assume that the f

ID: 3885206 • Letter: C

Question

Consider a service routine that responds to a timer interrupt. Assume that the function of this service routine is simply to increment the current value of ``clock''-- an integer stored in absolute address CLOCK. Ignore any overflow that may arise from this operation.

Below is a pseudo code for this service routine. Pseudo code of the service routine

----------------------------------

Load CLOCK, R1 (* loads the integer stored in address CLOCK to register R1 *)

INCREMENT R1 by 1

STORE R1, CLOCK (* stores the value in R1 to the memory location CLOCK *)

RETURN (* Pops the return address from control stack and loads it to PC *)

Questions:

(a) Point out any problems with this code, in less than 30 words.

(b) Show a corrected pseudo code.

Explanation / Answer

Please see the below answer.

Answer:

a) As it is mentioned in the abovquestion that the function of the service routine is simply to increment the current value of CLOCK as an absolute address holding some data value, that will be stored in the register R1 .

But the above loadinstruction that LOAD CLOCK , R1 implies

That the register value is copied to CLOCK address , so the whole thing will be worked just in opposite direction and return an erroneous value.

b) The correct pseudo code will be as follows.

LOAD PC , 0 ; ( PC holds initially 0 which automatically incremented by 1 after return

LOAD R1 , CLOCK; ( integer value stored in CLOCK address is copied to R1)

INCREMENT R1 ; ( increments R1 by 1)

STORE R1, CLOCK; ( stores the value in R1 to the memory location)

RETURN PC; (pops the return address from control stack and loads into PC)