-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmaximum.s
More file actions
40 lines (33 loc) · 1.16 KB
/
maximum.s
File metadata and controls
40 lines (33 loc) · 1.16 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# PURPOSE: Find the maximum number in a set of numbers
# VARIABLES:
#
# Registers:
#
# %edi - Index of current item
# %ebx - Largest item
# %eax - Current item
#
# Memory locations:
#
# data_items - The set of numbers, 0 terminates the data
.section .data
data_items:
.long 3, 67, 34, 222, 45, 75, 54, 34, 44, 33, 22, 11, 66, 0
.section .text
.global _start
_start:
movl $0, %edi # Move 0 into the index register
movl data_items(,%edi,4), %eax # Load the first byte of data
movl %eax, %ebx # The first item (%eax) is the biggest
start_loop:
cmpl $0, %eax # Check if the loop is finished (current item will be equal to 0)
je loop_exit
incl %edi
movl data_items(,%edi,4), %eax # Load the next value
cmpl %ebx, %eax # Compare greatest and current
jle start_loop # Go to the loop beginning if the new number is smaller
movl %eax, %ebx # Move the current value into the largest value
jmp start_loop # Go to the loop beginning
loop_exit:
movl $1, %eax # exit() syscall, %ebx is status code and has the largest number
int $0x80