1.11M Members

Array in Assembly

 
0
 

Hello all, I am having some trouble with my assembly code...still kind of new, but here it goes...
The assignment is to desing an assembly program that uses a dialog box to prompt the user for a number. These numbers will be stored in an array. There will be an output message that shows the following: sum of numbers entered, how many numbers were entered(not counting the -9999 to end the program), the aerage of the numbers, and the count of array entries that are greater that or equal to the average value. All help is appreciated!

Here is my code so far:

`.586
.MODEL FLAT

INCLUDE io.h            ; header file for input/output

.STACK 4096

.DATA
numArray       DWORD   ?
numElts     DWORD   100
num         DWORD   ?
prompt       BYTE    "Enter a number", 0
string      BYTE    40 DUP (?)
resultLbl     BYTE  "Results", 0
sum         BYTE    11 DUP(?), " is the sum.", 0dh, 0ah
numEntered   BYTE   11 DUP(?), " numbers were entered."
avg         BYTE    11 DUP(?), " is the average."
count         BYTE    11 DUP(?), " is the number of entries that are >= the average."

.CODE
_MainProc PROC
            mov     edx, -9999
            mov     eax, 0            ; sum := 0
            lea     ebx, numArray      ; get address of nbrArray

LOOP1:    input      prompt, string, 40  ; read ASCII characters
            atod       string             ; convert to integer
            mov        num, eax         ; store in memory
            mov     ecx, numElts        ; count := nbrElts
            jedx       QUIT             ; quit if -9999
            add     eax, [ebx]        ; add number to sum
            add     ebx, 4            ; get address of next array elt
            add     ecx, 1            ; add one for count
            loop       LOOP1               ; repeat nbrElts times

            cdq                         ; extend sum to quadword
            idiv       numElts           ; calculate average

            output     resultLbl, sum, avg, numEntered, count
QUIT:       mov        eax, 0             ; exit with return code 0
            ret

_MainProc ENDP
END                                     ; end of source code`
 
0
 

Did some more troubleshooting, and changed a few things...this is what I have now....still need help guys...its due tonight. Again, all help is appreciated greatly!!!

.DATA
numArray       DWORD   ?
numElts     DWORD   100
num         DWORD   ?
exitNum     DWORD   -9999
prompt       BYTE    "Enter a number", 0
string       BYTE    40 DUP (?)
resultLbl     BYTE  "Results", 0
sum         BYTE    11 DUP(?), " is the sum.", 0dh, 0ah
numEntered   BYTE   11 DUP(?), " numbers were entered."
avg         BYTE    11 DUP(?), " is the average."
count         BYTE    11 DUP(?), " is the number of entries that are >= the average."

.CODE
_MainProc PROC
            mov     eax, 0                   ; sum := 0
            lea     ebx, numArray             ; get address of nbrArray

LOOP1:      input      prompt, string, 40        ; read ASCII characters
            atod       string                    ; convert to integer
            mov        num, eax                ; store in memory
            mov     ecx, numElts               ; count := nbrElts
            cmp     exitNum, eax
            je       QUIT                      ; quit if -9999
            add     eax, [ebx]               ; add number to sum
            add     ebx, 4                   ; get address of next array elt
            add     ecx, 1                   ; add one for count
            loop       LOOP1                      ; repeat nbrElts times

            cdq                                ; extend sum to quadword
            idiv       numElts                  ; calculate average
            mov     count, ecx
            mov     sum, eax
            mov     avg, ebx

            output     resultLbl, sum, avg, numEntered, count
QUIT:       mov        eax, 0                    ; exit with return code 0
            ret
 
0
 

Have some more code...I'm sorry to keep posting, but I am really at a roadblock! It compiles, but now I cannot output anything. Here it is:

            mov     eax, 0                      ; sum := 0
            lea     ebx, numArray               ; get address of nbrArray

LOOP1:      input   prompt, string, 40          ; read ASCII characters
            atod    string                      ; convert to integer
            mov     num, eax                    ; store in memory
            mov     ecx, numElts                ; count := nbrElts
            cmp     exitNum, eax
            je      QUIT                        ; quit if -9999
            add     eax, [ebx]                  ; add number to sum
            add     ebx, 4                      ; get address of next array elt
            add     ecx, 1                      ; add one for count
            loop    LOOP1                       ; repeat nbrElts times

            cdq                                 ; extend sum to quadword
            idiv    numElts                     ; calculate average
            dtoa    avg, ebx                    ; convert to ASCII characters
            dtoa    count, ecx
            dtoa    sum, eax

QUIT:             
            output resultLbl, sum, avg, count
            ret
You
This article has been dead for over six months: Start a new discussion instead
Post:
Start New Discussion
View similar articles that have also been tagged: