You are on page 1of 3

Integrantes:

*
*
*

1)Indicate whether the following statements are syntactically correct or incorrect. If incorrect,
indicate what is wrong with the statement:

A.inc eax,1 (Incorrecto) deberia ser in eax++


B.add ebx,ecx (Incorrecto) debería ir un numero ebx,number
C.add dog,cat (Incorrecto)deberia ser eax,cat o eax,dog
B.idiv 3 (Correcto)
E.sub 2,number (Incorrecto) deberia ser sub ax,2
F.imul eax (Correcto)

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

mov result ,eax

C. answer=number / 2;

mov eax ,number


cdq
idiv 2
mov answer,eax

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

C. total=num1 / num2 - (num3*num4);


mov ebx,num3
imul num4
neg ebx
mov eax,num1
cdq
idiv ebx
mov total,eax

D. r=-s + t++;
mov eax,s
neg eax
add t
mov r,eax
inc t

E. m=n∗((i - j)∗ k);


mov ebx,i
sub ebx,j
imul k
mov eax,n
imul eax
mov m,eax

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

5. Write a complete assembly language program to implement the following C program:

#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

You might also like