-
Notifications
You must be signed in to change notification settings - Fork 0
/
chap3ex2b.s
43 lines (35 loc) · 1 KB
/
chap3ex2b.s
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
41
42
43
# PURPOSE: MODIFIED TO TERMINATED BY 255
#
# VARIABLES:
#
# register:
# %edi -> current position in the list
# %ebx -> current highest values
# %eax -> current element from the list
#
# memory:
# data_items -> list of numbers, terminated by a 255
.section .data
data_items:
.long 3,67,34,222,45,75,34,22,11,66,255
.section .text
.globl _start
_start:
movl $0, %edi # move 0 into index register
movl data_items(,%edi,4), %eax # load the first byte of data
movl %eax, %ebx # the first item is the highest so far
start_loop:
cmpl $255, %eax # end of list?
je loop_exit
incl %edi # increment index
movl data_items(,%edi,4), %eax # load next value
cmpl %ebx, %eax # compare values
jle start_loop # if new value is less than current max
cmpl $255, %eax # end of list?
je loop_exit
movl %eax, %ebx # move value as new largest to %ebx
jmp start_loop
loop_exit:
movl $1, %eax # exit system call
# %ebx now has max val as return code
int $0x80