Está en la página 1de 6

//Operaciones aritmticas C++ y Ensamblador

#include <stdio.h>
#include <conio.h>

int suma( int x, int y)


{
int result;

asm{
push ax;
push cx;
mov cx,x
mov ax,y
add ax,cx
mov result,ax;
pop cx;
pop ax;
}
return result;
}

int resta( int x, int y)


{
int result;

asm{

push ax;
push cx;
mov cx,y
mov ax,x
sub ax,cx
mov result,ax;
pop cx;
pop ax;
}
return result;
}

int mult( int x, int y)


{
int result;

asm{
push ax;
push cx;
mov cx,x
mov ax,y
mul cx
mov result,ax;
pop cx;
pop ax;
}

return result;
}

int division( int x, int y)


{
int result;

asm{
push ax;
push cx;
mov ax,x
mov bx,y
div bx
mov result,ax;
pop cx;
pop ax;
}
return result;
}

void pause()
{
asm {

mov ah, 10h


int 16h
}
}

void cls()
{
asm {
mov al, 3
mov ah, 0
int 10h
}
}

void main()
{

int dato1 = 0,
dato2 = 0,
resultado = 0, opc, salir = 0;

do{
cls();
//clrscr();
printf("\nIngrese el primer valor :");

scanf("%d",&dato1);

printf("Ingrese el segundo valor :");


scanf("%d",&dato2);

do
{
printf("\n\n1) suma\n2)resta\n3)multiplicacion\n4)division\n5)Salir");
printf("\n\nIngrese una opcion :");
scanf("%d",&opc);

switch(opc)
{
case 1 : resultado = suma(dato1, dato2);break;
case 2 : resultado = resta(dato1, dato2);break;
case 3 : resultado = mult(dato1, dato2);break;
case 4 : resultado = division(dato1, dato2);break;
case 5 : salir = 1;resultado = 0;break;
}
}while(opc< 1 || opc > 5 );

printf("\n\nResultado = %d",resultado);
pause();

}while(salir == 0);

//getch();
}

También podría gustarte