4
luxe011
4y

```
section .text
global _start ;must be declared for linker (ld)

_start: ;tells linker entry point
mov edx,len ;message length
mov ecx,msg ;message to write
mov ebx,1 ;file descriptor (stdout)
mov eax,4 ;system call number (sys_write)
int 0x80 ;call kernel

mov eax,1 ;system call number (sys_exit)
int 0x80 ;call kernel

section .data
msg db 'Hello, world!', 0xa ;string to be printed
len equ $ - msg ;length of the string
```

I've never seen such a terrible way to print "hello world"

Comments
  • 6
    Looks straightforward, what's terrible about it?
    It's equivalent to the c code

    #include <unistd.h>

    int main() {
    write(1, "Hello, world!", 14);
    exit();
    }
  • 6
    Must I remind you that this is faster than both Java and Python?!
  • 3
    Nobody:
    Assembler People: I am speed
  • 3
    How and why is this terrible?
  • 0
    @Hazarth who the hell needs a faster way to print hello world
  • 1
    @Root I'm used to Julia and Java which take only one line so learning assembly it killing me
  • 3
    that’s how assembly is. It’s the nature of the language to take more steps. What’s simple and mindless to do in high level languages is more complicated in assembly bc you’re getting more control over the hardware. There’s nothing terrible about that code bc it’s probably the best way to print hello world with what you have. Assembly is still widely used in certain programs that need to touch the guts.
  • 1
    @luxe011 +1 for taking the time to have a look at under the hood 🙂 we can't know everything in detail, but in times of Super complex frameworks on top of each other, I think it's worth to get at least an idea of most layers
Add Comment