April 1999
CS202: COMPUTER ARCHITECTURE AND DATA COMMUNICATION

QUESTION 2

Total Marks: 20 Marks

Click here to access other questions

GRADE A
Sample student's solutions are indicated in green.
Return to Question 2

 

(a) In stack operations, what is a binary operation? [2]
Addition of top two elements of stack.

 

(b) Describe the steps involved in using a specific linkage register for passing parameters (at low-level) into a subroutine. Assume [R2] is the specific linkage register. [6]
  1. The parameters are stored just after the Jump to Subroutine Instruction.
  2. PC = 2501
  3. Contents of the program counter is transferred to the specific linkage register.
  4. The subroutine is executed.
  5. The specific linkage register is incremented n number of times, where n is the number of parameters.
  6. At the end of the subroutine the contents of R2 are transferred back to PC and execution of the main program continues at 2501 + n.

 

(c) The use of nested subroutines means that a subroutine can call another subroutine to perform some task.

Given the diagram shown on the following page, for each of the following give the location of the Stack Pointers (SP) and the Program Counter (PC), and, for each subroutine call, give the starting address loaded into the PC when the subroutine call is executed. Assume that the only data stored on the stack is the PC.

 

[12]
(i) before calling SUB1,
(ii) when SUB1 is called,
(iii) before calling SUB2,
(iv) when SUB2 is called,
(v) before calling SUB3,
(vi) when SUB3 is called,
(vii) upon returning from SUB3,
(viii) upon returning from SUB2, and
(ix) upon returning from SUB1.

pic1.gif (7667 bytes)

(i) Before calling SUB1
PC = 3000
SP = C010

(ii) When SUB1 is called
PC = PC + 1 = 3000 + 1
SP = SP -1 = C0101 - 1 = C00F (SP is decremented)

(iii) Before calling SUB2
PC = 2300
SP = C00F

(iv) When SUB2 is loaded
PC = 2301 (PC is incremented)
SP = C00E. (SP is decremented)
contents of PC are pushed onto stack.
then contents of SP at C00E = 2301.
When SUB2 is called
address of SUB2 is put into PC.
PC = 5000

(v) Before calling SUB3
PC = 5500
SP = C00E

(vi) When SUB3 is called
PC = 5501 (PC is incremented)
SP = C00D (SP is decremented)
contents of PC are pushed onto stack.
then contents of SP at C00D = 5501.
address of SUB3 is put into PC = 4000.

(vii) Upon returning from SUB3
SP = C00D = 5501
contents of SP are popped into PC.
PC = 5501
SP = C00E = 2301 (SP is incremented)

(viii) Upon returning from SUB2
contents of SP at C00E = 2301 are popped into PC.
PC = 2301
SP = C00F = 3001 (SP is incremented)

(ix) Upon returning from SUB1
contents of SP at C00F = 3001 are popped into PC.
PC = 3001
SP = C010 (SP is incremented)