Which of the following must be true for the RFE (Return From Exception) instruction on a general purpose processor?
I. It must be a trap instruction II. It must be a privileged instruction III. An exception cannot be allowed to occur during execution of an RFE instruction
Answer: (D)
I. Trap instruction: true. RFE changes the processor mode (kernel to user) and reloads the PC and status from the saved values in one indivisible step. This mode change plus jump is how a trap instruction works. II. Privileged: true. RFE can switch the processor out of kernel mode. If user programs could run it, they could give themselves kernel rights. So only the kernel may execute it. III. No exception during RFE: true. RFE is restoring the saved PC and status. If another exception came in the middle, this half-restored state would be lost or overwritten, and the return address could not be recovered. So exceptions must not occur during RFE. All three hold. Answer: (D)
Consider the following program segment. Here R1, R2 and R3 are the general purpose registers.
Assume that the content of memory location 3000 is 10 and the content of the register R3 is 2000. The content of each of the memory locations from 2000 to 2010 is 100. The program is loaded from the memory location 1000. All the numbers are in decimal.
Assume that the memory is byte addressable and the word size is 32 bits. If an interrupt occurs during the execution of the instruction "INC R3", what return address will be pushed on to the stack?
Answer: (C)
An interrupt is taken only after the current instruction finishes. At that time the PC points to the next instruction, and this value is pushed on the stack. So the return address is the address of the instruction after INCR3.
One word is 32 bits =4 bytes. From the table, the instructions before INCR3 are MOVR1,(3000) (2 words), MOVR2,(R3) (1), ADD (1) and MOV(R3),R2 (1), which is 5 words =20 bytes. INCR3 is at 1000+20=1020. It is 1 word long, so the next instruction, DECR1, is at 1020+4=1024. This is the address pushed on the stack.
Consider the following program segment. Here R1, R2 and R3 are the general purpose registers.
Assume that the content of memory location 3000 is 10 and the content of the register R3 is 2000. The content of each of the memory locations from 2000 to 2010 is 100. The program is loaded from the memory location 1000. All the numbers are in decimal.
Assume that the memory is word addressable. After the execution of this program, the content of memory location 2010 is:
Answer: (A)
The loop goes round 10 times.
First pass: R1=10,Memory[2000]=110,
Next pass: R1=9,Memory[2001]=109,
Next pass: R1=8,Memory[2002]=108,
Next pass: R1=7,Memory[2003]=107,
Next pass: R1=6,Memory[2004]=106,
Next pass: R1=5,Memory[2005]=105,
Next pass: R1=4,Memory[2006]=104,
Next pass: R1=3,Memory[2007]=103,
Next pass: R1=2,Memory[2008]=102,
Last pass: R1=1,Memory[2009]=101,
Once R1=0 is reached, the loop stops. So Memory[2010]=100
Consider the following program segment. Here R1, R2 and R3 are the general purpose registers.
Assume that the content of memory location 3000 is 10 and the content of the register R3 is 2000. The content of each of the memory locations from 2000 to 2010 is 100. The program is loaded from the memory location 1000. All the numbers are in decimal.
Assume that the memory is word addressable. The number of memory references for accessing the data in executing the program completely is:
Answer: (D)
Only data references count, not instruction fetches.
MOVR1,(3000) runs once and reads M[3000]=10 into R1: 1 data reference.
The loop starts at MOVR2,(R3). R1 is 10 and DECR1 lowers it by 1 each pass, and BNZLOOP jumps back while R1 is not zero. So the loop runs 10 times.
In each pass, MOVR2,(R3) reads one word from memory and MOV(R3),R2 writes one word to memory. The other instructions work only on registers. So each pass makes 2 data references, which gives 2×10=20.