Professional Documents
Culture Documents
*
*
*
1)Indicate whether the following statements are syntactically correct or incorrect. If incorrect,
indicate what is wrong with the statement:
2. Convert the following C arithmetic statements to the equivalent Intel assembly language
statements (hint: as discussed in the text, do not forget to move any immediate values
into a register first for the imul and idiv instructions, if necessary):
A. product=3∗number;
mov eax,3
imul number
mov product,eax
B. result=number % amount;
mov eax,number
C. answer=number / 2;
D. difference=4 - number;
mov eax,4
sub eax,number
mov difference,eax
3. Using order of operations from C, convert the following arithmetic statements into the
equivalent assembly language statements. Be sure not to destroy the contents of any of
the variables that appear only to the right of the assignment symbol:
A. x=x∗y+z*2;
mov eax ,x
imul y
add ebx ,z
imul 2
mov x,eax
B. a=b-c/3;
mov eax,b
sub z
cdq
idiv 3
mov a,eax
D. r=-s + t++;
mov eax,s
neg eax
add t
mov r,eax
inc t
4. Using the order of operations from C, convert the following arithmetic statements into
the equivalent assembly language code segment. Be careful to implement the unary
minus sign, increment, and decrement operators carefully:
A. --i;
sub i,1
B. j=++k - m;
mov eax,k
add k,1
sub eax,m
mov j,eax
C. z=-(x + y);
mov eax,x
add eax,y
neg eax
mov z.eax
D. a=++b - c++;
mov eax,b
add b,1
sub ebx,c
mov a,eax
inc c
E. x=-y + z--;
mov eax,y
neg eax
add ebx z
sub z,1
move x,eax
#include <stdio.h>
int main(){
int number;
printf("\n%s","Enter an integer: ");
scanf("%d",&number);
number=7-number*3;
printf("\n%s%d\n\n","The integer is: ",number);
return 0;
}
6. Given Ohm’s law from the complete program at the end of this chapter and Watt’s law
as W=IE, where W stands for the number of watts, write a complete assembly language
program to prompt for and input the number amperes and ohms, and then calculate both
the number of volts and number of watts. The form of the input and output can be found
below, and as always be careful with the vertical and horizontal spacings:
Input and Output
Enter the number of amperes: 5
Enter the number of ohms: 4
The number of volts is: 20
The number of watts is: 100
7. Write a complete assembly language program to prompt for and input the temperature
in degrees Fahrenheit, calculate the degrees in Celsius, and then output the degrees in
Celsius. The equation to be used is
C=(F–32)/9∗5, where C stands for Celsius and F stands for Fahrenheit. Note that the answer will be
off slightly due to using integers andbe very careful to use the proper order of operations. The form
of the input and outputcan be found below. Be sure to use proper vertical and horizontal spacings:
Input and Output
Enter the degrees in Fahrenheit: 100
The degrees in Celsius is: 35