forked from miguelmota/x86-assembly-examples
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsum_input_ints.asm
executable file
·97 lines (72 loc) · 1.58 KB
/
sum_input_ints.asm
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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
; Description: Asks for a number of integers
; and sums them up.
TITLE MASM Template (main.asm)
INCLUDE Irvine32.inc
.data
enterCountPrompt BYTE "How many integers will be added?: ",0
enterNumberPrompt BYTE "Enter a signed integer: ",0
sumMsg BYTE "The sum equals ",0
newline BYTE 0dh,0ah,0
ARRAY_SIZE = 20
numbers DWORD ARRAY_SIZE DUP(?)
count DWORD 0
sum DWORD 0
.code
main PROC
call Clrscr
Call GetIntegerCount
Call PromptForIntegers
Call CalcSum
Call DisplaySum
exit
main ENDP
GetIntegerCount PROC
mov edx, OFFSET enterCountPrompt
call WriteString
call ReadInt
mov count, eax
mov ecx, count
mov edx, OFFSET newline
call WriteString
GetIntegerCount ENDP
PromptForIntegers PROC
L1:
mov edx, OFFSET enterNumberPrompt
call WriteString
call ReadInt
mov numbers[ecx*4], eax
loop L1
PromptForIntegers ENDP
CalcSum PROC
mov eax, 0
mov ecx, count
L2:
add eax, numbers[ecx*4]
loop L2
mov sum, eax
CalcSum ENDP
DisplaySum PROC
mov edx, OFFSET newline
call WriteString
mov edx, OFFSET sumMsg
call WriteString
mov eax, sum
call WriteInt
mov edx, OFFSET newline
call WriteString
DisplaySum ENDP
END main
; =======================================
; OUTPUT
; =======================================
COMMENT !
How many integers will be added?: 5
Enter a signed integer: 2
Enter a signed integer: 4
Enter a signed integer: 6
Enter a signed integer: 3
Enter a signed integer: 9
The sum equals +24
Press any key to continue . . .
!
; =======================================