summaryrefslogtreecommitdiff
path: root/PGU/OLD/chapter3/max.s
diff options
context:
space:
mode:
authorCarlos Maiolino <[email protected]>2025-07-10 22:55:07 +0200
committerCarlos Maiolino <[email protected]>2025-07-10 22:56:55 +0200
commitd98f46ce647846b0aa30b2e16a30fd4e152a1bf5 (patch)
tree267474fcc77cf20b428f6f4c7f768ca09f4cfe0e /PGU/OLD/chapter3/max.s
parent869e68986aa8f69af6e7842260a68d1e5c6f796f (diff)
Add new code
Signed-off-by: Carlos Maiolino <[email protected]>
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