Machine-Instructions

Question 1

For computers based on three-address instruction formats, each address field can be used to specify which of the following:

    (S1) A memory operand
    (S2) A processor register
    (S3) An implied accumulator register
A
Either S1 or S2
B
Either S2 or S3
C
Only S2 and S3
D
All of S1, S2 and S3
Question 1 Explanation: 
Any implied register is never explicitly mentioned as an operand in an operation.
So as the question asks what can be specified using the address fields, implied accumulator register can't be represented in address field.
So, S3 is wrong.
Hence Option A is the correct answer.
Question 2
A processor has 16 integer registers (R0, R1, …, R15) and 64 floating point registers (F0, F1, …, F63). It uses a 2-byte instruction format. There are four categories of instructions:
Type-1, Type-2, Type-3 and Type-4. Type-1 category consists of four instructions, each with 3 integer register operands (3Rs).
Type-2 category consists of eight instructions, each with 2 floating point register operands (2Fs).
Type-3 category consists of fourteen instructions, each with one integer register operand and one floating point register operand (1R+1F).
Type-4 category consists of N instructions, each with a floating point register operand (1F).
The maximum value of N is ________.
A
32
B
33
C
34
D
35
Question 2 Explanation: 
Instruction size = 2−byte.
So, total number of instruction encodings = 216
There are 16 possible integer registers, so no. of bits required for an integer operand = 4
There are 64 possible floating point registers, so no. of bits required for a floating point operand = 6
Type-1 instructions:
There are 4 type-1 instructions and each takes 3 integer operands.
No. of encodings consumed by type-1 = 4 × 24 × 24 × 24 = 214.
Type-2 instructions:
There are 8 type-2 instructions and each takes 2 floating point operands.
No. of encodings consumed by Type-2 instructions = 8 × 26 x 26 = 215.
Type-3 instructions:
There are 14 type-3 instructions and each takes one integer operand and one floating point operand.
No. of encodings consumed by Type-3 instructions = 14 × 24 × 26 = 14336.
So, no. of encodings left for Type-4 = 216 − (214 + 215 + 14336) = 2048.
Since type-4 instructions take one floating point register, no. of different instructions of Type-4 = 2048 / 64 = 32.
Question 3

Consider a hypothetical processor with an instruction of type LW R1, 20 (R2), which during execution reads a 32-bit word from memory and stores it in a 32-bit register R1. The effective address of the memory location is obtained by the addition of constant 20 and the contents of register R2. Which of the following best reflects the addressing mode implemented by this instruction for the operand memory?

A
Immediate Addressing
B
Register Addressing
C
Register Indirect Scaled Addressing
D
Base Indexed Addressing
Question 3 Explanation: 
Here 20 will act as base and content of R2 will be index.
Question 4

A processor has 40 distinct instructions and 24 general purpose registers. A 32-bit instruction word has an opcode, two register operands and an immediate operand. The number of bits available for the immediate operand field is __________.

A
16 bits
B
17 bits
C
18 bits
D
19 bits
Question 4 Explanation: 
6 bits are needed for 40 distinct instructions (because, 25 < 40 < 26)
5 bits are needed for 24 general purpose registers (because, 24 < 24 < 25)
32-bit instruction word has an opcode (6 bit), two register operands (total 10 bits) and an immediate operand (x bits).
The number of bits available for the immediate operand field
⇒ x = 32 – (6 + 10) = 16 bits
Question 5

Consider a processor with 64 registers and an instruction set of size twelve. Each instruction has five distinct fields, namely, opcode, two source register identifiers, one destination register r identifier, and a twelve-bit immediate value. Each instruction must be stored in memory in a byte-aligned fashion. If a program has 100 instructions, the amount of memory (in bytes) consumed by the program text is _________.

