#include <iostream>
using namespace std;
void printSum(int *);
void printfAsm();
int main(void) {
int table[] = {3,4,5,6,4,5,6,7,8,6,5,4,5,6};
printSum(table);
printfAsm();
return 0;
}
void printSum(int *table) {
int sum = 0;
cout << "printSum(); function called - ";
_asm {
mov ebx, 0 // holds sum
mov ecx, 0; // initialize counter
mov edx, [esp + 8] // pointer to table
_label:
cmp ecx, 14 // have we processed all elements in the table ?
jl _doIt // if not jump to label _doIt
jmp _finish // else jump to _finish
_doIt:
add ebx, edx // add table[i] to sum
inc edx // get next element
inc ecx // increment counter
jmp _label // jump back to label
_finish:
mov sum, ebx // return result into sum
}
cout << "The sum is : " << sum << endl;
}
char format[] = "%s\n";
char stringAsm[] = "Hello there !";
void printfAsm() {
cout << "printfAsm(); function called - ";
_asm {
mov eax, offset stringAsm // move the address of stringAsm into eax
push eax // push it onto stack
mov eax, offset format // move the address of format into eax
push eax // push it onto stack
call printf // call printf
pop ebx // pop format
pop ebx // pop stringAsm
}
}