• recategorized by
9,784 views
40 40 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;

3 Answers

Best answer
58 58 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
14 14 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 –2 votes

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

 

Position:
Show:

Related questions

17 17 votes
3 answers 3 answers
5.6k
5.6k views
Kathleen asked Oct 8, 2014
5,631 views
Consider the following Pascal function where $A$ and $B$ are non-zero positive integers. What is the value of $\text{GET}(3, 2)$?function GET(A,B:integer): integer; begin...
15 15 votes
3 answers 3 answers
5.8k
5.8k views
Kathleen asked Oct 8, 2014
5,783 views
Assume that $X$ and $Y$ are non-zero positive integers. What does the following Pascal program segment do?while X < Y do if X Y then X := X - Y else Y := Y - X; write(X)...
24 24 votes
1 answers 1 answer
8.3k
8.3k views
Kathleen asked Oct 8, 2014
8,265 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 ...
1 1 vote
1 1 answer
1.8k
1.8k views
Arjun asked Jul 14, 2019
1,760 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 to...