A
500 bytes
B
501 bytes
C
502 bytes
D
503 bytes
Question 5 Explanation: 
One instruction is divided into five parts,
(i) The opcode- As we have instruction set of size 12, an instruction opcode can be identified by 4 bits, as 24 = 16 and we cannot go any less.
(ii) & (iii) Two source register identifiers- As there are total 64 registers, they can be identified by 6 bits. As they are two i.e. 6 bit + 6 bit.
iv) One destination register identifier- Again it will be 6 bits.
v) A twelve bit immediate value- 12 bit.
Adding them all we get,
4 + 6 + 6 + 6 + 12 = 34 bit = 34/8 byte = 4.25 bytes.
Due to byte alignment total bytes per instruction = 5 bytes.
As there are 100 instructions, total size = 5*100 = 500 Bytes.
Question 6

Consider a processor with byte-addressable memory. Assume that all registers, including Program Counter (PC) and Program Status Word (PSW), are of size 2 bytes. A stack in the main memory is implemented from memory location (0100)16 and it grows upward. The stack pointer (SP) points to the top element of the stack. The current value of SP is (016E)16. The CALL instruction is of two words, the first word is the op-code and the second word is the starting address of the subroutine (one word = 2 bytes). The CALL instruction is implemented as follows:

    • Store the current value of PC in the stack.
    • Store the value of PSW register in the stack.
    • Load the starting address of the subroutine in PC.

The content of PC just before the fetch of a CALL instruction is (5FA0)16. After execution of the CALL instruction, the value of the stack pointer is

A
(016A)16
B
(016C)16
C
(0170)16
D
(0172)16
Question 6 Explanation: 
Here the memory is byte-addressable.
The CALL instruction is implemented as follows:
-Store the current value of PC in the stack
pc is 2 bytes so when we store pc in stack SP is increased by 2 so current value of SP is (016E)16+2 -Store the value of PSW register in the stack
psw is 2 bytes, so when we store psw in stack SP is increased by 2
so current value of SP is (016E)16+2+2 = (0172)16
Question 7

A machine has a 32-bit architecture, with 1-word long instructions. It has 64 registers, each of which is 32 bits long. It needs to support 45 instructions, which have an immediate operand in addition to two register operands. Assuming that the immediate operand is an unsigned integer, the maximum value of the immediate operand is ________.

A
16383
B
16384
C
16385
D
16386
Question 7 Explanation: 
1 Word = 32 bits
Each instruction has 32 bits.
To support 45 instructions, opcode must contain 6-bits.
Register operand1 requires 6 bits, since the total registers are 64.
Register operand 2 also requires 6 bits

14-bits are left over for immediate Operand using 14-bits, we can give maximum 16383, Since 214 = 16384 (from 0 to 16383)
Question 8

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
A
I only
B
II only
C
I and II only
D
I, II and III only
Question 8 Explanation: 
RFE is a privileged instruction that is performed explicitly by the Operating System to switch from kernel mode to user mode at the end of handling an exception. Hence it has to be a trap. We know when a trap/interrupt is in execution, till its completion all other trap/interrupts will not be allowed to execute. So option D is correct answer.
Question 9

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)?

A
400
B
500
C
600
D
700
Question 9 Explanation: 
The instruction is of 24 bits or 3 bytes. Now the program starts at address 300 and the next will be 303 then, 306, then 309 and so on.
So finally we can say that the values in the program counter will always be the multiple of 3.
Hence, option (C) is correct.
Question 10

The memory locations 1000, 1001 and 1020 have data values 18, 1 and 16 respectively before the following program is executed.

MOVI Rs, 1        ; Move immediate
LOAD Rd, 1000(Rs) ; Load from memory
ADDI Rd, 1000     ; Add immediate
STOREI 0(Rd), 20  ; Store immediate 

Which of the statements below is TRUE after the program is executed?

A
Memory location 1000 has value 20
B
Memory location 1020 has value 20
C
Memory location 1021 has value 20
D
Memory location 1001 has value 20
Question 10 Explanation: 
Rs ← 1
Rd ← 1
Rd ← 1001
Store in address 1001 ← 20.
Question 11

