News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

Something that confused me.

Started by Narray, October 15, 2011, 03:57:19 AM

Previous topic - Next topic

Narray

this confused me. 

RRY_COUNT = 64                     ; sets the length to 64

.data
fullName   BYTE "X1234567890 X1234",0Dh,0Ah,0   ; puts full name in Var fullName
ToString   BYTE "There are ",0
ToString2nd   BYTE " values greater than 0.",0dh,0ah,0
PCount      BYTE ?
ArrayInt   BYTE RRY_COUNT Dup (0),0
.code
main PROC
.
.
.
      mov edx,OFFSET ToString         ; outputs the string
      call WriteString            
      
      xor eax,eax

      mov al,PCount
      call Writedec

      mov edx,OFFSET ToString2nd
      call WriteString   

when set up like this it outputs something like this
"There are 34 values greater than 0."

but when i set it up like this 

.data
fullName   BYTE "X1234567890 X1234",0Dh,0Ah,0   ; puts full name in Var fullName
ArrayInt   BYTE RRY_COUNT Dup (0),0             
PCount      BYTE ?                                   
ArrayInt   BYTE RRY_COUNT Dup (0),0     
ToString   BYTE "There are ",0                         
ToString2nd   BYTE " values greater than 0.",0dh,0ah,0

.code
main PROC
.
.
.
      mov edx,OFFSET ToString         ; outputs the string
      call WriteString            
      
      xor eax,eax

      mov al,PCount
      call Writedec

      mov edx,OFFSET ToString2nd
      call WriteString   
it out put this
"↔0ere are 32 values greater than 0."

what's is wrong with the 2nd statement?

dedndave

well - you aren't showing us all the code
but it looks to me as though the ArrayInt is being over-written (the second one - lol)
i.e. you are writing beyond the length of that array - oops!
it could be that RRY_COUNT is not correct for the implemenation

dunno how that works - you can't have 2 variables with the same name

Narray

#2
code deleted

dedndave

ArrayInt is typed as a byte array, then you fill it with dwords   :P
the only thing saving you is that you increment the index into the array by "TYPE ArrayInt"
but, that tells you why it is over-written by 3 bytes

try this
ArrayInt   DWORD RRY_COUNT Dup (0)