Contact
CoCalc Logo Icon
StoreFeaturesDocsShareSupport News AboutSign UpSign In
| Download

Example of using NASM Netwide Assembler online via https://cocalc.com.

Project: public
Path: nasm / hello.asm
Views: 65
License: OTHER
Image: ubuntu2004
1
; ----------------------------------------------------------------------------------------
2
;
3
; From https://cs.lmu.edu/~ray/notes/nasmtutorial/
4
;
5
; Writes "Hello, World" to the console using only system calls. Runs on 64-bit Linux only.
6
; To assemble and run:
7
;
8
; nasm -felf64 hello.asm && ld hello.o && ./a.out
9
; ----------------------------------------------------------------------------------------
10
11
global _start
12
13
section .text
14
_start: mov rax, 1 ; system call for write
15
mov rdi, 1 ; file handle 1 is stdout
16
mov rsi, message ; address of string to output
17
mov rdx, 13 ; number of bytes
18
syscall ; invoke operating system to do the write
19
mov rax, 60 ; system call for exit
20
xor rdi, rdi ; exit code 0
21
syscall ; invoke operating system to exit
22
23
section .data
24
message: db "Hello, World", 10 ; note the newline at the end
25
26