News:

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

Help with MASM-Arrays

Started by john113, March 10, 2008, 03:49:20 PM

Previous topic - Next topic

john113

Hi guys,

In the work I am suppose to use the "adding 30h" method, as the numbers are 0-9.

mov esi, offset myarray

mov eax, [esi]
add eax,30H
mov total,eax

mov eax, [esi+4]
add eax,30H
mov total,eax


mov eax, [esi+8]
add eax,30h
mov total,eax


mov eax, [esi+12]
add eax,30h
mov total,eax


mov eax, [esi+16]
add eax,30h
mov total,eax


mov eax, [esi+20]
add eax,30h
mov total,eax


mov eax, [esi+24]
add eax,30h
mov total,eax




I can get the first element to display using StdOut and it gives out correct answer "2". But the rest comes out as symbols. Any idea why?

ramguru

using your way


total      db 100 dup(?) ; it should be a string - an array of bytes

mov esi, offset myarray

mov eax, [esi]
add eax,30H
mov BYTE PTR [total+0],al

mov eax, [esi+4]
add eax,30H
mov BYTE PTR [total+1],al

mov eax, [esi+8]
add eax,30h
mov BYTE PTR [total+2],al
...
mov BYTE PTR [total+x],0 ; zero terminated string



Of course this code isn't very recommended, but it's your way, maybe for better understanding.

john113

Is there anyway to display using StdOut after adding 30H to each element?


ramguru

Now I'm confused in one your code-snippet you use ... "myarray": array of BYTES in another array of DWORDS

Quote from: john113 on March 10, 2008, 10:17:12 PM
Is there anyway to display using StdOut after adding 30H to each element?
It supposed to work when myarray is an array of dwords, otherwise (if bytes)
you should change code:
[esi+0]
[esi+1]
[esi+2]
...
Just know that BYTE is the base unit .. so it's 1, DWORD is 4
you add 1 if it's byte you add 4 if it's dword  etc.

john113

Hi

I dont really get what you say, my code so far....


.data
   myarray dword 00000010b,01000000b,00010100b,011111100b

  total dword ?
 
       
    .code                       ; tell masm where the code starts

    start:                          ; the code entry point to the program


mov esi, offset myarray
mov eax,[esi]
add eax,30h
mov total, eax
invoke StdOut, addr [total] ; this bit seems to work ok and output 2

mov eax, [esi+4]
add eax,30H
mov total, eax
invoke StdOut, addr [total] ;when I add this bit it only prints out "p" giving output "2p" when I am expecting "27"



ramguru

Quote from: john113 on March 10, 2008, 07:29:45 PM
Hi guys,
In the work I am suppose to use the "adding 30h" method, as the numbers are 0-9.
So what the heck are you doing?
myarray dword 00000010b,01000000b,00010100b,011111100b
==
myarray dword 2,64,20,252

64 is not in range of 0-9
20 is not in range of 0-9
252 is not in range of 0-9


EDIT> I think I understood what you were trying to do. You wanted to get an index of the bit that was set...but it's not the proper way of doing it... 00010 and result 2 was just a coincidence  :lol  :lol  :lol

john113

Hey

I managed to declare the array as:


myarry db 0001b,0001b,1000b.........


then call each element,add 30h and display it....