How to resolve the algorithm Hello world/Newbie step by step in the X86-64 Assembly programming language

Published on 12 May 2024 09:40 PM

How to resolve the algorithm Hello world/Newbie step by step in the X86-64 Assembly programming language

Table of Contents

Problem Statement

Guide a new user of a language through the steps necessary to install the programming language and selection of a text editor if needed, to run the languages' example in the Hello world/Text task.

Let's start with the solution:

Step by Step solution about How to resolve the algorithm Hello world/Newbie step by step in the X86-64 Assembly programming language

Source code in the x86-64 programming language

option casemap:none
option literals:on

;; OS related crap
WIN64   equ 1
LIN64   equ 3

if @Platform eq WIN64
    option dllimport:
        ExitProcess proto uexit:dword 
    option dllimport:
        printf      proto fmt:qword, args:VARARG
    option dllimport:none
        exit        equ ExitProcess
    option dllimport:none 
        exit equ ExitProcess
elseif @Platform eq LIN64
    printf      proto SYSTEMV fmt:qword, args:VARARG
    exit        proto SYSTEMV ucode:dword
endif

.code
main proc
    invoke printf, CSTR("Hello, World!",13,10)
    invoke exit, 0
    ret
main endp
end


global main

extern printf
extern ExitProcess

section .data
msg     db "Hello, World!",0xa 

section .text
    main: 
        mov rcx, msg
        call printf
        mov rcx, 0
        call ExitProcess
        ret


extern printf
extern exit

section .rodata
msg   db "Goodbye, World!",10,0
section .text
   global main

   main:
      lea rdi, [rel msg]
      call [rel printf wrt ..got]
      pop rbp
      call [rel exit wrt ..got]
      ret


; ------------------------------------------------------------------------------
; To assemble:
;     nasm -Wall -f elf64 -o hello.o hello.asm
;     ld -o hello hello.o
; ------------------------------------------------------------------------------

        global  _start

	section .data
message db      "Hello, World!", 10     ; newline at the end
length  equ     $ - message		; length of message

        section .text
_start:
        mov     rsi, message    ; address of string to output
        mov     rdx, length     ; number of bytes
	mov	rax, 1		; system call 1 = write
	mov	rdi, 1		; stdout
	syscall

	;; exit program
        mov     rax, 60         ; system call 60 = exit
        xor     rdi, rdi        ; exit code 0
        syscall


  

You may also check:How to resolve the algorithm Sorting algorithms/Merge sort step by step in the Standard ML programming language
You may also check:How to resolve the algorithm Guess the number step by step in the Haskell programming language
You may also check:How to resolve the algorithm Barnsley fern step by step in the Emacs Lisp programming language
You may also check:How to resolve the algorithm Inheritance/Multiple step by step in the Fantom programming language
You may also check:How to resolve the algorithm Terminal control/Unicode output step by step in the Nemerle programming language