summaryrefslogtreecommitdiff
path: root/PGU/OLD/chapter3/max.s
diff options
context:
space:
mode:
Diffstat (limited to 'PGU/OLD/chapter3/max.s')
-rw-r--r--PGU/OLD/chapter3/max.s42
1 files changed, 42 insertions, 0 deletions
diff --git a/PGU/OLD/chapter3/max.s b/PGU/OLD/chapter3/max.s
new file mode 100644
index 0000000..6ebc906
--- /dev/null
+++ b/PGU/OLD/chapter3/max.s
@@ -0,0 +1,42 @@
+# Given a list of X numbers, find the maximum number of the list and use it as
+# the argument of exit() syscall
+
+# %rbx holds the maximum number through the whole scanning process
+# %rax holds the current element being examined
+# %rdi holds the currend position in the list
+# zero marks the end of the list
+
+# Data section, now containing some statically created data
+.section .data
+
+# Just a label to refer to the first item in the list
+data_items:
+ # "Type" of memory location to be reserved. In quotes because it just
+ # says how many bytes should be reserved to each item, not the 'type'
+ # itself
+ # Reserves 10 '8byte' (quad) slots consecutive in memory,
+ .quad 3,10,9,230,66,77,23,66,12,69,0
+
+.section .text
+
+.globl _start
+
+_start:
+ movq $0, %rdi
+ movq data_items(, %rdi,8), %rax
+ movq %rax, %rbx
+
+ start_loop:
+ cmpq $0, %rax
+ je loop_exit
+ incq %rdi
+ movq data_items(,%rdi,8), %rax
+ cmpq %rbx, %rax
+ jle start_loop
+ movq %rax, %rbx
+ jmp start_loop
+
+
+ loop_exit:
+ movq $1, %rax
+ int $0x80