-
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 void say_hello(); Test(say_hello, should_print_hello_world) { say_hello(); cr_assert(1); }
Output:
-
Code - global say_hello
- section .text
- say_hello:
mov eax, 4 ; system call for write (for Linux)mov ebx, 1 ; file handle 1 is STDOUTmov ecx, message ; memory address of output buffermov edx, msgLen ; size of output buffer in bytesint 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)
This comment has been reported as {{ abuseKindText }}.
Show
This comment has been hidden. You can view it now .
This comment can not be viewed.
- |
- Reply
- Edit
- View Solution
- Expand 1 Reply Expand {{ comments?.length }} replies
- Collapse
- Remove
- Remove comment & replies
- Report
{{ fetchSolutionsError }}
Please sign in or sign up to leave a comment.