Bài 1: #Include #Include Using Namespace STD Int Count (Int A) (Int S - Asm (Mov Ebx, Ss:a Mov Eax, 0 WHILE: CMP Ebx, 0 Je End - While Test Ebx, 1

You might also like

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 4

Bi 1:

#include <iostream>
#include<conio.h>
using namespace std;
int Count(int a)
{
int s;
__asm{
mov ebx, ss:a
mov eax,0
WHILE: cmp ebx,0
je END_WHILE
test ebx,1
je a
INC eax
a:SHR bx,1
jmp WHILE
END_WHILE:
mov s,eax
}

return s;
}

int main()
{
int a,n;
cout<<"nhap 1 so: ";
cin>>n;
a=Count(n);
cout<<"\nso bit 1 cua so "<<n<<" la "<<a;
getch();
return 0;
}
Bai 2:
#include <iostream>
#include<conio.h>
using namespace std;
int Sum(int A[], int N)

{int s=0;
__asm{
mov ebx, ss:A
mov ecx, ss:N
mov edx,0
shl cx,2
mov edi,0
FOR: cmp edi,ecx
jae END_FOR
mov eax,[ebx][edi]
shr eax,2
jc Khongchiahet
shl eax,2
add edx,eax
Khongchiahet:
add di,4
jmp FOR
END_FOR: mov s,edx
}


return s;

}

int main()
{
int b;
int a[3];
cout<<"nhap gia tri mang";
for(int i=0;i<3;i++)
{
cout<<"\na["<<i<<"]=";
cin>>a[i];
}
cout<<"\ntong so phan tu chia het cho 4 cua mang a[3] la: ";
b=Sum(a,3);
cout<<b;
getch();
return 0;
}

You might also like