Skip to content

Commit

Permalink
thello.s: update & fix comments, etc.
Browse files Browse the repository at this point in the history
- add attribution (mostly stolen from https://polprog.net/blog/netbsdasmprog/)
- replace syscall args comment with the actual one from syscall.c
- rename $hello to $hello_str

(in response to first part of issue #2)
  • Loading branch information
robohack committed May 18, 2021
1 parent 430b5ea commit 6467e85
Showing 1 changed file with 18 additions and 7 deletions.
25 changes: 18 additions & 7 deletions thello.s
Original file line number Diff line number Diff line change
@@ -1,29 +1,40 @@
# SYSCALL ARGS
# rdi rsi rdx rcx r8 r9

#
# thello.s: "Hello world!" in x86_64 assembly language
#
# this example was mostly stolen from: https://polprog.net/blog/netbsdasmprog/
#
.section .text

.globl _start

_start:
andq $-16, %rsp # clear the 4 least significant bits of stack pointer to align it

# from src/sys/arch/x86/x86/syscall.c:
# ifdef __x86_64__
# /*
# * The first 6 syscall args are passed in rdi, rsi, rdx, r10, r8 and r9
# * (rcx gets copied to r10 in the libc stub because the syscall
# * instruction overwrites %cx) and are together in the trap frame
# * with space following for 4 more entries.
# */
#
mov $4, %rax # SYS_write
mov $1, %rdi
mov $hello, %rsi
mov $hello_str, %rsi
mov hello_len, %dl # Note: does not clear upper bytes. Use movzxb (move zero extend) for that
syscall

mov $1, %rax # SYS_exit
xor %rdi, %rdi
syscall

.section .data
.section .data

hello:
hello_str:
.ascii "Hello world!\n"
hello_len:
.byte . - hello
.byte . - hello_str

#
# Local Variables:
Expand Down

0 comments on commit 6467e85

Please sign in to comment.