-
Notifications
You must be signed in to change notification settings - Fork 0
/
gasMos.s
38 lines (31 loc) · 1.02 KB
/
gasMos.s
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# Program 10.2
# Debug and System Write Interrupts - GAS, Clang/LLVM on macOS (32-bit)
# Copyright (c) 2017 Hall & Slonka
.data
output: .ascii "Computer Architecture\n"
.equ len, (. - output)
.text
.globl _main
_main: # Print "Computer Architecture"
int $3 # Set breakpoint (remove if desired)
pushl $len # String length
pushl $output # String address
pushl $1 # Print to STDOUT (File Descriptor 1, FD1)
pushl $0 # Extra push to align stack
movl $4, %eax # Use SYSCALL 4 (WRITE), prints to screen
int $0x80 # system call interrupt
addl $16, %esp # Clean up stack
pushl $len # BSD assumes that a function calls INT 80h
pushl $output # as opposed to issuing INT 80h directly
pushl $1 # Print using kernel call
movl $4, %eax
call _kernel
addl $12, %esp
pushl $0 # return value
subl $4, %esp # align stack
movl $1, %eax # call number for exit
int $0x80 # system call interrupt
_kernel: # For any system call
int $0x80
ret
.end