The MASM Forum Archive 2004 to 2012

General Forums => The Campus => Topic started by: *DEAD* on December 17, 2007, 10:23:39 AM

Title: strange syntax errors
Post by: *DEAD* on December 17, 2007, 10:23:39 AM
This has me absolutely baffled.



IsPrime proc test:DWORD
;
; ;mov ecx, test
; shr ecx, 1
;
; StartLoop:
;
; ; mov eax, test
; xor edx, edx
; div ecx
; cmp edx, 0
; jnz ExitLoop
; sub ecx, 2
;
; ja StartLoop
;
; push 1
; ret
;
; ExitLoop:
; push 0
; ret
IsPrime endp


Apparently, there is a syntax error with the colon. I have no idea whats going on, seeing as I practically copied the DlgProc example, which does work, to make my own.
"C:\masm32\projects\primefinder2\primefinder.asm(32) : error A2008: syntax error : :"
Also, when the middle code isnt commented out, mov ecx, test returns a syntax error
"C:\masm32\projects\primefinder2\primefinder.asm(39) : error A2008: syntax error : test"
but that is more that likely to be a result of the first syntax error. Can anyone tell me whats wrong with my colon. The rest of the code is below.
Title: Re: strange syntax errors
Post by: sinsi on December 17, 2007, 10:51:39 AM
"TEST" is a reserved word (test eax,eax)
Title: Re: strange syntax errors
Post by: RuiLoureiro on December 17, 2007, 05:44:18 PM
I didnt understand the way you want exit from IsPrime procedure:

push 1    and   push 0
ret                  ret

Can you explain it ?
Rui
Title: Re: strange syntax errors
Post by: Tedd on December 18, 2007, 12:28:26 PM
It's wrong :P
(The return address is popped off the stack, so it will try to 'return' to address 0 or 1, which will crash.)

The tradition is to put the return value into eax (though there's little to stop you from using a different register, or a memory location.)