summaryrefslogtreecommitdiff
path: root/PGU/OLD/chapter3/min.s
blob: 9179be7fc445b38bc98087a62b9affce11fd161d (plain)
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
44
45
46
47
48
49
50
51
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