GATE / CS ARCHIVE

GATE CSE 1995 / QUESTION 3

Evaluate unsigned byte arithmetic

Computer Organization & Architecture · Data Representation & Arithmetic · Full GATE CSE 1995 paper

GATE 1995, Q3 Descriptive
Report issue

Data Representation & Arithmetic

Question 3, GATE 1995: A and B are unsigned bytes with A=5CH and B=92H; W,X,Y are unsigned bytes and Z is a two-byte unsigned integer. Execute X:=A+B; Y:=abs(A−B); W:=A−B; Z:=A*B. Give the stored values and error conditions. GFG supplies this Y statement; GateForum prints malformed abs(bA-b).
Question 3, GATE 1995: A and B are unsigned bytes with A=5CH and B=92H; W,X,Y are unsigned bytes and Z is a two-byte unsigned integer. Execute X:=A+B; Y:=abs(A−B); W:=A−B; Z:=A*B. Give the stored values and error conditions. GFG supplies this Y statement; GateForum prints malformed abs(bA-b).
Tap to enlarge
Answer & solution

Answer: With widened intermediates: X=EEH, Y=36H, Z=3478H; W underflows (CAH if wrapping). (no official key was published)

Convert the hexadecimal operands first: A=92 and B=146. Their sum is 238=EEH, within the unsigned-byte range 0 through 255. Their mathematical difference is −54, so its absolute value is 54=36H. The product is 13432=3478H, within the unsigned 16-bit range. Thus X and Z fit their declared destinations and Y fits if abs receives the mathematical signed difference.

W cannot represent −54. A checked implementation reports a range/underflow error; an explicitly wrapping 8-bit implementation stores −54 modulo 256=202=CAH. These are distinct execution models, not two simultaneous outcomes. If execution traps at W, the subsequent assignment to Z is not reached.

There is also an intermediate-arithmetic ambiguity: if A−B is evaluated as an unsigned 8-bit operation before abs, it becomes CAH=202 and abs leaves it unchanged, giving Y=CAH instead of 36H. Similarly Z requires multiplication in a sufficiently wide type, not truncation to a byte before assignment. The pseudocode does not specify these rules or byte order. Report Z as the word 3478H, with bytes 34H and 78H in unspecified order.

Original paper, page 5