News:

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

Is there an easier way to write this short code?

Started by Trope, September 21, 2005, 09:12:19 PM

Previous topic - Next topic

Trope

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


Mirno

I think the following code'll work.

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


Mirno

QvasiModo

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"


Trope