You are on page 1of 3

a) Max(a,b,c)

#include <stdio.h>
int main()
{
int a,b,c,maxi;
printf("a=");
scanf("%d",&a);
printf("b=");
scanf("%d",&b);
printf("c=");
scanf("%d",&c);
__asm
{
mov eax,a
mov
ebx,b
mov ecx,c
cmp eax,ebx
ja compxac
jbe compxbc
compxac:
cmp eax,ecx
ja resulta
jbe resultc
compxbc:
cmp ebx,ecx
ja resultb
jbe resultc
resulta:
mov maxi,eax
jmp fin
resultb:
mov maxi,ebx
jmp fin
resultc:
mov maxi,ecx
fin:
}
printf("\n\n Maximul dintre %d, %d, %d este %d", a, b, c, maxi);
return 0;
}

b) CMMDC(a,b)
#include <stdio.h>
int main()
{

int a,b,re;
printf("a=");
scanf("%d",&a);
printf("b=");
scanf("%d",&b);
__asm
{
mov eax,a
mov
ebx,b
compare:cmp eax,ebx
ja
jb
je

difab
difba
result

difab: sub eax,ebx


jmp compare
difba: sub ebx,eax
jmp compare
result: mov re,eax
}
printf("\n\n CMMDC( %d, %d) = %d", a, b, re);
return 0;
}

c) Sum for i=1 to n (n inputed)


#include <stdio.h>
int main()
{
int n,re;
printf("n=");
scanf("%d",&n);
__asm
{
mov eax,n
mov edx,0
mov ecx,0
compare:cmp eax,edx
ja
je

incradd
result

incradd:add edx,1
add ecx,edx
jmp compare

result: mov
}

re,ecx

printf("\n\n sum=%d",re);
return 0;
}

You might also like