2018-04-30 16:09:48 +00:00
|
|
|
;; Hello World Program #2
|
2018-04-26 02:40:23 +00:00
|
|
|
;; Compile with: nasm -f elf hello.s
|
2018-04-25 14:56:08 +00:00
|
|
|
;; Link with: ld -m elf_i386 -o hello hello.o
|
|
|
|
;; Run with: ./hello
|
|
|
|
|
2018-04-30 16:09:48 +00:00
|
|
|
;; The following includes are derived from:
|
2018-04-25 15:41:35 +00:00
|
|
|
;; sys/unistd_32.h
|
2018-04-25 14:56:08 +00:00
|
|
|
%define SYS_write 4
|
|
|
|
%define SYS_exit 1
|
|
|
|
|
2018-04-30 16:09:48 +00:00
|
|
|
;; The following includes are derived from:
|
2018-04-25 14:56:08 +00:00
|
|
|
;; unistd.h
|
|
|
|
%define STDOUT 1
|
|
|
|
|
2018-04-30 16:09:48 +00:00
|
|
|
;;; 'global' is the directive that tells the NASM the address of the
|
|
|
|
;;; first instruction to run.
|
|
|
|
|
|
|
|
global _start
|
|
|
|
|
2018-04-25 14:56:08 +00:00
|
|
|
section .data
|
|
|
|
msg db "Hello You Beautiful Human", 0Ah
|
2018-04-30 16:09:48 +00:00
|
|
|
len equ $-msg ; The $ is a NASM helper that means
|
|
|
|
; "The address of the current
|
|
|
|
; instruction. 'equ' is a NASM
|
|
|
|
; macro that performs the math and
|
|
|
|
; places in the 'len' constant the
|
|
|
|
; difference between the start of the
|
|
|
|
; current instruction and the 'msg'.
|
2018-04-26 02:40:23 +00:00
|
|
|
|
2018-04-25 14:56:08 +00:00
|
|
|
section .text
|
|
|
|
_start:
|
2018-04-30 16:09:48 +00:00
|
|
|
mov edx, len ; Mov the address of 'len' to register EDX
|
|
|
|
mov ecx, msg ; Mov the address of the message (not the content)
|
2018-04-25 14:56:08 +00:00
|
|
|
mov ebx, STDOUT ; using STDOUT (see definition above)
|
2018-04-30 16:09:48 +00:00
|
|
|
mov eax, SYS_write ; Acesss WRITE in 32-bit Linux
|
|
|
|
int 80h ; Call the kernel to run the WRITE command.
|
|
|
|
|
|
|
|
;; Note that it's always register AX that we use to tell the kernel
|
|
|
|
;; what we want it to do. Depending on the kernel instruction, other
|
|
|
|
;; registers may be used to fill out the command.
|
2018-04-25 14:56:08 +00:00
|
|
|
|
2018-04-30 16:09:48 +00:00
|
|
|
mov ebx, 0 ; Mov '0' to be our exit code
|
|
|
|
mov eax, SYS_exit ; Access EXIT
|
|
|
|
int 80h ; Call the kernel to run the EXIT command.
|
2018-04-25 14:56:08 +00:00
|
|
|
|
|
|
|
|