Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Assembler Login With Password Compare Help!?

Status
Not open for further replies.

DaveyAPP

Programmer
Aug 3, 2007
2
GB
I am an asp.net developer but at current i need to make a simple assembler login which will ask the user for their username, then password, then confirm password and then output whether the passwords match. In short i am a total newbie to this language and struggling to understand it! Any help or tutorials that would help me to achieve the above would be great, i have been googling for a while and still struggling.

I do have the following code though, but sadly it doesnt work:
Thanks in advance =]

TITLE (comparinvariableshideinput.asm)

; This program reads 2 messages, compares the values and displays a message if they match or do not match

.model large ; specify a large memory model for this program
.stack 4096 ; allocate 4096 bytes to the stack
.386 ; use the 386 processor instruction set

.data ; define data variables used by the program

;DECLARE VARIABLES

msg byte "please enter your team-name" ; msg is of type byte and overflows to 19 bytes
msg2 byte 0dh,0ah,"$" ; msg is of type byte and includes line feed, carr return and terminate

msg3 byte 0dh,0ah
byte 0dh,0ah ; add line feed and carr return
byte "the team name entered was" ; add string as listed
byte 0dh,0ah,"$" ; add line feed and carr return and terminate char

msg6 byte 0dh,0ah
byte 0dh,0ah
byte "the team names entered do not match", "$"

msg8 byte 0dh,0ah
byte 0dh,0ah
byte "the team names entered match", "$"

char byte 00h ; allocate 0 to varable char
counter dw 0 ; delc

teamname1 byte 40 DUP ('$') ; define variable to store teamname1 with $
teamname2 byte 40 DUP ('$') ; define variable to store teamname2 with $

.code

; INITIALISE REGISTERS

main PROC
mov ax,SEG msg ; move the segment number used by msg into ax
mov ds,ax ; copy the segment number (ax) into ds (the data register used to store the segment used by this program)
mov ah,9 ; copy function 9 (display to screen) into the high bits of reg ax
mov dx,OFFSET msg ; copy the offset (within the segment in ds) of msg into dx (as dx req's offset within segment to start reading message)
int 21h ; generate interrupt and display message to the screen

xor cx,cx ; clear register cx
cld ; clear the direction flag
lea di,teamname1 ; load the effective address of teamname1 (segment + offset) into di so that we can write to it

; PROCESS AND TEST USER INPUT

EnterTeamname1:

mov ah,8 ; read a character, which is put in al or lower 8 bits of ax
int 21h

cmp al,1bh ; is the character <ESC>
je Maintenance
cmp al,0dh ; or <RET>
je Maintenance

mov [di],al ; store the character in the 1st 8 bits of the mem loc di is pointing at or start of buffer
inc di ; increment the index register, i.e. point to the next 8 bits to be written
jmp EnterTeamname1 ; loop

Maintenance:

xor cx,cx
cld
lea di,teamname2
; load teamname2

mov ah,9 ; copy function 9 (display to screen) into the high bits of reg ax
mov dx,OFFSET msg ; copy the offset (within the segment in ds) of msg into dx (as dx req's offset within segment to start reading message)
int 21h ; generate interrupt and display message to the screen

EnterTeamname2:

mov ah,8 ; read a character, which is put in al or lower 8 bits of ax, do not echo to the screen
int 21h

push ax ; store the value entered on the stack

mov ah,2
; display an exclamation mark on the screen, ascii for 21h

mov dl,21h
int 21h

pop ax ; retrieve the character entered

cmp al,1bh ; is the character <ESC>
je Comparison

cmp al,0dh ; or <RET>
je Comparison

mov [di],al ; store the character in the 1st 8 bits of the mem loc di is pointing at
inc di ; increment the index register, i.e. point to the next 8 bits
jmp EnterTeamName2 ; loop

Comparison:

lea di,teamname2 ; load the offset address password2
starts at into di

lea si,teamname1 ; load the offset address password1 starts at into si
xor cx,cx ; clear the cx register

CheckTeams:

mov al,ds:[di] ; copy the 1st character of teamname1 into al
mov bl,ds:[si] ; copy the 1st character of teamname2 into bl
cmp al,bl ; compare the values
jne TeamNamefail ; if the values are incorrect display error
inc di ; increment di to look at the next character in password
inc si ; increment si to look at the next character in password 2
inc cx ; increment the counter register cx
cmp cx,4 ; compare the counter to see if we have exceeded 4 characters
je TeamNameOK ; if we have got this far the first 4 characters match
jmp CheckTeams ; loop until we process 4 characters the rest are not compared

TeamNameOK:

mov ah,9
mov dx,OFFSET msg8 ; display message
int 21h
jmp Onward

TeamNameFail:

mov ah,9
mov dx,OFFSET msg6 ; display message
int 21h

Onward:

mov ah,9
mov dx,OFFSET msg3 ; display message
int 21h

mov ah,9
mov dx,OFFSET Teamname1 ; display teamname1
int 21h

mov ah,9
mov dx,OFFSET msg3 ; display teamname2
int 21h

mov ah,9
mov dx,OFFSET teamname2 ; display password 2
int 21h

mov ah,4ch ; terminate program
int 21h

main ENDP
END main
 
ignore the above, i fixed the program :)!
couldnt work out how to delete the post!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top