# Calculate Sum of numbers in MASM

Page 1 of 1

## 1 Replies - 2785 Views - Last Post: 11 February 2010 - 09:04 PM

### #1 Zerobu Reputation: 13
• Posts: 1,822
• Joined: 14-January 08

# Calculate Sum of numbers in MASM

Posted 14 July 2009 - 08:35 PM

Description: This snippet will calculate the sum of a list of positive integers. It uses C++ equivalent as comments.
```        .model  small
.stack  1024
.data
prompt          db      "Enter a list of positive integers (ending with -1)",0
answer_str      db      "The sum is ",0

number          dw      ?               ; int number, sum;
sum             dw      ?

.code
extern  inputn:far
extern  printn:far
extern  printc:far
extern  endl:far

.STARTUP			; void main () {
mov     sum,0                   ;   sum = 0;

mov     ax,offset prompt        ;   cout << "Enter a list of positive integers (ending with -1)";
call    printc

call    inputn                  ;   cin >> number;
mov     number,ax

while1:	cmp	number,0		;   while (number >= 0) {
jl	endwhile1

mov	ax,number		;     sum += number;

call	inputn			;     cin >> number;
mov	number,ax

jmp	while1			;   }
endwhile1:

mov     ax,offset answer_str	;   cout << "The sum is " << sum << endl;
call    printc
mov     ax,sum
call    printn
call    endl

.exit				; }
end
```

Is This A Good Question/Topic? 0

## Replies To: Calculate Sum of numbers in MASM

### #2 nadmike Reputation: 0
• Posts: 1
• Joined: 11-February 10

## Re: Calculate Sum of numbers in MASM

Posted 11 February 2010 - 09:04 PM

i'm just wondering where could I find the function call you have been using...

Page 1 of 1

 .related ul { list-style-type: circle; font-size: 12px; font-weight: bold; } .related li { margin-bottom: 5px; background-position: left 7px !important; margin-left: -35px; } .related h2 { font-size: 18px; font-weight: bold; } .related a { color: blue; }