In a simplified computer the instructions are:

  OP Rj,Ri - Performs Rj OP Ri and stores the result in register Ri. 
  OP m,Ri  - Performs val OP Ri and stores the result in Ri. val denotes the content of memory location m.
  MOV m,Ri - Moves the content of memory location m to register Ri.
  MOV Ri,m - Moves the content of register Ri to memory location m.

The computer has only to registers, and OP is either ADD or SUB. Consider the following basic block:

  t1 = a+b
  t2 = c+d
  t3 = e-t2
  t4 = t1-t3 

Assume that all operands are initially in memory. The final value of the computation should be in memory. What is the minimum number of MOV instructions in the code generated for this basic block?

A
2
B
3
C
5
D
6
Question 11 Explanation: 
We can write the given four instructions using OP and MOV operations as below.
MOV a, R1
ADD b, R1
MOV c, R2
ADD d, R2
SUB e, R2
SUB R1, R2
MOV R2, m
So, from the above total no. of MOV instructions = 3
Question 12

Consider the following program segment. Here R1, R2 and R3 are the general purpose registers.

       Instruction      Operation     Instruction size (no. of words)
       MOV R1,(3000)   R1 ← m[3000]                2
 LOOP: MOV R2,(R3)     R2 ← M[R3]                  1
       ADD R2,R1       R2 ← R1 + R2                1
       MOV (R3),R2     M[R3] ← R2                  1
       INC R3          R3 ← R3 + 1                 1
       DEC R1          R1 ← R1 - 1                 1
       BNZ LOOP        Branch on not zero          2
       HALT            Stop                        1 

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:

A
10
B
11
C
20
D
21
Question 12 Explanation: 
Firstly before the loop one memory reference is,
R1 ← m[3000]
Now loop will run 10 times because R1 contain value 10, and in each iteration of the loop there are two memory reference,
R2 ← M[R3]
M[R3] ← R2
So, in total, the no. of memory references are,
2(10) + 1 = 21
Question 13

Consider the following program segment. Here R1, R2 and R3 are the general purpose registers.

       Instruction      Operation     Instruction size (no. of words)
       MOV R1,(3000)   R1 ← m[3000]                2
 LOOP: MOV R2,(R3)     R2 ← M[R3]                  1
       ADD R2,R1       R2 ← R1 + R2                1
       MOV (R3),R2     M[R3] ← R2                  1
       INC R3          R3 ← R3 + 1                 1
       DEC R1          R1 ← R1 - 1                 1
       BNZ LOOP        Branch on not zero          2
       HALT            Stop                        1 

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:

A
100
B
101
C
102
D
110
Question 13 Explanation: 
Loop will execute 10 times since the value in R1 stored is 10 in first step.
Now since the value will change at memory locations from 2000 to 2009 and will not affect the memory locations 2010.
Hence, the value at memory location 2010 it will be old value, i.e., 100.
Question 14

Consider the following program segment. Here R1, R2 and R3 are the general purpose registers.

       Instruction      Operation     Instruction size (no. of words)
       MOV R1,(3000)   R1 ← m[3000]                2
 LOOP: MOV R2,(R3)     R2 ← M[R3]                  1
       ADD R2,R1       R2 ← R1 + R2                1
       MOV (R3),R2     M[R3] ← R2                  1
       INC R3          R3 ← R3 + 1                 1
       DEC R1          R1 ← R1 - 1                 1
       BNZ LOOP        Branch on not zero          2
       HALT            Stop                        1 

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?

A
1005
B
1020
C
1024
D
1040
Question 14 Explanation: 
Memory is byte addressable, so it requires 1 word or 4 bytes to perform a each operation such that
→ Starts at memory location 1000.

Interrupt occurs during the execution of information “INC R3”.
Then the value of address i.e., 1024 is pushed into the stack.
There are 14 questions to complete.

Access quiz wise question and answers by becoming as a solutions adda PRO SUBSCRIBER with Ad-Free content

Register Now

If you have registered and made your payment please contact solutionsadda.in@gmail.com to get access