Professional Documents
Culture Documents
Midterm 1
Absolutely No Books Notes Calculators- Computers
Question 1 : (Knowledge assessed Assembly language , program flow) (20 points)
Given the following function compareSET that accepts two integer arguments: If the second argument
is larger than the first argument, function compare set exchanges the values of these variables and
returns 1. Otherwise returns 0.
.global
_compareSET
int compareSET(int *a, int *b)
_compareSET:
{
int temp;
If ( *b > *a )
pushl %ebp
{ temp = *b;
movl %esp,%ebp
*b = *a;
*a = temp;
movl 8(%ebp),%ebx
return (1);
}
movl 12(%ebp),%ecx
else return(0);
movl (%ebx),%edx
}
_____________________________________________
The main function calling the function
CompareSET is given below. Write the function
int compareSET();
int main(void)
{
int a, b;
a=10;
b=7;
if (compareSET(&a,&b) == 0)
{
puts("No change was needed");
}
else puts("Values have been changed
");
}
movl $0,%eax
cmpl %edx,(%ecx)
JLE done
movl (%ecx),%eax
movl %eax,(%ebx)
movl %edx,(%ecx)
movl $1,%eax
done:
movl %ebp,&esp
popl %ebp
ret
.globl _Threshold
_Threshold:
pushl %ebp
movl %esp,%ebp
movl 8(%ebp), %ebx
movl 12(%ebp), %ecx
movl 16(%ebp), %edx
dec %ecx
loopstart:
cmpl $0,%ecx
JL done
cmpl %edx,(%ebx,%ecx,4)
JLE nochange
movl %edx,(%ebx,%ecx,4)
nochange:
dec %ecx
JMP loopstarrt
done:
popl
ret
%ebp
0 |1 0 1 1|0 1 1 0 1
b- (5 points) Consider a 10 bit floating point number system. The sign bit is the most significant bit.
4 bits are reserved for the exponent and remaining 5 bits are the mantissa. A bias of 7 is to be
used. What is the floating point representation of number 12.5
0 |1 0 1 0 |1 0 0 1 0
c- (10 points) Using the rules for floating point addition , add the two floating point numbers in (a)
and (b) and present the result as a binary floating point number. Please note that it is not allowed
to add the numbers in decimal number system and represent the number in floating point.
0 |1 1 0 0|0 0 0 1 1
Question 4 : ( 8 points)
a- Consider a 16 bit binary number system. Write the Hexadecimal equivalent of the most negative number.
Answer
0 x 8000
b- Consider a 16 bit binary number system. Write the number -127 in binary.
Answer
c- Compute two's complement of the number 0x56FF and write the result in Hexadecimal.
Answer
d- Consider a 16 bit binary number system. What is the hexadecimal equivalent of the signed binary number
0101011101110011.
Answer
0 x 5773
b- Write an assembly language instruction equivalent of the C statement Numbers[i] = 11; Assume in
assembly the base Numbers is mapped to register %ebx and index i is mapped to %esi register. Also
assume integer size variables.
.global addUS
_addUS:
pushl %ebp
movl %esp,%ebp
movl 8(%ebp),%ebx
movl 12(%ebp),%ecx
movl $1,%esi
continue:
movl %esi,%edi
dec %edi
movl (%ebx,%edi,4),%eax
addl %eax,(%ebx,%esi,4)
inc %esi
cmpl %esi,%ecx
JG continue
popl %ebp
ret