You are not logged in.

#1 2006-10-18 01:49:06

rab
Member
Registered: 2006-06-15
Posts: 185

[x86 ASM] CMP strings help

section .data
    _execve        equ 59            
    _passwd        db 'hi', 0x00
    _passwdlen    equ $-_passwd
    _wrong        db 'WRONG',10,0        
    _wronglen    equ $-_wrong        
    _right        db 'RIGHT!!!',10,0    
    _rightlen    equ $-_right        
    _write         equ 4            
    _stdout        equ 1            
    _exit        equ 1

section .text
    global _start

_start:
    pop eax
    pop ebx
    pop ebx
    
    cmp eax, 2
    jne _die
    mov eax, 0
    jmp _checkpasswdstart

_checkpasswdstart:
        cmp ebx[eax], _passwd[eax]
    jne _wrongpasswd
    cmp eax, _passwdlen
    je _winner
    inc eax
    jmp _checkpasswdstart
    
_wrongpasswd:
    mov eax, _write
    mov ebx, _stdout
    mov ecx, _wrong
    mov edx, _wronglen
    int 0x80
    
    jmp _die

_winner:
        mov eax, _write
        mov ebx, _stdout
        mov ecx, _right
        mov edx, _rightlen
        int 0x80

    jmp _die

_die: 
    mov eax, _exit
    xor ebx, ebx
    int 0x80

I've tried google, but found nothing on what im trying to do.
I want to compare byte by byte to see if the passwords are right. I'm just starting out on ASM so constructive criticism and useful pointers will be much appriciated.


rawr

Offline

#2 2006-10-18 14:56:27

phrakture
Arch Overlord
From: behind you
Registered: 2003-10-29
Posts: 7,879
Website

Re: [x86 ASM] CMP strings help

First off I want to say this:  if you are learning x86 assembly because it's "faster", you will NEVER be able to write assembly as well as gcc can.

That said, there is no generic "asm" - I'm going to guess you're using nasm though.

In nasm, and most assembly, you cannot index a variable with a register.  What you need to do is "Load the Effective Address" (lea):

lea ecx, [ebx+eax]
lea edx, [passwd+eax]
cmp ecx, edx

Offline

#3 2006-10-18 15:26:28

bboozzoo
Member
From: Poland
Registered: 2006-08-01
Posts: 125

Re: [x86 ASM] CMP strings help

If you still have problems, then write implementation in C and use gcc -S

Offline

#4 2006-10-18 15:38:40

chrismortimore
Member
From: Edinburgh, UK
Registered: 2006-07-15
Posts: 655

Re: [x86 ASM] CMP strings help

bboozzoo wrote:

If you still have problems, then write implementation in C and use gcc -S

That is well cool, never knew about that.

Anyway, just to say that I agree, there is little point learning assembler, unless (like me) you use it to program PICs (and such like) to simplify circuits.  High level languages are there to make life easy smile


Desktop: AMD Athlon64 3800+ Venice Core, 2GB PC3200, 2x160GB Maxtor DiamondMax 10, 2x320GB WD Caviar RE, Nvidia 6600GT 256MB
Laptop: Intel Pentium M, 512MB PC2700, 60GB IBM TravelStar, Nvidia 5200Go 64MB

Offline

#5 2006-10-18 18:00:52

phrakture
Arch Overlord
From: behind you
Registered: 2003-10-29
Posts: 7,879
Website

Re: [x86 ASM] CMP strings help

chrismortimore wrote:

Anyway, just to say that I agree, there is little point learning assembler, unless (like me) you use it to program PICs (and such like) to simplify circuits.

I disagree.  I think it's very good for those who want to know _how_ things work.  But writing actual programs in assembly is not a very good idea, unless it NEEDS to be assembly (see lrmi)

Offline

#6 2006-10-18 20:06:22

chrismortimore
Member
From: Edinburgh, UK
Registered: 2006-07-15
Posts: 655

Re: [x86 ASM] CMP strings help

phrakture wrote:

I disagree.  I think it's very good for those who want to know _how_ things work.  But writing actual programs in assembly is not a very good idea, unless it NEEDS to be assembly (see lrmi)

Sorry, I actually meant "using" instead of "learning".  I've been getting my words muddled all day...


Desktop: AMD Athlon64 3800+ Venice Core, 2GB PC3200, 2x160GB Maxtor DiamondMax 10, 2x320GB WD Caviar RE, Nvidia 6600GT 256MB
Laptop: Intel Pentium M, 512MB PC2700, 60GB IBM TravelStar, Nvidia 5200Go 64MB

Offline

Board footer

Powered by FluxBB