INEL4206PE1sol.pdf
INEL4206PE1sol.pdf
INEL4206PE1sol.pdf
Create successful ePaper yourself
Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.
Problem 1: Programming in C [26 Points]<br />
Write a program in C that does the following:<br />
a) receives three integer numbers from the console<br />
b) if they are already sorted in non-ascending order, it prints “Great! In n tries.” And<br />
ends<br />
c) if they are not already sorted in non-ascending order, it prints “Try again…”, and<br />
goes to step a.<br />
#include <br />
#include <br />
int main(int argc, char *argv[])<br />
{<br />
//Variable declaration<br />
int flag; //loop condition variable<br />
int maxIter; //max number of iterations<br />
int first, second, third; //input integers<br />
//variable initialization<br />
flag=0;<br />
maxIter=0;<br />
while(flag!=1){<br />
maxIter++; //incrementing the loop counter<br />
printf("Please enter three integers in non-ascending order \n");<br />
printf("Enter the first integer \n");<br />
scanf("%d",&first);<br />
printf("Enter the second integer \n");<br />
scanf("%d",&second);<br />
printf("Enter the third integer \n");<br />
scanf("%d",&third);<br />
//cheking for non-ascending order<br />
if( (first >= second) && (second >= third) ){<br />
printf(" %d %d %d \n",first , second ,third);<br />
printf("Great in %d tries", maxIter);<br />
flag=1;<br />
}<br />
else{<br />
//input is not in decreasing order<br />
printf(" %d %d %d \n",first , second ,third);<br />
printf("Try Again......");<br />
}<br />
}// end while<br />
system("PAUSE");<br />
return 0;<br />
}<br />
Page 1/4
Problem 2: Number Systems [30 points]<br />
a) Convert -20.125 from decimal number into single-precision floating point number:<br />
Write your final answer here:<br />
1 10000011 01000010000000000000000<br />
Show the details of calculations here:<br />
20 10100<br />
0.125 0.001<br />
20.125 10100.001<br />
10100.001=1.0100001 *2^4<br />
4+127=131<br />
131 10000011<br />
b) Convert +65 from decimal numbers into signed binary words.<br />
Write your final answer here:<br />
00000000 01000001<br />
c) Convert -65 from decimal numbers into signed binary words.<br />
Write your final answer here:<br />
11111111 10111111<br />
Show the details of calculations here:<br />
-65= -128+32+16+8+4+2+1<br />
11111111 10111111<br />
Page 2/4
Problem 2: Number Systems (continued)<br />
d) Convert AB.CD from hexadecimal number into binary-coded hexadecimal code (BCH)<br />
Your answer here:<br />
1010 1011 . 1010 1101<br />
e) Show how 15-10 (15 minus 10) is calculated using the 2’s complement and the addition operation.<br />
Note. You need to convert both numbers to binary first.<br />
Your answer here:<br />
15 – 10 = 15 + 2’s comp of (10)<br />
15 1111<br />
10 1010<br />
1111 – 1010 = 1111 + 0110= 1/ 0101<br />
Since carry bit is 1, we ignore it and the final answer is 0101<br />
f) Convert 11011.11from binary to decimal.<br />
Your answer here:<br />
16+8+2+1+1/2+1/4=27.75<br />
Page 3/4
Problem 3: Short Answer Questions: [24 Points]<br />
a) What is the purpose of IP/EIP register?<br />
b) What memory location is addressed by in the real mode 80286 register when SS=2900H and<br />
SP=2A00H ?<br />
2BA00H<br />
c) Protected mode memory addressing allows access to which area of the memory in the 80286<br />
microprocessor?<br />
ALL 16 MB<br />
e) How much memory is found in the Windows system area?<br />
f) How much memory is found in the DOS transient program area?<br />
Keeps the address of the next step of the<br />
program<br />
d) If DS=0107H in a protected mode system, which entry, which table, and which requested privilege level<br />
are selected?<br />
Entry:<br />
Table:<br />
Requested privilege<br />
20H<br />
Local<br />
level: 3<br />
2GB<br />
640KB<br />
The content of a segment register during protected mode operation of the 80286-Core2 µp<br />
Page 4/4