Contact
CoCalc Logo Icon
StoreFeaturesDocsShareSupport News AboutSign UpSign In
| Download

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

Views: 212
License: OTHER
Image: ubuntu2004-dev
1
# ----------------------------------------------------------------------------------------
2
#
3
# From https://cs.lmu.edu/~ray/notes/gasexamples/
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
# gcc -c hello.s && ld hello.o && ./a.out
9
#
10
# ----------------------------------------------------------------------------------------
11
12
.global _start
13
14
.text
15
_start:
16
# write(1, message, 13)
17
mov $1, %rax # system call 1 is write
18
mov $1, %rdi # file handle 1 is stdout
19
mov $message, %rsi # address of string to output
20
mov $13, %rdx # number of bytes
21
syscall # invoke operating system to do the write
22
23
# exit(0)
24
mov $60, %rax # system call 60 is exit
25
xor %rdi, %rdi # we want return code 0
26
syscall # invoke operating system to exit
27
message:
28
.ascii "Hello, world\n"
29
30