From: Dylan Lloyd Date: Sun, 14 Oct 2012 20:36:02 +0000 (-0400) Subject: added 64bit equivalent X-Git-Url: https://disinclined.org/git/?a=commitdiff_plain;h=a39d4ce01d07032e98a128c9f9df72a3fdd23972;p=nasm.git added 64bit equivalent --- diff --git a/hello.asm b/hello.asm deleted file mode 100644 index 7e5d8c1..0000000 --- a/hello.asm +++ /dev/null @@ -1,27 +0,0 @@ -section .data - hello: db 'Hello, world.',10 ; declare initialized string with linefeed char - helloLen: equ $-hello ; declare and init. constant - done: db 0 - -section .text - global _start - -_start: - movzx eax, byte [done] ; Pad value of done to one byte and put in eax - cmp eax,1 ; Compare eax with 1 - jg myFirstASMLabel ; Jump if greater than to myFirstASMLabel - - mov byte [done], 1 - - mov eax,4 ; Put magic # for system call sys_write into eax - mov ebx,1 ; Prepare arg 1 of sys_write, 1 - file descriptor of stdo - mov ecx,hello ; Prepare arg 2, reference to string hello - mov edx,helloLen ; Prepare arg 3, string length, no deref. b/c constant - int 80h ; Call the kernel -; - -myFirstASMLabel: - mov eax,1 ; The system call for exit (sys_exit) - mov ebx,0 ; Exit with return code of 0 (no error) - int 80h - diff --git a/hello32.asm b/hello32.asm new file mode 100644 index 0000000..b6178a0 --- /dev/null +++ b/hello32.asm @@ -0,0 +1,27 @@ +section .data + hello: db 'Hello, world.',10 ; declare initialized string with linefeed char + helloLen: equ $-hello ; declare and init. constant + done: db 0 + +section .text + global _start + +_start: + movzx eax, byte [done] ; Pad value of done to one byte and put in eax + cmp eax,1 ; Compare eax with 1 + jg myFirstASMLabel ; Jump if greater than to myFirstASMLabel + + mov byte [done], 1 + + mov eax,4 ; Put magic # for system call sys_write into eax + mov ebx,1 ; Prepare arg 1 of sys_write, 1 - file descriptor of stdo + mov ecx,hello ; Prepare arg 2, reference to string hello + mov edx,helloLen ; Prepare arg 3, string length, no deref. b/c constant + int 80h ; Call the kernel +; + +myFirstASMLabel: + mov eax,1 ; The system call for exit (sys_exit) + mov ebx,0 ; Exit with return code of 0 (no error) + int 80h + diff --git a/hello64.asm b/hello64.asm new file mode 100644 index 0000000..32296f5 --- /dev/null +++ b/hello64.asm @@ -0,0 +1,27 @@ +section .data + hello: db 'Hello, world.',10 ; declare initialized string with linefeed char + helloLen: equ $-hello ; declare and init. constant + done: db 0 + +section .text + global _start + +_start: + movzx rax, byte [done] ; Pad value of done to one byte and put in rax + cmp rax,1 ; Compare rax with 1 + jg myFirstASMLabel ; Jump if greater than to myFirstASMLabel + + mov byte [done], 1 + + mov rax,1 ; Put magic # for system call sys_write into rax + mov rdi,1 ; Prepare arg 1 of sys_write, 1 - file descriptor of stdo + mov rsi,hello ; Prepare arg 2, reference to string hello + mov rdx,helloLen ; Prepare arg 3, string length, no deref. b/c constant + syscall ; Call the kernel +; + +myFirstASMLabel: + mov rax,60 ; The system call for exit (sys_exit) + mov rdi,0 ; Exit with return code of 0 (no error) + syscall +