INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Jobs

new to assembly, need some help

new to assembly, need some help

(OP)
my goal is to add all the number in ary, but my problem seems to come on the command "add eax,[esi]" if anyone could give me some advice it would be greatly appreciated.


TITLE MASM Template (main.asm)

; Description:
;
; Revision date:

INCLUDE Irvine32.inc
.data
myMessage BYTE "MASM program example",0dh,0ah,0

ary dword 100, -50, 125, 94, 35, -92, 82, 634, 193, 99, -54, 1, -5, 200, 15
dword 81, 44, 143, 132, 52, -62, 38, 56, 42, -81, 55, 43, 121, 25, 0

.code
main PROC
call Clrscr

lea esi,ary ;
addloop: ;
add esi,4 ;
add eax, [esi] ;
cmp esi,0 ;
jne addloop ;

call DumpRegs

mov edx,offset myMessage
call WriteString

exit
main ENDP

END main

RE: new to assembly, need some help

What happens when you run your program?

RE: new to assembly, need some help

(OP)
It runs successfully but acts like an infinite loop and won't print anything. When I run it on debug it shows an error on the line previously stated

RE: new to assembly, need some help

CODE

lea esi,ary ; 

You're loading an ADDRESS into esi, which will never be zero.

CODE

cmp esi,0 ;
jne addloop ; 

The loop continues when esi <> 0, which it will never be.

I can only guess you are wanting to add numbers until the CONTENTS of esi is zero.

Since you can't compare against the contents of memory, you'll have to move it to a register before you do so.

CODE

lea esi,ary
 addloop:
 add esi,4
 mov ecx, [esi]
 add eax, ecx
 cmp ecx,0
 jne addloop
 mov answer, eax 

It is not possible for anyone to acknowledge truth when their salary depends on them not doing it.

RE: new to assembly, need some help

(OP)
ah that makes sense, thank you for the help

RE: new to assembly, need some help

(OP)
I have a new problem in my sumloop or squareloop, it just does an infinite loop and won't print and debug won't show anything is wrong.

TITLE MASM Template (main.asm)

; Description:
;
; Revision date:

INCLUDE Irvine32.inc
.data
myMessage BYTE "MASM program example",0dh,0ah,0

ary dword 100, -50, 125, 94, 35, -92, 82, 634, 193, 99, -54, 1, -5, 200, 15
dword 81, 44, 143, 132, 52, -62, 38, 56, 42, -81, 55, 43, 121, 25, 0

.code
main PROC
call Clrscr

mov eax,0 ; *******************
mov ebx,0 ; *******************
mov ecx,0 ; ** set registers **
mov edx,0 ; ** to zero **
mov ebp,0 ; *******************

mov esi,offset ary ; set esi to START of the array

addloop: ; looping structure for computing the sum
inc ecx ; counter for # of values in array
mov edx,[esi] ; move the value in the array to edx
add eax, edx ; add number just read in to eax to keep the sum
add esi,4 ; to move through the array
cmp edx,0 ; compare the just read in value to sentinal value
jne addloop
dec ecx ; subtract one from counter to account for sentinal value

mov edx,eax ; make copy of sum
subloop: ; division by repeated subtraction
inc ebx ; increase by 1 for each loop for average
sub edx,ecx ; subtract # of values from sum
cmp edx,ecx ; compare sum to the number of values
jnl subloop

mov edx,0
mov eax,0
sumloop: ; looping structure for computing the sum
dec ecx ; decrease to compare to # of values
mov ebp,[esi] ; move the value in the array to ebp
sub ebp,ebx ; subtract the average from the value just read in
mov edi,ebp ; copy value after subtraction for counter
squareloop:
add edx,ebp ; repeated addition to find square
dec edi ; starts at value after subtracting average and decreases to 0 by 1
cmp edi,0 ; exits when the number has been squared
jne squareloop
add eax,edx ; sum of all values after being squared
add esi,4 ; to move through the array
cmp ecx,0 ; compare the total # of values to current # of values
jne sumloop

call DumpRegs

mov edx,offset myMessage
call WriteString

exit
main ENDP

END main

RE: new to assembly, need some help

(OP)
a

CODE --> assembly

TITLE MASM Template						(main.asm)

; Description:
; 
; Revision date:

INCLUDE Irvine32.inc
.data
myMessage BYTE "MASM program example",0dh,0ah,0
    
    ary	  dword	    100, -50, 125, 94, 35, -92, 82, 634, 193, 99, -54, 1, -5, 200, 15
		  dword	    81, 44, 143, 132, 52, -62, 38, 56, 42, -81, 55, 43, 121, 25, 0

.code
main PROC
	call Clrscr 
	   
	   mov	 eax,0				    ;   *******************
	   mov	 ebx,0				    ;   *******************
	   mov	 ecx,0				    ;   ** set registers **
	   mov	 edx,0				    ;   **    to zero	**
	   mov	 ebp,0				    ;   *******************

	   mov esi,offset ary			    ;   set esi to START of the array

addloop:							    ;   looping structure for computing the sum
	   inc	 ecx					    ;   counter for # of values in array
	   mov	 edx,[esi]			    ;   move the value in the array to edx
	   add	 eax, edx				    ;   add number just read in to eax to keep the sum
	   add	 esi,4				    ;   to move through the array
	   cmp	 edx,0				    ;   compare the just read in value to sentinal value
	   jne	 addloop
	   dec	 ecx					    ;   subtract one from counter to account for sentinal value

	   mov	 edx,eax				    ;   make copy of sum
subloop:							    ;   division by repeated subtraction
	   inc	 ebx					    ;   increase by 1 for each loop for average
	   sub	 edx,ecx				    ;   subtract # of values from sum
	   cmp	 edx,ecx				    ;   compare sum to the number of values
	   jnl	 subloop

	   mov	 edx,0
	   mov	 eax,0
sumloop:							    ;   looping structure for computing the sum
	   dec	 ecx					    ;   decrease to compare to # of values
	   mov	 ebp,[esi]			    ;   move the value in the array to ebp
	   sub	 ebp,ebx				    ;   subtract the average from the value just read in
	   mov	 edi,ebp				    ;   copy value after subtraction for counter
squareloop:						    
	   add	 edx,ebp				    ;   repeated addition to find square
	   dec	 edi					    ;   starts at value after subtracting average and decreases to 0 by 1
	   cmp	 edi,0				    ;   exits when the number has been squared
	   jne	 squareloop			    
	   add	 eax,edx				    ;   sum of all values after being squared
	   add	 esi,4				    ;   to move through the array
	   cmp	 ecx,0				    ;   compare the total # of values to current # of values
	   jne	 sumloop

	call	  DumpRegs

	mov	 edx,offset myMessage
	call WriteString

	exit
main ENDP

END main 

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Resources

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close