•
•
•
•
What is DaniWeb IT Discussion Community?
You're currently browsing the Assembly section within the Software Development category of DaniWeb, a massive community of 427,177 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 2,160 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our Assembly advertiser: Programming Forums
This is a program I wrote for my x86 assembly class which computes the sum of n numbers. It uses Irvine32.inc which came with the textbook.
Last edited : Aug 28th, 2006.
title Number Addition (add.asm) ; Dani Horowitz ; CSC111 x86 Assembly Programming ; This program adds integers a user inputs INCLUDE Irvine32.inc ;-------------------------------------------------- .stack ; begin stack segment ;-------------------------------------------------- .data ; begin data segment sum dword 0 counter dword 0 prompt byte "Enter a value: (0 to stop) ", 0 result byte "The sum of ", 0 count byte " numbers is ", 0 ;-------------------------------------------------- .code ; begin code segment ;-------------------------------------------------- ;-------------------------------------------------- prompt_user PROC ; ; Take a break! Pauses screen ;-------------------------------------------------- mov edx, OFFSET prompt ; prompt user to enter values call WriteString call Crlf GetValue: call ReadInt ; read integer from keyboard jo Overflow ; if ReadInt set overflow flag, jump to Overflow add sum, eax ; add entered value to accumulator sum jo Overflow ; if addition set overflow flag, jump to Overflow cmp eax, 0 ; did user enter 0? je Done ; if yes, goto Done inc counter ; increment counter jmp GetValue ; loop Overflow: mov eax, 0 mov sum, 0 Done: ret ;-------------------------------------------------- prompt_user ENDP ;-------------------------------------------------- ;-------------------------------------------------- print_sum PROC ; ; Take a break! Pauses screen ;-------------------------------------------------- mov edx, OFFSET result ; prints "The sum of " call WriteString mov eax, counter ; prints count of #s entered call WriteDec mov edx, OFFSET count ; prints " numbers is " call WriteString mov eax, sum ; prints sum call WriteDec call Crlf ret ;-------------------------------------------------- print_sum ENDP ;-------------------------------------------------- ;-------------------------------------------------- main proc ;-------------------------------------------------- call Clrscr ; clear screen call prompt_user ; get integers call print_sum ; print their sum exit main endp end main ;--------------------------------------------------
Post Comment
•
•
•
•
DaniWeb Marketplace (Sponsored Links)