summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormo khan <mo@mokhan.ca>2025-01-23 10:57:09 -0700
committermo khan <mo@mokhan.ca>2025-01-23 10:57:09 -0700
commit99c88ec429f73b614ece45b45ee482c8f9f8e059 (patch)
tree2d6b3c95e53d0505617070a71d00496f30c7c48b
parent7031e53d352b3b8cb7e9e403a48818ff585b6bc2 (diff)
learn assembly
-rw-r--r--assignments/3/.gitignore2
-rw-r--r--assignments/3/Makefile5
-rw-r--r--assignments/3/max_min.s17
3 files changed, 24 insertions, 0 deletions
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"