From 99c88ec429f73b614ece45b45ee482c8f9f8e059 Mon Sep 17 00:00:00 2001 From: mo khan Date: Thu, 23 Jan 2025 10:57:09 -0700 Subject: learn assembly --- assignments/3/.gitignore | 2 ++ assignments/3/Makefile | 5 +++++ assignments/3/max_min.s | 17 +++++++++++++++++ 3 files changed, 24 insertions(+) create mode 100644 assignments/3/.gitignore create mode 100644 assignments/3/max_min.s diff --git a/assignments/3/.gitignore b/assignments/3/.gitignore new file mode 100644 index 0000000..25a7384 --- /dev/null +++ b/assignments/3/.gitignore @@ -0,0 +1,2 @@ +*.o +*.exe diff --git a/assignments/3/Makefile b/assignments/3/Makefile index 8c3bc0c..75f6584 100644 --- a/assignments/3/Makefile +++ b/assignments/3/Makefile @@ -11,3 +11,8 @@ numbers.txt: run: main.exe numbers.txt ./main.exe < numbers.txt + +manual: max_min.s + as --64 -o max_min.o max_min.s + ld -o max_min.exe max_min.o + ./max_min.exe diff --git a/assignments/3/max_min.s b/assignments/3/max_min.s new file mode 100644 index 0000000..7e7895c --- /dev/null +++ b/assignments/3/max_min.s @@ -0,0 +1,17 @@ + .global _start + + .text +_start: + # write(1, message, 13) + mov $1, %rax # system call 1 is write + mov $1, %rdi # file handle 1 is stdout + mov $message, %rsi # address of string to output + mov $13, %rdx # number of bytes + syscall # invoke operating system to do the write + + # exit(0) + mov $60, %rax # system call 60 is exit + xor %rdi, %rdi # we want return code 0 + syscall # invoke operating system to exit +message: + .ascii "Hello, world\n" -- cgit v1.2.3