From d98f46ce647846b0aa30b2e16a30fd4e152a1bf5 Mon Sep 17 00:00:00 2001 From: Carlos Maiolino Date: Thu, 10 Jul 2025 22:55:07 +0200 Subject: Add new code Signed-off-by: Carlos Maiolino --- PGU/OLD/chapter3/max.s | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 PGU/OLD/chapter3/max.s (limited to 'PGU/OLD/chapter3/max.s') 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 -- cgit v1.2.3