Created
March 4, 2021 19:30
-
-
Save codenulls/82e7b9d13a1354919146e14171522365 to your computer and use it in GitHub Desktop.
prints: 0 2 4 6 8 10 12 14 16 18
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#include <stdint.h> | |
#include <Windows.h> | |
#include <iostream> | |
void __cdecl PrintNumber(int i) | |
{ | |
printf("%d ", i); | |
} | |
int main() | |
{ | |
__asm | |
{ | |
mov eax, 0 // i = 0 | |
mov ecx, 2 | |
mov edx, 0 | |
REPEAT_LOOP: | |
mov esi, eax | |
mul ecx | |
// calling the PrintNumber function can modify ecx (eax and edx can also get modified there) | |
// so store the value on the stack | |
push ecx | |
push eax // Now ecx is on top of the stack | |
call PrintNumber | |
add esp, 4 // clear the parameter from the stack | |
pop ecx | |
mov eax, esi | |
add eax, 1 // i += 1 | |
cmp eax, 10 | |
jb REPEAT_LOOP | |
} | |
getchar(); // halt the program | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment