flat assembler
Message board for the users of flat assembler.

Index > Main > fasm doesn't handle repe cmps instruction?

Author
Thread Post new topic Reply to topic
AlexP



Joined: 14 Nov 2007
Posts: 561
Location: Out the window. Yes, that one.
AlexP
After trying to get a loop working for validating passwords, I tried using a new instruction. The repe cmps instruction (from intel manual) doesn't seem to work with fasm, it just gives me a "invalid address" error. The variable FileHeaderBuffer points to a 64-byte long buffer for a header from a file passed to the function, but the "invalid address" is telling otherwise. Why is this?

The buffer code in the .data section looks like this:

FileHeaderBuffer RB 64

Code:

                PasswordCheck:

                ;Get offset of hashed password in file                
                ;-- -----------------------------------
                ;mov pointer to password in header into eax
                lea eax,[FileHeaderBuffer+0x8] ;offset
                ;pointer to user-supplied hashed pass already in ebx
                ;-------------------------------------


                ;Save registers for repeat instruction
                ;-----------------------------------
                ;Store the two pointers in temp regs
                push edi
                push esi
                ;Operands need to be in EDI and ESI
                mov edi,eax
                mov esi,ebx
                ;-----------------------------


                ;Repeatedly compare strings
                ;------------------------------
                ;Repeat instruction counter is ecx
                xor ecx,ecx  ;WOW ALMOST BIG BUG!!!!
                mov ecx,4
                ;This instruction compares what's in edi and esi
                ;then repeats for ecx times
                ;In other words, compares two 16-byte values
                ;  which in this case are our encrypted passwords
                repe cmps [edi],[esi]
               ;------------------------------
                je somewhereelse....
                
    


The instruction "repeats a string instruction the number of times specified in the count register or until the indicated condition of the ZF flag is no longer met.". I have seen it work in code before, but it is not working for me.
Post 24 Nov 2007, 02:37
View user's profile Send private message Visit poster's website Reply with quote
LocoDelAssembly
Your code has a bug


Joined: 06 May 2005
Posts: 4633
Location: Argentina
LocoDelAssembly
Because you can only use ESI as dest and EDI as source.

TFM wrote:
cmps subtracts the destination string element from the source string element and updates the flags AF, SF, PF, CF and OF, but it does not change any of the compared elements. If the string elements are equal, ZF is set, otherwise it is cleared. The first operand for this instruction should be the source string element addressed by SI or ESI with any segment prefix, the second operand should be the destination string element addressed by DI or EDI.

cmpsb ; compare bytes
cmps word [ds:si],[es:di] ; compare words
cmps dword [fs:esi],[edi] ; compare double words


In your case rep cmps word [esi], [edi] or just rep cmpsw will suffice
Post 24 Nov 2007, 03:17
View user's profile Send private message Reply with quote
AlexP



Joined: 14 Nov 2007
Posts: 561
Location: Out the window. Yes, that one.
AlexP
Yes, but I wanted to use repe (repeat if equal) so that if it breaks and the zero flag is not set, then I know the four dwords are not equal. So should I just use rep cmps dword [esi],[edi]? By the way, it is still giving me an invalid address error.. I'll check my code over, but it shouldn't be saying that..
Post 24 Nov 2007, 03:19
View user's profile Send private message Visit poster's website Reply with quote
LocoDelAssembly
Your code has a bug


Joined: 06 May 2005
Posts: 4633
Location: Argentina
LocoDelAssembly
I use "repe cmps dword [esi],[edi]" here and works OK, perhaps the error is somewhere else (also)?

Code:
virtual at 0
  rep
  repe
  load a byte from $-2
  load b byte from $-1
  if a = b
    display "same opcode!!", 13, 10
  end if
end virtual

; Guess what it prints    

Sorry though, it was a misspelling using REP instead of REPE and after reading I couldn't see it because I saw that it was correctly written for the purpose you wanted even though it was a little "obfuscated".
Post 24 Nov 2007, 03:47
View user's profile Send private message Reply with quote
AlexP



Joined: 14 Nov 2007
Posts: 561
Location: Out the window. Yes, that one.
AlexP
...Okay.. thanks for the little opcode demonstration, I think it's in my memory handling. I'll try to find out what is causing the "invalid address" message. Fasm error handling should be able to point out which address or specific opcode has the issue in the future. THanks!
Post 24 Nov 2007, 04:01
View user's profile Send private message Visit poster's website Reply with quote
LocoDelAssembly
Your code has a bug


Joined: 06 May 2005
Posts: 4633
Location: Argentina
LocoDelAssembly
But it does! It tell you which line of code is problematic, at least with FASMW.
Post 24 Nov 2007, 04:31
View user's profile Send private message Reply with quote
AlexP



Joined: 14 Nov 2007
Posts: 561
Location: Out the window. Yes, that one.
AlexP
Yeah, which line of code, but I'm saying which operand has the problem.. Or better yet, fasm should print out a paragraph saying what the problem was, where it happened, what I could've done to fix it, and whether to have one or two sugars in my morning coffee lol... I'm just gonna have to set the file pointer and read in those bytes manually instead of from the GIANT data structure I had. Great....
Post 24 Nov 2007, 17:11
View user's profile Send private message Visit poster's website Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  


< Last Thread | Next Thread >
Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Copyright © 1999-2020, Tomasz Grysztar.

Powered by rwasa.