recategorized by
5,273 views
21 votes
21 votes

Consider the following high level programming segment. Give the contents of the memory locations for variables $W, X, Y$ and $Z$ after the execution of the program segment. The values of the variables $A$ and $B$ are $5CH$ and $92H$, respectively. Also indicate error conditions if any.

var
    A, B, W, X, Y   :unsigned byte;
    Z               :unsigned integer, (each integer is represented by two bytes)
begin
    X               :=A+B
    Y               :=abs(A-B);
    W               :=A-B
    Z               :=A*B
end;
recategorized by

3 Answers

Best answer
34 votes
34 votes

The maximum value that can be accommodated in an unsigned byte $= 255$ and unsigned int $= 65535.$

$A$ and $B$ are given in Hexadecimal.

  • $A = 5C_{H } = (92)_{10 }$
  • $B = 92_{H } = (146)_{10}$
  • $X = A + B = (238)_{10} = EE_{H }$
  • $Y = \text{abs} (A - B) = (54)_{10 } = 36_{H }$
  •  $W = A - B = (-54)_{10 }$

Negative numbers represented in $2$'s complement form $\implies  -54 = 11001010$  ( in $8$-bit representations )

But $W$ is unsigned, therefore it cannot look for the sign $\implies W = 11001010 = CA_{H }$

$Z = A \ast B = (13432)_{10 } = 3478_{H }$

edited by
11 votes
11 votes
There won't be any problem.

The quick approach is:---

Here, $H$ denotes Hexadecimal No.

$X=A+B=5CH+92H=EEH$ (One Byte is enough)

$Y=abs(A-B) \ \& \ W=A-B$

(Subtraction operation never cause Overflow So $1$ Byte is enough)

$Z=A*B$

$n -bit * n-bit$ requires $2n \ bit$.

So, $8-bit*8-bit =16 \ bit$ required ($\&$ as per question $z$ is $16  \ bit$ unsigned number)

Max value that can be accommodated inside an unsigned $byte = 255$ and unsigned $int = 65535$
edited by
–2 votes
–2 votes

i think X = EC
          W =52 
           Z = will be error because its exceeds the size...

 

Related questions

11 votes
11 votes
3 answers
2
21 votes
21 votes
1 answer
3
Kathleen asked Oct 8, 2014
3,904 views
In the following Pascal program segment, what is the value of X after the execution of the program segment?X := -10; Y := 20; If X Y then if X < 0 then X := abs(X) else ...
0 votes
0 votes
0 answers
4
Arjun asked Jul 14, 2019
1,386 views
Consider a CRT display that has a text mode display format of $80×25$ characters with a $9×12$ character cell. What is the size of the video buffer RAM for the display ...