Click to See Complete Forum and Search --> : cmp help
Any ideas why this wont work? Im compilng with A86.
START:
mov ds, cs
jmp MAIN
Message1 db 13, 10, "Password [pass.exe]", 13, 10
db "Copyright (C) 2000 Hero Inc. All rights reserved.", 13, 10, "$"
Prompt db 13, 10, "Password: $"
Password db "hello$"
Buffer db "$"
MAIN:
;Clear
call ClearScreen
;Print Message1
mov dx, offset Message1
mov ah, 9
int 21h
;Print Prompt
mov dx, offset Prompt
mov ah, 9
int 21h
;Input string
mov ah, 3fh
xor bx, bx
mov cx, 20h
mov dx, offset Buffer
int 21h
mov ax, offset Buffer
cmp ax, offset Password
je EXIT
jmp MAIN
EXIT:
call ClearScreen
mov ax, 4c00h
int 21h
ClearScreen proc
mov ax, 0003h
int 10h
ret
ClearScreen endp
END START
I think it has something to do with these lines...
mov ax, offset Buffer
cmp ax, offset Password
Sam Finch
Oct 22nd, 2000, 10:04 AM
I think it's a bit ambitious to try to compare 2 strings with a single cmp line. all cmp does is subtract the 2 values and save the reruld to a register (can't remember which one, i think it's dx or it might be a special 2 bit register that just rempmbers the sign) then the jump commands go on whether this it +ve, -ve or 0.
I havn't got to the offset comand in my quest to learn ASM but i think you're just comparing the pointers to the strings, which will never be equal. either write a strcmp macro or a strcmp sub.
hope it helps
Sam Finch
Oct 22nd, 2000, 05:41 PM
err, you want pointers to the 2 strings in 2 registers say ebx and ecx then go into a loop, compare the values of the 2 bytes pointed to by ebx and ecx if they are not equal put a value of 0 (false) into eax, if they are equal check if one of them is 0, if it is put -1 (true) into eax and return, if not increment ebx and eax and go back to the start of the loop.
Unfortunatley I'm not quite at the stage where I can code that correctly, so I'll code it incorectly instead
StringCompare proc
pop ebx ;pops 2 parameters off the stack,
pop ecx ;these should be pointers to char arrays
strt: ;start of loop
cmp [ebx],[ecx] ;compare the bytes pointed to by
;ebx and ecx, this syntax is
;probably vey wrong so change it
;remember you only want to compare
;single bytes, not words or dwords
jne RetFalse ;if they are not the same return false
cmp [ebx], 0 ;compare the byte pointed to by ebx
;to 0 (syntax will be wrong again)
jne strt ;if it's not a termination character
;go back to the start
;end of loop
;both strings terminated so return true
mov eax, -1
ret
RetFalse:
;we've found 2 different characters so return false
mov eax, 0
ret
StringCompare endp
if you code that correctly it should work.
V(ery) Basic
Oct 29th, 2000, 04:35 AM
I was just wondering, maybe if you XOR them then the first value in the XOR would be zero, and then put a jz.
But that wouldn't be case sensitive, so you could convert it to lower case by anding each char with 6F (0110 1111).
Okay, I'm probably speaking rubbish, but the intention's good.
Darkwraith
Aug 8th, 2003, 05:31 PM
mov ax, BYTE [Buffer]
cmp ax, BYTE [Password]
I am not very good with A86, so I might be a little off. I am using the NASM syntax though
If you are comparing the values at Buffer and Password, then this would be your code.
vbforums.com
Copyright Internet.com Inc., All Rights Reserved.