Skip to content

Instantly share code, notes, and snippets.

@codenulls
Created March 4, 2021 19:30
Show Gist options
  • Save codenulls/82e7b9d13a1354919146e14171522365 to your computer and use it in GitHub Desktop.
Save codenulls/82e7b9d13a1354919146e14171522365 to your computer and use it in GitHub Desktop.
prints: 0 2 4 6 8 10 12 14 16 18
#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