-
Notifications
You must be signed in to change notification settings - Fork 16
Expand file tree
/
Copy pathinput_20_numbers_and_find_sum.asm
More file actions
67 lines (58 loc) · 927 Bytes
/
input_20_numbers_and_find_sum.asm
File metadata and controls
67 lines (58 loc) · 927 Bytes
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
64
65
66
67
; Write an assembly program that would input twenty numbers from the user and print
; sum, then the first number, then the 2nd number followed by 3rd number and so on.
segment .data
a: dq 2
b: dq 0
cnt: dq 0
fmt: dq "%lld ",10,0
fmt_in: dq "%lld", 0
fmt_out: dq "THE SUM IS: %lld", 10, 0
segment .bss
array resq 21
segment .text
global main
extern printf
extern scanf
main:
push RBP
mov RAX, 0
mov RCX, 0
mov RBX, 0
INPUT_ARRAY:
cmp RCX, 20
jz DONE
mov [cnt], RCX
mov RAX, 0
mov RDI, fmt_in
mov RSI, a
call scanf
mov RAX, [a]
mov RCX, [cnt]
mov [array+RCX*8], RAX
add RBX, [a]
inc RCX
jmp INPUT_ARRAY
DONE:
mov RAX, 0
mov RCX, 0
mov RDI, fmt_out
mov RSI, RBX
call printf
mov RAX, 0
mov RCX, 0
mov RBX, 0
PRINT_ARRAY:
cmp RCX, 20
jz END
mov RAX, [array+RCX*8]
inc RCX
mov [cnt], RCX
mov RDI, fmt
mov RSI, RAX
call printf
mov RCX, [cnt]
jmp PRINT_ARRAY
END:
mov RAX, 0
pop RBP
ret