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

#1 Zerobu   User is offline

  • Black Hatter

Reputation: 13
  • View blog
  • 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;
	add	sum,ax

	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   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • 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...
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1