summaryrefslogtreecommitdiff
path: root/assignments/3/max_min.s
blob: abf66f7e1ff6241b41c1fb77ccb7bb79363d3dd1 (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
53
54
55
56
57
58
59
60
61
62
63
	.global _start

	.text
_start:
	movq $0, max  # initialize max to 0
	movq $0, min  # initialize min to 0

	# write(1, greeting, 16)
	mov     $1, %rax                # system call 1 is write
	mov     $1, %rdi                # file handle 1 is stdout
	mov     $greeting, %rsi         # address of variable to pring
	mov     $16, %rdx               # number of bytes to write
	syscall                         # invoke operating system to do the write

read_input:
	# read(0, input, 3)
	mov     $0, %rax                # system call 0 is read
	mov     $0, %rdi                # file handle 0 is stdin
	mov     $input, %rsi            # address of var to input
	mov     $4, %rdx                # number of bytes to read
	syscall                         # invoke operating system to do the write

print_results:
	# write(1, max_message, 4)
	mov     $1, %rax                # system call 1 is write
	mov     $1, %rdi                # file handle 1 is stdout
	mov     $max_message, %rsi      # address of string to output
	mov     $5, %rdx                # number of bytes to write
	syscall                         # invoke operating system to do the write

	# write(1, input, 4)
	mov     $1, %rax                # system call 1 is write
	mov     $1, %rdi                # file handle 1 is stdout
	mov     $input, %rsi            # address of string to output
	mov     $4, %rdx                # number of bytes read
	syscall                         # invoke operating system to do the write

	# write(1, min_message, 4)
	mov     $1, %rax                # system call 1 is write
	mov     $1, %rdi                # file handle 1 is stdout
	mov     $min_message, %rsi      # address of string to output
	mov     $5, %rdx                # number of bytes
	syscall                         # invoke operating system to do the write

	# write(1, input, 4)
	mov     $1, %rax                # system call 1 is write
	mov     $1, %rdi                # file handle 1 is stdout
	mov     $input, %rsi            # address of string to output
	mov     $4, %rdx                # number of bytes
	syscall                         # invoke operating system to do the write

	# exit(0)
	mov     $60, %rax               # system call 60 is exit
	xor     %rdi, %rdi              # we want return code 0
	syscall                         # invoke operating system to exit

	.data
greeting: .ascii  "Enter numbers: \n"
max_message: .ascii  "Max: "
min_message: .ascii  "Min: "
input:	.word 0
max: .word 0
min: .word 0