Professional Documents
Culture Documents
2
2
#include "pch.h"
#include <iostream>
#include <stdio.h>
}
}
void diagSEC0(int *, int n) {
int numar;
int asd;
_asm {
mov ebx, [ebp+8]
mov ecx, [ebp+12]
lea eax, [ecx*4-4]
add ebx, eax
mov esi, 0 // i=0;
_while:
cmp esi, ecx
jge endWhile
inc esi
jmp _while
endWhile:
}
}
unsigned nrBits(int)
{
_asm
{
MOV ebx, [ebp + 8]
MOV EAX, 0
start_while:
CMP ebx, 0
JE stop_while
not_increment :
SHR ebx, 1
JMP start_while
stop_while :
}
unsigned isPrime(int)
{
_asm
{
MOV ebx, [ebp + 8]
CMP ebx, 2
je prim
jl not_prim
MOV edx, 0
MOV ecx, 2
MOV eax, ebx
DIV ecx
MOV esi, eax
for_start :
cmp ecx, esi
JG for_stop
MOV edx, 0
MOV eax, ebx
DIV ecx
CMP edx, 0
JE not_prim
INC ecx
for_stop :
prim:
MOV eax, 1
jmp endu
not_prim :
MOV eax, 0
jmp endu
endu :
}
}
int palindrom(unsigned int)
{
_asm
{
MOV ebx, [ebp + 8]
MOV esi, ebx
MOV ecx, 0
MOV edi, 10
while_start:
cmp esi, 0
je while_stop
MOV edx, 0
MOV eax, esi
DIV edi
MOV esi, eax
jmp while_start
while_stop :
MOV eax, 0
MOV esi, 0
for_start :
CMP esi, ecx
JGE for_stop
MUL edi
ADD eax, [ebp + 12 + esi * 4]
INC esi
jmp for_start
for_stop :
is_pali :
mov eax, 1
jmp _end
not_pali :
mov eax, 0
jmp _end
_end :
}
}
int invers(unsigned int)
{
_asm
{
MOV ebx, [ebp + 8]
MOV esi, ebx
MOV ecx, 0
MOV edi, 10
while_start:
cmp esi, 0
je while_stop
MOV edx, 0
MOV eax, esi
DIV edi
MOV esi, eax
jmp while_start
while_stop :
MOV eax, 0
MOV esi, 0
for_start :
CMP esi, ecx
JGE for_stop
MUL edi
ADD eax, [ebp + 12 + esi * 4]
INC esi
jmp for_start
for_stop :
}
}
int powerOf2(int, int*)
{
_asm
{
MOV eax, 0
MOV ebx, [ebp + 12]
MOV ecx, [ebp + 8]
for_start:
cmp ecx, 0
JLE for_stop
MOV edi, [ebx + 4 * ecx - 4]
MOV esi, edi
DEC edi
AND esi, edi
CMP esi, 0
JNE not_power_of_2
power_of_2 :
INC eax
not_power_of_2 :
DEC ecx
jmp for_start
for_stop :
_end:
}
}
int progresie_aritmetica(int, int*) {
_asm {
cmp ecx, 3
JL not_progresie
for_start:
CMP ecx, 1
JL for_stop
DEC ecx
for_stop :
progresie:
MOV eax, 1
JMP _end
not_progresie :
MOV eax, 0
JMP _end
_end :
}
}
void print1() {
cout << "DA";
}
void print2() {
cout << "NU";
}
/*int main() // 1
{
unsigned char p = 0;
_asm {
mov eax, main
}
for (int i = 0; i < 10; i++) {
_asm {
mov p, byte[eax]
inc eax
}
printf("%X ", p);
}
}*/
/*int main() // 2
{
int x, y;
x = 0;
_asm {
mov eax, x
cmp eax, 0
je el
mov dword ptr y, 7
jmp els
el:
mov dword ptr y, 3
els:
}
*/
/*
byte ---> 1 byte ah/al
word ---> 2 bytes ax
dword ---> 4 bytes eax
qword ---> 8 bytes rax
jmp-uri
j ---> jump if
e ---> equal
ne ---> not equal
g ---> greater
l ---> lower
ge ---> greater or equal
le ---> lower or equal
z ---> zero
nz ---> not zero
a ---> greater without sign
ae ---> greater equal without sign
b ---> lower without sign
be ---> lower equal without sign
$ ---> pozitia curenta
lea ---> low effective address, get the address of a variable
*/
//cout << y << endl;
/*
int s, n;
cin >> n;
_asm {
mov eax, 0
mov ecx, 0
beginfor:
cmp ecx, n
jge endfor
add eax, ecx
inc ecx
jmp beginfor
endfor:
mov s, eax
}
cout << s << endl;
*/
/*
char s[100];
int n;
cin >> s;
_asm {
mov ecx, 0
lea eax, s;
beginwhile:
mov bl, [eax + ecx]
cmp bl, 0
je endwhile
inc ecx
jmp beginwhile
endwhile:
mov n, ecx
}
cout << n << endl;
*/
/*int x[] = { 1, 2, 3, 4, 5, 6 };
int n = 6, s;
_asm {
mov ecx, 0
mov eax, 0
mov edx, 0
mov edi, 2
mov s, 0
lea ebx, x
beginwhile :
cmp ecx, n
je endwhile
mov eax, DWORD PTR[ebx + 4 * ecx]
div edi
cmp edx, 0
jne endif
mov eax, DWORD PTR[ebx + 4 * ecx]
add s, eax
mov edx, 0
endif:
inc ecx
jmp beginwhile
endwhile :
}
cout << s << endl;
return 0;
}
*/
// 3
int len(char*) {
_asm {
mov ebx, [ebp + 8]
mov eax, 0
beginwhile:
mov cl, BYTE PTR[ebx + eax]
cmp cl, 0
je endwhile
inc eax
jmp beginwhile
endwhile :
}
}
}
}
/*
int main()
{
/* int a = 5, b = 10, s;
_asm {
push b
push a
call sum
add esp, 8
mov s, eax
}
std::cout << s << std::endl;
// 4
par :
MOV eax, 1
JMP _end
impar :
MOV eax, 0
JMP _end
_end :
}
}
startwhile:
cmp ecx, eax
je endwhile
inc ecx
jmp startwhile
endwhile :
}
}
mov eax, p
mul val
push eax
push c
call printf
pop eax
pop eax
inc i
add p, 4
jmp multiply
finish :
mov l, eax
xor eax, eax
}
}
/*int main()
{
int m[4][4];
fill((int*)m, 4, 4);
diagSEC0((int*)m, 4);
for (int i = 0; i <= 3; i++){
for (int j = 0; j <= 3; j++)
cout << m[i][j] << " ";
cout << endl;
}
}*/
int main()
{
int v[] = { 1, 2, 3, 4, 5 };
cout << powerOf2(5, v);
return 0;
}
// 5
struct MyStruct {
char x; //0
char a; //1
int b; //4
short c; //8
};
struct Countt {
short nrLitere; //0
int nrCifre; //4
int nrTotal; //8
};
else_caracter_mic :
cmp[ebx + ecx], 'A'
jl else_caracter_mare
cmp[ebx + ecx], 'Z'
jg else_caracter_mare
inc eax
else_caracter_mare :
cmp[ebx + ecx], '0'
jl else_numar
cmp[ebx + ecx], '9'
jg else_numar
inc edx
else_numar :
inc ecx
jmp startwhile
endwhile :
mov ebx, [ebp + 8]
mov[ebx], ax
mov[ebx + 4], edx
mov[ebx + 8], ecx
}
}