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 28-Oct-2007, 13:20
czerdrill czerdrill is offline
New Member
 
Join Date: Oct 2007
Posts: 2
czerdrill is on a distinguished road

Program Not working, assembly language


Hey,

Why won't this program work in assembly? I'm using Microsoft Visual C++ 2005 Express Edition, and using x86 assembly architecture. It's suppose to add the values in the array that are higher than the variable sample(in this case 50) and display the result. The answer should be +358 but I keep getting +0. I know it's one little mistake I'm making. Any ideas? Code:

.data

sum DWORD 0
sample DWORD 50

array DWORD 10,60,20,33,72,89,45,65,72,18
ArraySize = ($ - array)/ TYPE array

.code

main PROC

mov eax, 0
mov edx, sample
mov esi, 0
mov ecx, ArraySize

L1: cmp esi,ecx
jg L2
jmp L5

L2: cmp array[esi*4], edx
jg L3
jmp L4
add eax, array[esi*4]

L3: add eax,array[esi*4]

L4: inc esi
jmp L1

L5: mov sum, eax
call Writeint
call Crlf


exit

main ENDP


END main
  #2  
Old 28-Oct-2007, 14:13
davekw7x davekw7x is offline
Outstanding Member
 
Join Date: Feb 2004
Location: Left Coast, USA
Posts: 4,712
davekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to behold

Re: Program Not working, assembly language


Quote:
Originally Posted by czerdrill
Hey,...Why won't this program work...

Isn't the following logic backwards?

Code:
L1: cmp esi,ecx jg L2 jmp L5

Since the contents of esi are not greater than the contents of ecx, it bails out (by jumping to L5) without ever going through the loop.

Regards,

Details! Details! The devil is in the details!
---me

Dave

Footnote:
What's up with this:
Code:
L2: cmp array[esi*4], edx jg L3 jmp L4 add eax, array[esi*4] <===Why is this statement here? It never gets executed. Lack of attention to detail shows sloppy methodology, and pretty much guarantees failure. L3: add eax,array[esi*4]

Beyond removing the superfluous statement, why not make the logic more concise? Instead of a conditional jump followed by an unconditional jump, why not reverse the sense: if the value is less or equal to the threshold, jump around the add statement.
 
 

Recent GIDBlogMeeting the populace 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
Two-Tier data dissemination code installation problem nidhibansal1984 Computer Software Forum - Linux 6 16-Sep-2007 10:13
Assemblers & assembly language BlueFireCO. Assembly Language 2 26-Mar-2007 09:56
BOOKEEPING program, HELP!! yabud C Programming Language 10 17-Nov-2006 03:48
which language ? onauc C++ Forum 2 19-Nov-2004 02:53

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

All times are GMT -6. The time now is 11:42.


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