Move History

Fork Selected
  • Description

    The original code used 32-bit system call. I refactored the code to use 64-bit system call.

    Code
    global say_hello
    section .text
    say_hello:
      mov rax, 1 ; system call for write (for Linux 64)
      mov rdi, 1 ; file handle 1 is STDOUT
      lea rsi, [rel message] ; memory address of output buffer
      mov rdx, msgLen ; size of output buffer in bytes
      syscall ; invoke OS to do the write
      ret ; Return to the caller
    
    section .data ; Read-only data
    message db "Hello World!", 10 ; message = "Hello World!\n"
    msgLen equ $-message ; msgLen = strlen(message)
    Test Cases
    #include <criterion/criterion.h>
    
    void say_hello();
    
    Test(say_hello, should_print_hello_world) {
      say_hello();
      cr_assert(1);
    }
  • Code
    • global say_hello
    • section .text
    • say_hello:
    • mov eax, 4 ; system call for write (for Linux)
    • mov ebx, 1 ; file handle 1 is STDOUT
    • mov ecx, message ; memory address of output buffer
    • mov edx, msgLen ; size of output buffer in bytes
    • int 0x80 ; invoke OS to do the write
    • mov rax, 1 ; system call for write (for Linux 64)
    • mov rdi, 1 ; file handle 1 is STDOUT
    • lea rsi, [rel message] ; memory address of output buffer
    • mov rdx, msgLen ; size of output buffer in bytes
    • syscall ; invoke OS to do the write
    • ret ; Return to the caller
    • section .data ; Read-only data
    • message db "Hello World!", 10 ; message = "Hello World!\n"
    • msgLen equ $-message ; msgLen = strlen(message)