9
u/themagicalfire Mar 24 '26
Is this what it does? Creating a variable called msg made of 13 spaces, then moves the variable to rsi in order to call the variable to text?
7
u/wizarddos Mar 24 '26
Not quite
First it reserves a chunk of memory with text. Then sets RAX register to 0x1, which corresponds to write syscall. Then sets rdi register to 0x1, which means text will be written to standard output (iirc). Then in rsi it specifies what will be displayed (variable msg in this case) and sets its length in rdx to 13 Next it calls kernel to execute mentioned syscall and then does it again, this time to EXIT the program with code 0
1
u/themagicalfire Mar 24 '26
Ah, so rax 0x1 and rdi 0x1 are asked to create memory and print a text, then rsi is like saying “print”, and rdx specifies the amount of characters. Syscall means execute. Then to exit you set rax to 60 (number to exit?) and rdi to 0 to show the text ended?
3
u/BenchEmbarrassed7316 Mar 24 '26
In x86 assembler you have 8 or 16 registers. These are what you might call very fast variables. For 16 bit architecture the name will be
AX, for 32 bit it will beEAX(extended), and for 64 bit it will beRAX(fantasy over). For 8 and 16 bit architectures you have 8 registers, for 64 bit they addR8-R15.
AX - accumulator, the result of the function is written to it
BX - base, previously used for addressing non-flat memory
CX - counter
DX - data
SI - source
DI - destination
BP - base stack pointer, used for addressing local variables and function arguments
SP - stack pointer, points to the top of the stack
IP - instruction pointer, points to the current instruction
FLAGS - most operations change the state of the flags register (mathematical operation, the result of comparing two numbers)
There are so-called calling conventions, which describe how functions should accept and return a result. Interestingly, there are specific instructions, for example we can write memory addresses in
SIandDI, write the size inCXand copy the memory like this:mov rsi, src mov rdi, dst mov rcx, 1024 cld rep movsqCopies 1024 elements, moving forward, element size - 8 bytes.
2
u/wizarddos Mar 24 '26
Rax is a register that stores a syscall number in this case - in short it’s just an info what function does a program want kernel to call. So RAX is responsible for “saying print” (or write in this case)
0x1 is a system call for sys_write - program will write data to a specific place. That place is specified in rdi. 0x1 is standard output (a.ka console)
Syscall instruction just means that a request prepared earlier (with setting registers) is ready to be passed down to kernel
And then we specify, that next thing we want to do is exit, so rax is set to 60 (meaning sys_exit). Then exit code is specified - in our case it’s zero, which means “no errors”
And then syscall, which I’ve explained
1
u/Nicolas_OSDEV Mar 24 '26
Exato
2
u/themagicalfire Mar 24 '26
So that means a C compiled program may be abused just by guessing the variables that are automatically created for showing texts?
5
2
u/Large-Assignment9320 Mar 25 '26
Why do write to stdout fileno, when you can just do printf? And also why call exit(0) when you can just return?
section .rodata
msg: db "Hello, World!", 10, 0
section .text
global main
extern printf
main:
push rbp
mov rbp, rsp
lea rdi, [rel msg]
call printf
pop rbp
ret1
1
u/FerriitMurderDrones Mar 27 '26
Because that links with the entire libc library, which blows the filesize from ~8kB to ~16kB
1
u/Large-Assignment9320 Mar 27 '26
Hmm, is true. And in todays memory saving era, I recommend just printing hello.
1
1
u/Difficult-Celery-721 May 09 '26
Well this example seems to be attempting to teach linux system calls, which is usually part of os classes in universities.
1
60
u/dark_lord_of_balls Mar 24 '26
ah yes the TRUE and only good language because it takes less lines for the same result.
20
u/ZookeepergameFew6406 Mar 24 '26
Less visible lines. Your CPU is dying for that hello world 😂
0
Mar 24 '26
[deleted]
2
u/jsrobson10 Mar 26 '26
in this example yes, but there's many cases where the CPU is the bottleneck. like, wanna make a simulation of some kind? python will limit you.
0
Mar 26 '26
[deleted]
1
u/jsrobson10 Mar 26 '26
but even with proper libraries (that do the bulk of the work for you), the performance still won't be as good as a solution in a compiled language.
0
Mar 27 '26
[deleted]
1
u/Only_Information7895 Mar 28 '26
I mean rarely, but in embedded compiled languages are the norm.
Most don't bother using assembly, instead just use C (regular old C). Even in work we were fighting to optimize 80 bytes (not megabytes, just bytes).
For example in my project I had a bug because my code took 1 CPU clock cycle longer and the whole thing crashed. A whole 1 instruction more. Luckily I was just dumb and could optimize it, but it was annoying to see.
1
u/ZookeepergameFew6406 Mar 27 '26
I’ve compared a Spring app (java) we do vs do not use an entity mapper (JPA iirc), and the performance difference is relevant if you’re talking about squeezing out as much juice as you want. Naturally this comes at the cost of losing flexibility, but thats usually the tradeoff. Was worthwhile for my usecase to do the mapling ourselves
1
1
32
u/roverfromxp Mar 24 '26
did they fucking ai upscale gigachad????
ABSOLUTLEY SACRILEGE
13
u/jirik-656 Mar 24 '26
I think they vibe coded entier meme
6
u/roverfromxp Mar 24 '26
i swear to god have we regressed so far as a species that COPY AND PASTING IMAGES INTO A GRAPHICS PROGRAM is unnecessary, tedious work ripe for automation: the cold embrace of the machine??????
how uncreative do you have to be?? i am not a creative person myself, the fact that i recognise that puts me at probably the bottom decile of the world population, and this is still unthinkable!
2
3
2
8
u/VoidJuiceConcentrate Mar 24 '26
Programming languages making bread:
Python: you bought a pre-made bead kit from the store, just add water
C/C++: you got bread flour, eggs, and yeast at the store.
ASM: you have a field of wheat, chickens, and a generational sourdough starter.
1
u/WaltzIndependent5436 Mar 24 '26
Where does vibing with my bro Claude sit?
2
u/VoidJuiceConcentrate Mar 24 '26
You gave a 9 year old the recipie and you're gonna call whatever's made afterwards "bread"
4
u/itscopperon Mar 24 '26
I think a better comparison is telling a 9 year old to make bread using a pile of shredded cooking books that they need to piece together to craft a recipe with.
2
u/Livro404 Mar 25 '26
I think a good comparison could also be asking your local baker to make one. They will be the ones making, not you.
3
u/itscopperon Mar 25 '26
Eh, to a degree that works, but a baker took the time to practice and refine their skills enough that they made it their career. An AI just mimics the info in its data set without any real experience.
1
4
u/teactopus Mar 24 '26
assembly programmers in shambles
4
1
u/Dizzy_Database_119 Mar 24 '26
It's crazy how even though this looks so raw, the assembler parsing this still has to do so much extra to make it executable machine code
2
2
2
1
u/Raferat Mar 24 '26
I see problems with your Assembly implementation. "Helllo world\0" with three 'l's and terminated with \0 instead of newline, really? Does no one read what the AI generates?
1
1
1
u/MARio23038 Mar 25 '26
#hehehe
LDM R0 M$[*strbuff]
LDM R1 M$[strlen]
LDM R2 M$[*ConsoleBuff]
ADD R3 R0 R1
@loop STJ @exit
JMP [EQ] R0 R3
STM R0 M$[R2]
ADD R2 R2 $1
ADD R0 R0 $1
STJ @loop
JMP [LTEQGT] $0 $0
@exit RET1
1
1
1
1
1
u/Dazzling_Cabinet_780 Mar 28 '26
Wouldn't it be something like(for MIPS, that is the assembly I know) :
.data
Hello_world: .asciiz "Hello_world"
.text
.globl main
main:
la $a0, Hello_world
li $v0, 8 # syscall for printing string
syscall
li $v0,10 #ending program
syscall1
u/Haoshokoken Mar 28 '26 edited Mar 28 '26
The assembly lines resulting from this Python code are longer than Wikipedia, and it consumes more CPU ticks and RAM than the Saturn V required to go to the Moon and back.
1
u/QuackQuackImTheDuck Mar 28 '26
Why would you use python if you could just yell "hello world" instead ?
0
u/Nicolas_OSDEV Mar 24 '26
Lembrando que isso é só um meme leve sobre a abstração das duas linguagens nada demais
1


58
u/rover_G Mar 24 '26
Assembly is just a wrapper around the CPU