-
Notifications
You must be signed in to change notification settings - Fork 68
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
brianrhall
committed
Aug 15, 2019
1 parent
2474967
commit 22d7d22
Showing
14 changed files
with
202 additions
and
0 deletions.
There are no files selected for viewing
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
# Console Output | ||
# Materials - GAS, Clang/LLVM on Linux (64-bit) | ||
# Copyright (c) 2019 Hall & Slonka | ||
|
||
# Uses system call information from Chapter 10 | ||
|
||
.data | ||
s1: .ascii "Hello Universe\n\0" | ||
lenS1: .long (. - s1) | ||
|
||
.text | ||
.global _main | ||
_main: | ||
|
||
print: | ||
movq $0x2000004, %rax # system write (4) | ||
movq $1, %rdi # file handle STDOUT (1) | ||
leaq s1(%rip), %rsi # address | ||
movq lenS1(%rip), %rdx # length | ||
syscall | ||
|
||
done: | ||
movq $60, %rax | ||
xorq %rdi, %rdi | ||
syscall | ||
.end |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
# Console Output | ||
# Materials - GAS, Clang/LLVM on macOS (64-bit) | ||
# Copyright (c) 2019 Hall & Slonka | ||
|
||
# Uses system call information from Chapter 10 | ||
|
||
.data | ||
s1: .ascii "Hello Universe\n\0" | ||
lenS1: .long (. - s1) | ||
|
||
.text | ||
.global _main | ||
_main: | ||
|
||
print: | ||
movq $0x2000004, %rax # system write (4) | ||
movq $1, %rdi # file handle STDOUT (1) | ||
leaq s1(%rip), %rsi # address | ||
movq lenS1(%rip), %rdx # length | ||
syscall | ||
|
||
done: | ||
movq $0x2000001, %rax | ||
xorq %rdi, %rdi | ||
syscall | ||
.end |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
; Console Output | ||
; Materials - MASM (64-bit) | ||
; Copyright (c) 2019 Hall & Slonka | ||
|
||
; Solution must use system call information from Chapter 10 | ||
; Use the CONSOLE subsystem (in project properties) | ||
; Build, then run in a console window | ||
|
||
extrn GetStdHandle : proc | ||
extrn WriteConsoleA : proc | ||
extrn ExitProcess : proc | ||
|
||
.data | ||
bytesWritten QWORD 0 ; for WriteConsoleA | ||
stdHandle QWORD 0 ; for WriteConsoleA | ||
s1 BYTE "Hello Universe", 13, 10, 0 | ||
lenS1 = ($ - s1) | ||
|
||
.code | ||
_main PROC | ||
|
||
sub rsp, 10h ; reserve for return and rbp | ||
sub rsp, 8h ; reserve for parameters | ||
sub rsp, 20h ; reserve shadow space for regs | ||
|
||
print: | ||
; get STDOUT handle | ||
mov rcx, -11 ; request STD_OUTPUT_HANDLE (-11) | ||
call GetStdHandle ; call WinAPI to get console handle | ||
mov stdHandle, rax ; save stdHandle | ||
|
||
mov rcx, stdHandle ; STD_OUPUT_HANDLE | ||
mov rdx, OFFSET s1 ; string address | ||
mov r8, lenS1 ; bytes to write | ||
mov r9, OFFSET bytesWritten ; bytes written | ||
push 0 ; reserved, push NULL | ||
call WriteConsoleA ; call win api to write text to console | ||
|
||
add rsp, 38h ; clean up stack | ||
|
||
done: | ||
xor rcx, rcx | ||
call ExitProcess | ||
_main ENDP | ||
|
||
END |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
; Console Output | ||
; Materials - NASM (64-bit) | ||
; Copyright (c) 2019 Hall & Slonka | ||
|
||
; Uses system call information from Chapter 10 | ||
|
||
SECTION .data | ||
s1: DB "Hello Universe", 10, 0 | ||
lenS1: DQ ($ - s1) | ||
|
||
SECTION .text | ||
global _main | ||
_main: | ||
|
||
print: mov rax, 1 ; system write (1) | ||
mov rdi, 1 ; file handle STDOUT (1) | ||
lea rsi, [rel s1] ; address | ||
mov rdx, [lenS1] ; length | ||
syscall | ||
|
||
done: | ||
mov rax, 60 | ||
xor rdi, rdi | ||
syscall |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
# GDB and LLDB | ||
# Materials - GAS, Clang/LLVM on Linux (64-bit) | ||
# Copyright (c) 2019 Hall & Slonka | ||
|
||
.data | ||
s1: .ascii "Hello Universe\n\0" | ||
lenS1: .long (. - s1) | ||
nums: .long 2, 4, 6, 8, 10, 12 | ||
lenNums: .long (. - nums) | ||
floats: .float 1.2, 3.4, 5.6, 7.8 | ||
lenFloats: .long (. - floats) | ||
value: .long 22 | ||
|
||
.text | ||
.global _main | ||
_main: | ||
|
||
leaq s1(%rip), %rax | ||
leaq nums(%rip), %rax | ||
leaq floats(%rip), %rax | ||
movups floats(%rip), %xmm0 | ||
|
||
done: | ||
movq $60, %rax | ||
xorq %rdi, %rdi | ||
syscall | ||
.end |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
# GDB and LLDB | ||
# Materials - GAS, Clang/LLVM on macOS (64-bit) | ||
# Copyright (c) 2019 Hall & Slonka | ||
|
||
.data | ||
s1: .ascii "Hello Universe\n\0" | ||
lenS1: .long (. - s1) | ||
nums: .long 2, 4, 6, 8, 10, 12 | ||
lenNums: .long (. - nums) | ||
floats: .float 1.2, 3.4, 5.6, 7.8 | ||
lenFloats: .long (. - floats) | ||
value: .long 22 | ||
|
||
.text | ||
.global _main | ||
_main: | ||
|
||
leaq s1(%rip), %rax | ||
leaq nums(%rip), %rax | ||
leaq floats(%rip), %rax | ||
movups floats(%rip), %xmm0 | ||
|
||
done: | ||
movq $0x2000001, %rax | ||
xorq %rdi, %rdi | ||
syscall | ||
.end |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
; GDB and LLDB | ||
; Materials - NASM (64-bit) | ||
; Copyright (c) 2019 Hall & Slonka | ||
|
||
SECTION .data | ||
s1: DB "Hello Universe", 10, 0 | ||
lenS1: EQU ($ - s1) | ||
nums: DD 2, 4, 6, 8, 10, 12 | ||
lenNums: EQU ($ - nums) | ||
floats: DD 1.2, 3.4, 5.6, 7.8 | ||
lenFloats: DQ ($ - floats) | ||
value: DD 22 | ||
|
||
SECTION .text | ||
global _main | ||
_main: | ||
|
||
lea rax, s1 | ||
lea rax, nums | ||
lea rax, floats | ||
movups xmm0, [rel floats] | ||
|
||
done: | ||
mov rax, 60 | ||
xor rdi, rdi | ||
syscall |