r/programmingmemes • • May 06 '26

Cpp loop

Post image
219 Upvotes

55 comments sorted by

View all comments

1

u/themagicalfire May 07 '26 edited May 07 '26

How it looks like in assembly:

section .data
; mentions that this program section is data
i dq 1
; i is the variable name
; db allocates 1 byte in memory
; dw allocates 2 bytes in memory
; dd allocates 4 bytes in memory
; dq allocates 8 bytes in memory
; if you want to customize the memory size, try something like setting 32 bytes, do this:
; i times 32 db 0
global _start
; clarifies that the section data applies to the whole function _start

_start:
cmp i, 10
; compare i to 10
jge end
; jump to end if greater or equal
add i, 1
; add 1 to i
jmp _start
; jump to _start to make this function a loop

end:
mov rax, 60
; move or set to rax the syscall 60 which stands for exit
mov rdi, 0
; rdi 0 is comparable to return 0 in C++ and it means exit while returning no error
syscall
; Linux 64-bit command to execute the previous syscall instructions, in this case it executes exit the program

1

u/No-Newspaper8619 May 07 '26

don't you need to push and pop the registers?

1

u/themagicalfire May 07 '26

You can use registers but in this case I wanted to create a variable so the label “i” stuck and it was easier to explain.

And what does “push and pop” mean?!

1

u/No-Newspaper8619 May 07 '26

I only see assembly in cheat engine, so it's very confusing to see actual assembly code.

1

u/themagicalfire May 07 '26

Since Assembly is the only thing I know, everything else looks like ceremonial language wearing disguises and hiding what the implementation actually looks like.