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/CHAP3/exit.s | 23 ++++++++++++++++++ PGU/CHAP3/max_value.s | 65 +++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 88 insertions(+) create mode 100644 PGU/CHAP3/exit.s create mode 100644 PGU/CHAP3/max_value.s (limited to 'PGU/CHAP3') diff --git a/PGU/CHAP3/exit.s b/PGU/CHAP3/exit.s new file mode 100644 index 0000000..df2addb --- /dev/null +++ b/PGU/CHAP3/exit.s @@ -0,0 +1,23 @@ +# Program does not but exit() call with a status code +# returned to kernel + +# No inputs or outputs + +# Variables +# +# %rax - holds syscall number +# %rdi - holds return status + +.section .data +#No data + +.section .text +.globl _start + +_start: +movq $60, %rax # %rax used to hold syscall numbers + # 60 is exit() syscall + +movq $245, %rdi # Exit status (BYTE MAX) + +syscall diff --git a/PGU/CHAP3/max_value.s b/PGU/CHAP3/max_value.s new file mode 100644 index 0000000..7025b05 --- /dev/null +++ b/PGU/CHAP3/max_value.s @@ -0,0 +1,65 @@ +# Find the maximum value inside a static list + +# Variables used: +# +# - %r11 - Holds index of the data item being examined +# - %rdi - Largest data item found so far +# - %rax - Current data item +# +# +# Constant memory locations: +# +# data_items - contains the item data. (Marks the beginning actualy) +# So far, 0 is used as terminator +# +# This program is written for x86_64 processors, it won't assemble in x86 + +.section .data # Specify data section + + +# Array of data items. This use 8bytes (quad-word) for each location +data_items: +.quad 133,55,50,12,25,77,30,93,222,55,62,250,66,34,69,0 + + +.section .text + +# Mark program's starting point so Linux can 'see' it +.globl _start + +_start: +movq $0, %r11 # Move 0 into %rdi to indicate + # the start of the index + +movq data_items(,%r11,8), %rax # Load the first data item (8bytes long) + # This actually uses indexed access + # mode, where %rdi is the 'offset' into + # the data_items array, and 8 is the + # multiplier. + +movq %rax, %rbx # This is the first item, so, %rax is + # current the biggest anyway + + +# Loop over all items +start_loop: + cmpq $0, %rax # compare current item with the + je loop_exit # terminator 0, and jump to exit + # if it is equal. + + incq %r11 # Increment index so we can grab next + # item + + movq data_items(,%r11,8), %rax # Grab next item once we incremented the + # index above + + cmpq %rbx, %rax # If our current item in %rax is smaller + jle start_loop # we ignore it and move back to the loop + + movq %rax, %rdi # Otherwise we store it as our new largest + jmp start_loop # item and jump back to the loop unconditionally + +loop_exit: + movq $60, %rax # Call exit() syscall, our argument is + # already in %rdi, just setup syscall + syscall # number and call kernel -- cgit v1.2.3