Quellcode durchsuchen

document what maximum.s does.

my first loop. in assembler. but please, someone explain those mnemonics
to me. movl = move long, move left? je = jump equal? jle = jump less
than or equal? probably.
Lucas Stadler vor 11 Jahren
Ursprung
Commit
a2198e05d4
1 geänderte Dateien mit 19 neuen und 5 gelöschten Zeilen
  1. 19 5
      pgu/01_arch/maximum.s

+ 19 - 5
pgu/01_arch/maximum.s

@ -1,29 +1,43 @@
1
.section .data
1
# maximum - calculates the maximum of a fixed list of numbers
2
#   returns the maximum via exit
2 3
4
.section .data
3 5
numbers:
4 6
	.long 3,67,34,222,65,45,75,54,34,44,33,22,11,66,0
5 7
6 8
.section .text
7 9
.globl _start
8 10
11
# %eax current number
12
# %ebx current maximum
13
# %edi current offset
14
9 15
_start:
10
	movl $0, %edi
11
	movl numbers(,%edi,4), %eax
12
	movl %eax, %ebx
16
	movl $0, %edi # initial offset is 0
17
	movl numbers(,%edi,4), %eax # load first number into %eax
18
	movl %eax, %ebx # first number is also first maximum
19
20
	# apparrently then the program just goes to the next thing? what
21
	# would be if we'd put loop_start and loop_end before _start?
13 22
14
loop_start:
23
loop_start: 
24
	# 0 marks the end of the numbers, finish if %eax == 0
15 25
	cmpl $0, %eax
16 26
	je loop_exit
17 27
28
	# load next number
18 29
	incl %edi
19 30
	movl numbers(,%edi,4), %eax
20 31
32
	# if the current number is smaller (or equal?), go back to loop_start
21 33
	cmpl %ebx, %eax
22 34
	jle loop_start
23 35
36
	# otherwise store the current number as the maximum number
24 37
	movl %eax, %ebx
25 38
	jmp loop_start
26 39
27 40
loop_exit:
41
	# exit. conveniently the maximum is already stored in %ebx
28 42
	movl $1, %eax
29 43
	int $0x80