#include "stdafx.h"
#include <cstdlib>
#include <iostream>
using namespace std;
int _tmain(int argc, _TCHAR* argv[])
{
short X;
short Y;
long count = 0;
cout << "Podschet par (X,Y) iz [-128..127], gde (|X|-|Y|) mod 4 = 0" << endl;
__asm {
mov word ptr X, -128
outer_loop:
mov cx, 256
mov word ptr Y, -128
inner_loop:
mov ax, word ptr X
test ax, ax
jns ax_pos
neg ax
ax_pos:
mov dx, word ptr Y
test dx, dx
jns ay_pos
neg dx
ay_pos:
sub ax, dx
test ax, 3
jnz not_match
inc dword ptr count
not_match:
inc word ptr Y
loop inner_loop
inc word ptr X
cmp word ptr X, 127
jle outer_loop
}
cout << hex << count << endl;
cout << "count " << dec << count << endl;
system("pause");
return 0;
}
#include "stdafx.h"
#include <cstdlib>
#include <iostream>
using namespace std;
int _tmain(int argc, _TCHAR* argv[])
{
short X;
short Y;
short resX = 0;
short resY = 0;
long count = 0;
long found = 0;
cout << "Poisk 200-oy pary (X,Y), gde (|X|-|Y|) mod 4 = 0" << endl;
__asm {
mov word ptr X, -128
outer_loop:
mov cx, 256
mov word ptr Y, -128
inner_loop:
mov ax, word ptr X
test ax, ax
jns ax_pos
neg ax
ax_pos:
mov dx, word ptr Y
test dx, dx
jns ay_pos
neg dx
ay_pos:
sub ax, dx
test ax, 3
jnz not_match
inc dword ptr count
cmp dword ptr count, 200
jne not_match
mov ax, word ptr X
mov word ptr resX, ax
mov ax, word ptr Y
mov word ptr resY, ax
mov dword ptr found, 1
xor cx, cx
jmp inner_end
not_match:
inc word ptr Y
loop inner_loop
inner_end:
cmp dword ptr found, 1
je done
inc word ptr X
cmp word ptr X, 127
jle outer_loop
done:
}
if (found == 1)
{
cout << "200-ya para: X=" << dec << resX << ", Y=" << resY << endl;
cout << hex << "(hex) X=" << resX << ", Y=" << resY << endl;
}
else
{
cout << "Par menshe 200!" << endl;
}
system("pause");
return 0;
}