flat assembler
Message board for the users of flat assembler.

Index > Main > [strings + variables] Help with simple program i am writing

Author
Thread Post new topic Reply to topic
thor6136



Joined: 19 Dec 2011
Posts: 2
thor6136
Hey guys i am writing a program where it asks you for a password and if password is right then it says accepted and if it is wrong then it says denied, so here is the code: (dont bash me i am beginner Smile )

Code:

org 100h
        mov bx, 3                                ; used for describing how many inserted characters were equal to our password
        mov cx, 3                                ; used for describing how many loops will it take, since our password is 3 characters long it takes 3 turns
        mov ah, 09h                            
        mov dx, insert_password
        int 21h

        i=0


w_password:                                      ; this part compares if character imputed by the user is equal to character in password
        mov si, password+i                   
        mov ah, 08h
        int 21h
        mov [di], al
        mov al, [si]
        cmp al, [di]
        je t
        jne f

t:
        i=i+1                                        ; this is the part that it doesn't work, here i is not increased it always stays 0
        dec bx
        call cx_register

f:
        call cx_register                           ; since character was wrong it doesn't need to do anything

cx_register:                                        ; this part decreases cx (cx value = lenght of password) 
        dec cx
        jz compare
        jnz w_password


compare:                                           ; at the end it compares if bx is 0 (if it is all characters were equal)
        cmp bx, 0
        je true_m
        jne false_m

true_m:
        mov ah, 09h
        mov dx, true
        int 21h

        mov ah, 08h
        int 21h
        int 20h

false_m:
        mov ah, 09h
        mov dx, false
        int 21h

        mov ah, 08h
        int 21h
        int 20h


insert_password: db 'Insert password: ',24h
false: db 'false',24h
true: db 'true',24h
password: db 'asd'       
    

    


So i hope you understand, my english is not really good and i am sorry. So basically i want program to check each turn if character that was inputed is the same as in password and if it is than password that was inputed by the user is accepted and if not it was denied. But i am stuck with the part where it has to check for the 2nd and 3rd character in password. It only checks the first one, if you look at the code i is not increased, it stays 0.
Post 19 Dec 2011, 22:35
View user's profile Send private message Reply with quote
JohnFound



Joined: 16 Jun 2003
Posts: 3502
Location: Bulgaria
JohnFound
use "inc si" and "inc di" instead of i=i+1.
You don't need "i" here at all. There is no variables in this meaning in assembly language. "si" and "di" are your variables here.
Post 19 Dec 2011, 22:45
View user's profile Send private message Visit poster's website ICQ Number Reply with quote
DOS386



Joined: 08 Dec 2006
Posts: 1901
DOS386
Your "i" is a variable, but it exists at compile time only ... and has no effect ! Shocked
Post 13 Jan 2012, 08:45
View user's profile Send private message Reply with quote
typedef



Joined: 25 Jul 2010
Posts: 2913
Location: 0x77760000
typedef
try this simple snippet
Code:
password db 'pass1234'
input       db 8 dup(0)

[...]    ;<-- Get the password here

mov  cx,   8  ;<---- strlen(password)
lea    esi,  [password]
lea    edi,  [input]
repe  compsb

jne    not_equal

[...]    ; valid password

    
Post 13 Jan 2012, 15:42
View user's profile Send private message Reply with quote
thor6136



Joined: 19 Dec 2011
Posts: 2
thor6136
typedef wrote:
try this simple snippet
Code:
password db 'pass1234'
input       db 8 dup(0)

[...]    ;<-- Get the password here

mov  cx,   8  ;<---- strlen(password)
lea    esi,  [password]
lea    edi,  [input]
repe  compsb

jne    not_equal

[...]    ; valid password

    


Can you tell me what exactly is dup(0), and lea esi, edi
Post 24 Feb 2012, 22:16
View user's profile Send private message Reply with quote
AsmGuru62



Joined: 28 Jan 2004
Posts: 1412
Location: Toronto, Canada
AsmGuru62
dup means duplicate.
Value in brackets is a value to be used to initialize memory.
The following code:
Code:
input db 8 dup(0)    

is equivalent to this:
Code:
input db 0,0,0,0,0,0,0,0    

LEA instruction is used to Load Executive Address into a register:
Code:
LEA ESI,[password]    

In this ^^^ case ESI will have an address of a 1st byte in 'password'.
Post 25 Feb 2012, 00:53
View user's profile Send private message Send e-mail Reply with quote
DOS386



Joined: 08 Dec 2006
Posts: 1901
DOS386
> LEA ESI,[password]
> In this ^^^ case ESI will have an address of a 1st byte in 'password'

The ZERO'th Byte Wink

LEA makes sense if your buffer is local ... so password translates into something like "EBP+8" for example ... otherwise use MOV:

Code:
MOV ESI, password ; constant
MOV ESI, EAX      ; from other register
    
Post 03 Mar 2012, 08:24
View user's profile Send private message Reply with quote
shutdownall



Joined: 02 Apr 2010
Posts: 518
Location: Munich
shutdownall
Anyway it is not good to store a password in plain text in the program (which maybe watched with a hex editor easily). Better to just store a hash value and compare with a hash value from the input. MD5 is an often used hash mechanism.
Post 03 Mar 2012, 17:54
View user's profile Send private message Send e-mail 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. Also on YouTube, Twitter.

Website powered by rwasa.