Skip to content

Instantly share code, notes, and snippets.

@YusufOzmen01
Created September 19, 2024 17:44
Show Gist options
  • Select an option

  • Save YusufOzmen01/070611b911d7dd876393bf555b856673 to your computer and use it in GitHub Desktop.

Select an option

Save YusufOzmen01/070611b911d7dd876393bf555b856673 to your computer and use it in GitHub Desktop.
x86_64 GCC Loop
main:
push rbp ; Store the previous stack frame base pointer
mov rbp, rsp ; Copy the current stack frame pointer to rbp
mov DWORD PTR [rbp-4], 5 ; Store the value 5 (32 bit integer)
loop:
cmp DWORD PTR [rbp-4], 0 ; Compare the value we stored with 0 to see if we completed the loop
je loop_exit ; Jump to the .loop_exit section of the code if we hit 0
sub DWORD PTR [rbp-4], 1 ; Subtract 1 from the counter
jmp loop ; Jump to the loop beginning to repeat the cycle
loop_exit:
pop rbp ; Pop the pointer we stored
ret
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment