The MASM Forum Archive 2004 to 2012

General Forums => The Campus => Topic started by: lingjie on May 06, 2007, 01:25:21 AM

Title: compile error while using cmp
Post by: lingjie on May 06, 2007, 01:25:21 AM
I have a compile error when I compare two BYTE

.386
.model flat,stdcall       ; FLAT memory model & STDCALL calling
option casemap:none       ; set code to case sensitive

include \masm32\include\masm32rt.inc
helper PROTO :BYTE,:BYTE


.stack  4096                  ; reserve 4096-byte stack
.data

.code
start:

invoke helper,'a','z'

exit
PUBLIC start

helper proc startChar:BYTE, endChar:BYTE

inc endChar

cmp startChar,endChar ; compile error here, can only do cmp startChar, 'z', how can I compare startChar and endChar?
ret


helper endp

end start
Title: Re: compile error while using cmp
Post by: PBrennick on May 06, 2007, 01:32:54 AM
lingjie,

You cannot compare memory to memory. Move one into a register and do the compare.

cmp startChar,endChar

changes to:

mov eax,startChar
cmp eax,endChar

Paul
Title: Re: compile error while using cmp
Post by: raymond on May 06, 2007, 01:49:42 AM
If you continue to declare them as BYTES, you should do the following to avoid another error message or an error in the result:

mov al,startChar
cmp al,endChar

Raymond
Title: Re: compile error while using cmp
Post by: korte on May 06, 2007, 12:50:33 PM



mov ax word ptr startChar
cmp ah,al