GIDForums  

Go Back   GIDForums > Computer Programming Forums > Assembly Language
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

 
 
Thread Tools Search this Thread Rate Thread
  #1  
Old 14-Mar-2009, 08:04
bonekrusher bonekrusher is offline
New Member
 
Join Date: Sep 2007
Posts: 9
bonekrusher is on a distinguished road

Added the values of an Array


Hi,

I am working on a homework assignment, which is to add the values of an array. The array is populated by user input. I am able to store the values, but unable to get the sum. My programs crashes (see comments in code). Any help or guidance is appreciated.

Code:
TITLE Arrays (lab5.asm) INCLUDE Irvine32.inc .data startStr BYTE "Hello, you will be asked to enter a number and hit enter (10 times)", 0 enterStr BYTE "Please enter a number and hit enter:", 0 myArray DWORD 10 DUP( 0) count DWORD 2 ;set counter .code main PROC mov ecx, count ; set counter to 2 mov esi, OFFSET myArray ; set size of array mov edx, OFFSET startStr call WriteString call CRLF call getInput ; get input from users call arraySum ; add array sum call WriteInt call DumpRegs exit main ENDP ; Gets input from user getInput PROC mov edx, OFFSET enterStr inputLoop: ; start loop call WriteString call ReadInt ; get value from user call WriteInt mov eax, [esi] ; store in array add esi, 4 ; next integer (32 bit integer use 4) call Crlf loop inputLoop ; end loop ret getInput ENDP ; example from page 139 arraySum PROC push esi; ; save esi push ecx ; save ecx mov eax, 0 ; set eax to 0 L1: add eax,[esi] ; PROGRAM CRASHES HERE add esi, 4 loop L1; pop esi; ; restore esi pop ecx ; restore ecx ret arraySum ENDP END main
  #2  
Old 17-Mar-2009, 02:01
Howard_L Howard_L is offline
Regular Member
 
Join Date: Apr 2007
Location: Maryland/PA, USA
Posts: 840
Howard_L is a jewel in the roughHoward_L is a jewel in the roughHoward_L is a jewel in the rough

Re: Added the values of an Array


Sorry I didn't see this. Did you get it fixed?
  #3  
Old 17-Mar-2009, 16:21
bonekrusher bonekrusher is offline
New Member
 
Join Date: Sep 2007
Posts: 9
bonekrusher is on a distinguished road

Re: Added the values of an Array


Hi, no I havent. I appreciate any help. This what I have so far:

Code:
TITLE Arrays (lab5.asm) INCLUDE Irvine32.inc .data startStr BYTE "Hello, you will be asked to enter a number and hit enter (10 times)", 0 enterStr BYTE "Please enter a number and hit enter:", 0 myArray DWORD 10 DUP( 0) count DWORD 2 ;set counter .code main PROC mov ecx, count ; set counter to 2 mov esi, OFFSET myArray mov edx, OFFSET startStr call WriteString call CRLF call getInput ; get input from users mov esi, OFFSET myArray ; go to start of the array call arraySum ; add array sum call WriteInt call DumpRegs exit main ENDP ; Gets input from user getInput PROC mov edx, OFFSET enterStr inputLoop: ; start loop call WriteString call ReadInt ; get value from user call WriteInt mov [esi], eax ; store in array add esi, 4 ; next integer (32 bit integer use 4) call Crlf loop inputLoop ; end loop ret getInput ENDP ; example from page 139 arraySum PROC mov esi, OFFSET myArray mov eax, 0 ; set eax to 0 L1: mov eax,[esi] add esi, 4 ; PROGRAM CRASHES HERE loop L1; ret arraySum ENDP END main

The program crashes at:
Code:
add esi, 4

in arraySum

Thanks for the help.
  #4  
Old 17-Mar-2009, 16:41
bonekrusher bonekrusher is offline
New Member
 
Join Date: Sep 2007
Posts: 9
bonekrusher is on a distinguished road

Re: Added the values of an Array


Never mind, I figured it out. I never set my loop count for my loop!
mov ecx, count
 
 

Recent GIDBlogProblems with the Navy (Officers) by crystalattice

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
where is the problem and can you fix it (php) oggie MySQL / PHP Forum 8 14-Apr-2008 16:08
Getting a line error in register oggie MySQL / PHP Forum 5 13-Apr-2008 17:16
Need Help with input files. Efferus C++ Forum 2 24-Nov-2007 17:19
How to sort in C++ alphabetically wilen C++ Forum 5 20-Apr-2007 15:43
Need help deleting the last element in the array headphone69 C++ Forum 2 15-Mar-2006 20:31

Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The

All times are GMT -6. The time now is 03:09.


vBulletin, Copyright © 2000 - 2010, Jelsoft Enterprises Ltd.