The MASM Forum Archive 2004 to 2012

General Forums => The Campus => Topic started by: Trope on September 21, 2005, 09:12:19 PM

Title: Is there an easier way to write this short code?
Post by: Trope on September 21, 2005, 09:12:19 PM
Basically I have a buffer that contains 3 numbers and I want to see if the numbers = 231. That's all.

I know, I am making this more difficult on myself, but this is the only way I knew how. Can anyone simplify my code?


        ;-------------------
; Check the sequence
;--------------------
lea edx, TheSequence
mov al, [edx]
.if al != '2'
mov correct_SEQUENCE, 1
ret
.endif

inc edx
mov al, [edx]
.if al != '3'
mov correct_SEQUENCE, 1
ret
.endif

inc edx
mov al, [edx]
.if al != '1'
mov correct_SEQUENCE, 1
ret
.endif

Title: Re: Is there an easier way to write this short code?
Post by: Mirno on September 21, 2005, 11:01:04 PM
I think the following code'll work.

  mov eax, [edx]
  and eax, 0FFFFFFh
  cmp eax, "231"


Mirno
Title: Re: Is there an easier way to write this short code?
Post by: QvasiModo on September 21, 2005, 11:28:29 PM
Due to MASM's tricky syntax it should be:

  mov eax, [edx]
  and eax, 0FFFFFFh
  cmp eax, "132"


Or to make it clearer, this will work on almost every assembler:

  mov eax, [edx]
  and eax, 0FFFFFFh
  cmp eax, 00313332h    ; ASCII "231"

Title: Re: Is there an easier way to write this short code?
Post by: Trope on September 21, 2005, 11:48:45 PM
cool thanks! I will replace it now!