News:

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

Program can't assemble

Started by Kyoy, January 28, 2005, 03:28:29 AM

Previous topic - Next topic

Kyoy

This was an example i extracted from a book. This is basically just adding up the an array of dwords.


main PROC USES esi ecx
ptrArray:PTR DWORD
szArray:DWORD

mov esi,ptrArray
mov ecx,szArray
cmp ecx,0
je L2
mov eax,0

l1:add eax,[esi]
add esi,1
loop L1
L2:ret


it says error A2008 syntax error: ptr and
error A2008 syntax error:dword

It can't recognise ptr and dword. But i was just following the books example. Any idea what additional steps or codes i must put to get this to work?

Titan

Here, I edited your code and this compiles for me:
Quote
main PROC USES esi ecx
LOCAL ptrArray:DWORD
LOCAL szArray:DWORD
mov esi,ptrArray
mov ecx,szArray
cmp ecx,0
je L2
mov eax,0

L1:add eax,[esi]
add esi,1
loop L1
L2:ret
main endp
Your loop was simple, MASM is case sensative, so you have to have your "L1"'s both capitalized.  And you should have "LOCAL" before your variables to declare them as local.  This worked for me, hope it helps! ;)

Ic3D4ne

Quote from: Kyoy on January 28, 2005, 03:28:29 AM
This was an example i extracted from a book. This is basically just adding up the an array of dwords.


main PROC USES esi ecx
ptrArray:PTR DWORD
szArray:DWORD

mov esi,ptrArray
mov ecx,szArray
cmp ecx,0
je L2
mov eax,0

l1:add eax,[esi]
add esi,1
loop L1
L2:ret


it says error A2008 syntax error: ptr and
error A2008 syntax error:dword

It can't recognise ptr and dword. But i was just following the books example. Any idea what additional steps or codes i must put to get this to work?

I'm also new to this, but should "PTR DWORD" be "DWORD PTR" ?

-Ic3D4ne

thomasantony

Hi IC3D4NE,
      You use dword ptr when you want to access a dword at an addess. For eg. if esi contains the pointer to a dword you use:
  mov dword ptr[esi],1 to set that variable to 1 etc. What he means with PTR DWORD is something like a data type which is not defined in MASM. Kyoy, you goota understand that everything is a dword in assembler. It doesn't matter whether it is HANDLE, HINSTANCE or any other data type of 32bits

Thomas Antony :U
There are 10 types of people in the world. Those who understand binary and those who don't.


Programmer's Directory. Submit for free

Kyoy

That l1 was a typo :P
Titan, thanks. That compiled but the program keeps crashing whenever executed. Any further mistakes to fix up?


main PROC USES esi ecx
LOCAL ptrArray:DWORD
LOCAL szArray:DWORD
mov esi,ptrArray
mov ecx,szArray
cmp ecx,0
je L2
mov eax,0

L1:add eax,[esi]
add esi,1
loop L1
L2:ret
main endp

thomasantony

Hi,
    Yoiu must first set the variables to point to some arrays. Or else it will point to some bogus address. This may be why your prog is crashing.

Thomas Antony :U
There are 10 types of people in the world. Those who understand binary and those who don't.


Programmer's Directory. Submit for free

MichaelW

eschew obfuscation

dsouza123

Two problems:
What is the exit condition to stop the loop.
Since it is adding dwords it should increment by 4 bytes not 1.


L1:add eax,[esi]
add esi,4  <=  increase by 4 bytes, a dword, each time
=>some sort of check for exiting the loop should be here
loop L1
L2:ret
main endp

P1

#8
Kyoy,

Please post the calling code, the error maybe there.

You have not programmed for an overflow condition for the adds.

How old is this book?   Is it a DOS MASM book?

Regards,  P1  :8)

Titan

Apparently MASM doesn't like your brackets.  I took away the brackets and I got no errors.

main PROC USES esi ecx

LOCAL ptrArray:DWORD
LOCAL szArray:DWORD

mov esi,ptrArray
mov ecx,szArray
cmp ecx,0
je L2
mov eax,0
L1:
add eax,esi
add esi,1
loop L1
L2:
ret

main endp


I came up with this after I ran your programming in OllyDbg.  It told me the error was here:

0040107A  |. B8 00000000    MOV EAX,0
0040107F  |> 0306           /ADD EAX,DWORD PTR DS:[ESI] <------- Error Here
00401081  |. 83C6 01        |ADD ESI,1


Looks like it's not doing exactly what you want it to do.  Hopefully this helps someone who is better than me, and can explain this to you better.  :P

GregL

PTR DWORD is perfectly acceptable in MASM. It means the variable is a pointer to a DWORD. I use it all the time, it makes things clearer if you ask me.

tenkey

Quote from: Kyoy on January 28, 2005, 02:22:21 PM
That l1 was a typo :P
Titan, thanks. That compiled but the program keeps crashing whenever executed. Any further mistakes to fix up?


main PROC USES esi ecx
LOCAL ptrArray:DWORD
LOCAL szArray:DWORD
mov esi,ptrArray
mov ecx,szArray
cmp ecx,0
je L2
mov eax,0

L1:add eax,[esi]
add esi,1
loop L1
L2:ret
main endp


This is not a complete program. As thomasanthony says, the two critical pieces of data, ptrArray and szArray, do not start with known good values. Start with garbage data, get garbage results.

I suspect the original PROC line was coded this way:

main PROC USES esi ecx ptrArray:PTR DWORD, szArray:DWORD


This would clearly point up the need to create "calling" code that CALLs or INVOKEs this PROC. The calling code would provide the data in the form of an array to this snippet of code.
A programming language is low level when its programs require attention to the irrelevant.
Alan Perlis, Epigram #8