Просмотр исходного кода

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 лет назад: 11
Родитель
Сommit
a2198e05d4
1 измененных файлов с 19 добавлено и 5 удалено
  1. 19 5
      pgu/01_arch/maximum.s

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

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
numbers:
5
numbers:
4
	.long 3,67,34,222,65,45,75,54,34,44,33,22,11,66,0
6
	.long 3,67,34,222,65,45,75,54,34,44,33,22,11,66,0
5
7
6
.section .text
8
.section .text
7
.globl _start
9
.globl _start
8
10
11
# %eax current number
12
# %ebx current maximum
13
# %edi current offset
14
9
_start:
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
	cmpl $0, %eax
25
	cmpl $0, %eax
16
	je loop_exit
26
	je loop_exit
17
27
28
	# load next number
18
	incl %edi
29
	incl %edi
19
	movl numbers(,%edi,4), %eax
30
	movl numbers(,%edi,4), %eax
20
31
32
	# if the current number is smaller (or equal?), go back to loop_start
21
	cmpl %ebx, %eax
33
	cmpl %ebx, %eax
22
	jle loop_start
34
	jle loop_start
23
35
36
	# otherwise store the current number as the maximum number
24
	movl %eax, %ebx
37
	movl %eax, %ebx
25
	jmp loop_start
38
	jmp loop_start
26
39
27
loop_exit:
40
loop_exit:
41
	# exit. conveniently the maximum is already stored in %ebx
28
	movl $1, %eax
42
	movl $1, %eax
29
	int $0x80
43
	int $0x80