diff options
| author | Carlos Maiolino <[email protected]> | 2025-07-10 22:55:07 +0200 |
|---|---|---|
| committer | Carlos Maiolino <[email protected]> | 2025-07-10 22:56:55 +0200 |
| commit | d98f46ce647846b0aa30b2e16a30fd4e152a1bf5 (patch) | |
| tree | 267474fcc77cf20b428f6f4c7f768ca09f4cfe0e /PGU/OLD/chapter3/min.s | |
| parent | 869e68986aa8f69af6e7842260a68d1e5c6f796f (diff) | |
Add new code
Signed-off-by: Carlos Maiolino <[email protected]>
Diffstat (limited to 'PGU/OLD/chapter3/min.s')
| -rw-r--r-- | PGU/OLD/chapter3/min.s | 52 |
1 files changed, 52 insertions, 0 deletions
diff --git a/PGU/OLD/chapter3/min.s b/PGU/OLD/chapter3/min.s new file mode 100644 index 0000000..9179be7 --- /dev/null +++ b/PGU/OLD/chapter3/min.s @@ -0,0 +1,52 @@ +# This code has been originally copied from max.s + +# It has been modified to: +# - Find the smallest value, instead of the largest +# - Use Start/End addresses to delimit the boundaries of the number list +# +# %rax - holds the current element being examined +# %rbx - Holds the smallest number + +.section .data + +# This version has 2 labels, one to point to the start of the list, and another +# to point to the address right after it, so we can use it to search the list +# boundary. + +data_items: + .quad 234,10,9,230,66,77,23,66,101,69,100 +data_end: + +.section .text + +.globl _start + +_start: + +# Using immediate mode with a label, will give you the ADDRESS of the +# instruction/data it points to. Once the label itself contains an ADDRESS, the +# immediate mode will give you the ADDRESS itself. + +# Using direct mode with a label, will give you the DATA into the address the +# label points to. Once the label itself contains an address, the direct mode, +# as expected will give you the DATA into the address pointed by the label. + movq $data_items, %rax + cmpq $data_end, %rax # We need this check here in case + je exit_loop_empty # the items list is empty + movq (%rax), %rbx + + loop_start: + addq $8, %rax # We are using QuadWords, so 8 bytes + cmpq $data_end, %rax + je exit_loop + + cmpq (%rax), %rbx + jle loop_start + movq (%rax), %rbx + jmp loop_start + + exit_loop_empty: + movq $255, %rbx + exit_loop: + movq $1, %rax + int $0x80 |
