×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Contact US

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.

Students Click Here

Need Help Please!

Need Help Please!

Need Help Please!

(OP)
I need to create an array of 20 values (bytes) and compute the average. I'm new in this. This is my code for the addition phase:

.MODEL SMALL
.STACK 100h
.DATA
arreglo db 3, 8, 5, 3, 9, 2, 1, 4, 5, 11, 2, 1, 12, 10, 7, 17, 18, 6, 14, 13
arrsuma db ?
promedio db ?

.CODE
main proc

     mov ax,@DATA
     mov ds,ax
     mov al,arreglo[0]
     add al,arreglo[1]
     add al,arreglo[2]
     add al,arreglo[3]
     add al,arreglo[4]
     add al,arreglo[5]
     add al,arreglo[6]
     add al,arreglo[7]
     add al,arreglo[8]
     add al,arreglo[9]
     add al,arreglo[10]
     add al,arreglo[11]
     add al,arreglo[12]
     add al,arreglo[13]
     add al,arreglo[14]
     add al,arreglo[15]
     add al,arreglo[16]
     add al,arreglo[17]
     add al,arreglo[18]
     add al,arreglo[19]
     mov arrsuma,al
     mov ax,4c00h
     int 21h


main endp
end main

--------end of code------------

the problem is that when I create the executable it only have 1kb and when I use debug to see if it is doing what I want the it doesn't do it. Help me please

  

RE: Need Help Please!

Problem 1:  Array Indexing in assembler is done as follows:

CODE

; load base offset in an base register
mov bx,offset arreglo
; get first item in array
mov ax, byte [bx]
; now add second item
add ax,byte [bx+1]
while there are some assemblers that utilize the base[index] form of accessing arrays, it is because they use a macro to translate to the actual assembler instructions.

problem 2:
  your assumption that the end result is less than 255, and therefore will fit into a byte sized register. While in this particular case it is, what happens when the result is greater than 255, the overflow flag is set and the result "goes around the corner."

Problem 3:  Most assemblers default to hex radix, meaning that indexes and integers without a radix designator are assumed to be in hexadecimal format. Your assumption is indexes are decimal.  As a safety measure ALWAYS designate numerals with the desired radix, i.e. 3fH, 21d 56o, 1011b.  Saves a lot of hair loss. smile

The simplest solution is the best!

RE: Need Help Please!

Assemblers build your executables ONLY with the code YOU specify. HLL compilers mostly add
a lot of additional code (debug info, error checking, memory management etc.) to your final
program, stuff you might not even use or need. That's why assembler programs are so small.

what is exactly going wrong in your debug session?

if you want, you can use the following code instead of all the "add al,xxx" lines. it is shorter.

CODE

  mov si,offset arreglo
  mov cx,sizeof arreglo
  xor ah,ah

lp:
  lodsb
  add ah,al
  loop lp

  mov arrsuma,ah

RE: Need Help Please!

(OP)
Thank You for your time and your help. I used the tips that denc4 recommend and worked. Thanks Alot!

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! Already a Member? Login


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