assembly-playground/x86/minimum/minimum.asm

33 lines
953 B
NASM
Raw Normal View History

2024-06-11 13:42:37 +07:00
# FIND SMALLEST NUMBER
# edi = index of data_items
# ebx = smallest item found
# eax = current item
.global _start
.intel_syntax noprefix
.section .text
_start:
mov edi, 0 # move 0 to edi (first index)
mov eax, [data_items + edi * 4] # move first number to eax
mov ebx, eax # move eax to ebx
start_loop:
cmp eax, 255 # compare eax to 0
je loop_exit # if eax == 0, jump to loop_exit
inc edi # increment edi by 1
mov eax, [data_items + edi * 4] # move next number to eax
cmp eax, ebx # compare smallest item (ebx) to current item (eax)
jge start_loop # if ebx is greater than eax, jump to start loop
mov ebx, eax # move eax to ebx
jmp start_loop # jump back to start_loop
loop_exit:
mov eax, 1 # move 1 to eax (syscall number)
int 0x80 # kernel interrupt
.section .data
data_items: .long 3, 67, 34, 222, 45, 75, 54, 34, 44, 33, 22, 11, 66, 255