Machine Instruction · Computer Organization and Architecture
36 questions · asked in 19 of 27 years (2000–2026)
MCQ 27 · MSQ 1 · NAT 81-mark 22 · 2-mark 14
2000Questions per year2026
Questions 26–30 of 36
Consider these two functions and two statements S1 and S2 about them.
S1 : The transformation from work 1 to work 2 is valid, i.e., for any program state and input arguments, work 2 will compute the same output and have the same effect on program state as work 1
S2 : All the transformations applied to work 1 to get work 2 will always improve the performance (i.e. reduce CPU time) of work 2 compared to work 1
int work1(int *a, int i, int j) int work2(int *a, int i, int j)
{ {
int x = a[i+2]; int t1 = i+2;
a[j] = x+1; int t2 = a[t1];
return a[i+2] - 3; a[j] = t2+1;
} return t2 - 3;
}S1 : The transformation from work 1 to work 2 is valid, i.e., for any program state and input arguments, work 2 will compute the same output and have the same effect on program state as work 1
S2 : All the transformations applied to work 1 to get work 2 will always improve the performance (i.e. reduce CPU time) of work 2 compared to work 1
Answer: (A)
S1. Work 1 reads again after the store . Work 2 reuses the old value in . These differ when , because then the store changes .
Example: , , .
- Work 1: ; ; it returns .
- Work 2: ; ; ; it returns .
The return values differ, so the transformation is not valid and S1 is false.
S2. The changes only save a repeated addition and a repeated array read. A compiler may already do this, so the saving can be zero. The new temporaries and also need registers, and when registers run short they can cost extra memory accesses. So these transformations cannot be said to always reduce CPU time, and S2 is false.
Answer: (A)
Example: , , .
- Work 1: ; ; it returns .
- Work 2: ; ; ; it returns .
The return values differ, so the transformation is not valid and S1 is false.
S2. The changes only save a repeated addition and a repeated array read. A compiler may already do this, so the saving can be zero. The new temporaries and also need registers, and when registers run short they can cost extra memory accesses. So these transformations cannot be said to always reduce CPU time, and S2 is false.
Answer: (A)
Consider a new instruction named branch-on-bit-set (mnemonic bbs). The instruction "bbs reg, pos, label" jumps to label if bit in position pos of register operand reg is one. A register is 32 bits wide and the bits are numbered 0 to 31, bit in position 0 being the least significant. Consider the following emulation of this instruction on a processor that does not have bbs implemented.
tempreg & mask
Branch to label if temp is non-zero
The variable temp is a temporary register. For correct emulation the variable mask must be generated by
tempreg & mask
Branch to label if temp is non-zero
The variable temp is a temporary register. For correct emulation the variable mask must be generated by
Answer: (A)
Suppose we want to test one bit position, say (third from the right). Take the number as (the last bits are ). The bit at position from the right is . So we must AND the number with . Any other mask gives a wrong value, because it may count other bits or drop the bit at position "". The mask is made by . Here we shift to the left "" times. This gives a mask with set only at the "" bit position.
Answer: (A)
A CPU has 24-bit instructions. A program starts at address 300 (in decimal). Which one of the following is a legal program counter (all values in decimal)?
Answer: (C)
A CPU with 24-bit instructions fetches bytes per instruction (memory is byte addressable). The PC starts at 300 and goes up by 3 for each instruction, so it holds . Since 300 is itself a multiple of 3, every legal PC value is a multiple of 3, and its difference from 300 is a multiple of 3.
(A) , not a multiple of 3.
(B) , not a multiple of 3.
(C) , a multiple of 3.
(D) , not a multiple of 3.
Answer: (C)
(A) , not a multiple of 3.
(B) , not a multiple of 3.
(C) , a multiple of 3.
(D) , not a multiple of 3.
Answer: (C)
If we use internal data forwarding to speed up the performance of a CPU (R1, R2 and R3 are registers and M[100] is a memory reference), then the sequence of operations
R1 M[100]
M[100] R2
M[100] R3
can be replaced by
R1 M[100]
M[100] R2
M[100] R3
can be replaced by
Answer: (D)
Internal data forwarding: when a value is written to a memory location and then read back, the reader takes it directly from the register that was written, and does not wait for memory.
Here is stored in , and then is read into and . Both reads would get the value of , so and can be done directly, and still has to be done. That is option (D).
Why the others are wrong:
(A) never gets the value of , and gets the old .
(B) It reads before it is written, and is never written with .
(C) copies the old value of , and is not loaded with the value of .
Answer: (D)
Here is stored in , and then is read into and . Both reads would get the value of , so and can be done directly, and still has to be done. That is option (D).
Why the others are wrong:
(A) never gets the value of , and gets the old .
(B) It reads before it is written, and is never written with .
(C) copies the old value of , and is not loaded with the value of .
Answer: (D)
Consider the following program segment for a hypothetical CPU having three user registers R1, R2 and R3.
Consider that the memory is byte addressable with size 32 bits, and the program has been loaded starting from memory location 1000 (decimal). If an interrupt occurs while the CPU has been halted after executing the HALT instruction, the return address (in decimal) saved in the stack will be
Consider that the memory is byte addressable with size 32 bits, and the program has been loaded starting from memory location 1000 (decimal). If an interrupt occurs while the CPU has been halted after executing the HALT instruction, the return address (in decimal) saved in the stack will be
Answer: (D)
One word is 32 bits bytes. From the table, the five instructions are 2, 1, 1, 2 and 1 words long, which is 7 words bytes. So they start at 1000, 1008, 1012, 1016 and 1024 (the 2-word instructions take two words), and the program ends just before .
The interrupt comes after HALT has already executed. The PC then points to the instruction after HALT, and this is the return address saved on the stack: 1028.
1024 is the address of HALT itself and 1020 is the second word of , so they are not the next instruction.
Answer: (D)
The interrupt comes after HALT has already executed. The PC then points to the instruction after HALT, and this is the return address saved on the stack: 1028.
1024 is the address of HALT itself and 1020 is the second word of , so they are not the next instruction.
Answer: (D)
Keep practising