IAE Academy

GATE 2023 EE Q.57: solution and answer

GATE 2023 · EEQ.57 · 2 marks · NAT

In a given 8-bit general purpose micro-controller there are following flags.

C-Carry, A-Auxiliary Carry, O-Overflow flag, P-Parity (0 for even, 1 for odd)

R0 and R1 are the two general purpose registers of the micro-controller.

After execution of the following instructions, the decimal equivalent of the binary sequence of the flag pattern [CAOP] will be ________.

MOV R0, +0x60
MOV R1, +0x46
ADD R0, R1

See the question in the paper

Answer and solution

ANSWER

After ADD R0, R1 the result is , giving , , , , so .

Official answer: 2Source: Official answer key, GATE 2023 EE (IIT Kanpur)

  1. Write both operands in binary: and . Both have MSB , so read as signed 8-bit numbers both are positive ( and ).

  2. Add them (8-bit binary addition): Check: . So after the ADD.

  3. Carry flag (carry out of bit 7): , so the sum fits in 8 bits, there is no carry out of bit 7, and .

  4. Auxiliary carry (carry out of bit 3 into bit 4): the lower nibbles give , with no carry out of bit 3, so .

  5. Overflow flag (signed overflow: two numbers of the same sign give a result of the opposite sign). At bit 6, , so the carry into bit 7 is ; at bit 7, , so the carry out of bit 7 is . Hence . Equivalently, positive positive produced MSB (a negative-looking result), since .

  6. Parity flag: the result has four 1s, which is even parity. The question defines P as 0 for even, so .

  7. Flag pattern .

KEY IDEA

Do the 8-bit addition once, then read each flag off it separately. Carry is an unsigned idea (carry out of bit 7). Auxiliary carry is the carry out of bit 3. Overflow is a signed idea: it equals the carry into bit 7 XOR the carry out of bit 7. Parity follows whatever convention the question states, here 0 for an even number of 1s.

WATCH OUT FOR

Treating overflow as the same thing as carry. Here there is no carry () but there is signed overflow (), so while . A second trap is using the 8085/8051 convention (parity flag set for even parity). This question defines P as 0 for even, so four 1s gives , not 1.

From the GATE 2023 EE paper. Every question of this paper · Download the full paper · All 9 Processors & memory questions, with notes

More Processors & memory questions