| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 668 人关注过本帖, 1 人收藏
标题:口令识别
只看楼主 加入收藏
屁洞
Rank: 1
等 级:新手上路
帖 子:7
专家分:0
注 册:2010-10-6
结帖率:100%
收藏(1)
已结贴  问题点数:20 回复次数:3 
口令识别
题目:
设计一个程序,实现用户口令验证功能,程序中预先设置好若干个用户的帐号信息(包括用户名和口令)。
程序执行后,给出简单明了的操作提示,请用户输入用户名和口令。当用户键入的帐号信息与程序内置的某个用户帐号一致时,给出欢迎信息,否则给出拒绝信息。

我的代码:
DATA SEGMENT

n equ 20
buf1 db n+1
count1 db 0
string1 db n+1 dup('$')
buf2 db n+1
count2 db 0
string2 db n+1 dup('$')

C0 DB 0DH,0AH,"$"
C1 DB "please input the username: $"
C2 DB "please input the code: $"
C3 DB "welcome!",0DH,0AH,"$"
C4 DB "error!",0DH,0AH,"$"

S1 DB "hello$"
N1 EQU 5
T1 DB "hello08$"
M1 EQU 7

S2 DB "world$"
N2 EQU 5
T2 DB "world08$"
M2 EQU 7

S3 DB "lidong$"
N3 EQU 6
T3 DB "lidong08$"
M3 EQU 8

DATA ENDS

STACK SEGMENT STACK
DB 100 DUP(?)
STACK ENDS

CODE SEGMENT
ASSUME CS:CODE,DS:DATA,SS:STACK

START:
mov ax, DATA
mov ds, ax
mov ah, 09h
mov dx, offset C1
int 21h
lea dx, buf1
mov ah, 0ah
int 21h
lea dx, C0
mov ah, 09h
int 21h
mov ah, 09h
mov dx, offset C2
int 21h
lea dx, buf2
mov ah, 0ah
int 21h
lea dx, C0
mov ah, 09h
int 21h
mov al, count1
mov bl, count2

mov cx, 0
cmp al, N1
jnz L1
lea di, string1
lea si, S1
mov cl, al
repz cmpsb
jnz L1

mov cx, 0
cmp bl, M1
jnz L1
lea di, string2
lea si, T1
mov cl, bl
repz cmpsb
jnz L1
jmp right

L1:
cmp al, N2
jnz L2
lea di, string1
lea si, S2
mov cl, al
repz cmpsb
jnz L2

cmp bl, M2
jnz L2
lea di, string2
lea si, T2
mov cl, bl
repz cmpsb
jnz L2
jmp right

L2:
cmp al, N3
jnz wrong
lea di, string1
lea si, S3
mov cl, al
repz cmpsb
jnz wrong

cmp bl, M3
jnz wrong
lea di, string2
lea si, T3
mov cl, bl
repz cmpsb
jnz wrong
jmp right

wrong:
mov ah, 09h
mov dx, offset C4
int 21h
jmp end1

right:
mov ah, 09h
mov dx, offset C3
int 21h
jmp end1

end1:
mov ah, 09h
mov dx, offset string2
int 21h
mov ah, 4ch
int 21h

code ends
end start

结果:
编译连接均正确,生成了有效的exe文件,可是结果总是不对,我输入用户名为hello,密码为hello08,结果总是error!
请各位大虾帮帮我,程序是哪里错了,谢谢~
搜索更多相关主题的帖子: 口令 
2010-10-20 21:10
xiaomarn
Rank: 11Rank: 11Rank: 11Rank: 11
等 级:小飞侠
威 望:5
帖 子:348
专家分:2026
注 册:2009-3-18
收藏
得分:20 
DATA SEGMENT

n equ 20
buf1 db n+1
count1 db 0
string1 db n+1 dup('$')
buf2 db n+1
count2 db 0
string2 db n+1 dup('$')

C0 DB 0DH,0AH,"$"
C1 DB "please input the username: $"
C2 DB "please input the code: $"
C3 DB "welcome!",0DH,0AH,"$"
C4 DB "error!",0DH,0AH,"$"

S1 DB "hello$"
N1 EQU 5
T1 DB "hello08$"
M1 EQU 7

S2 DB "world$"
N2 EQU 5
T2 DB "world08$"
M2 EQU 7

S3 DB "lidong$"
N3 EQU 6
T3 DB "lidong08$"
M3 EQU 8

DATA ENDS

STACK SEGMENT STACK
DB 100 DUP(?)
STACK ENDS

CODE SEGMENT
ASSUME CS:CODE,DS:DATA,SS:STACK

START:
mov ax, DATA
mov ds, ax
mov es,ax            ;key!,di的段寄存器是es,使它们指向同一个段就行了(数据在同一个段)

mov ah, 09h
mov dx, offset C1
int 21h
lea dx, buf1
mov ah, 0ah
int 21h
lea dx, C0
mov ah, 09h
int 21h
mov ah, 09h
mov dx, offset C2
int 21h
lea dx, buf2
mov ah, 0ah
int 21h
lea dx, C0
mov ah, 09h
int 21h
mov al, count1
mov bl, count2

mov cx, 0
cmp al, N1
jnz L1
lea di, string1
lea si, S1
mov cl, al
repz cmpsb
jnz L1

mov cx, 0
cmp bl, M1
jnz wrong
lea di, string2
lea si, T1
mov cl, bl
repe cmpsb
jnz wrong
jmp right

L1:
cmp al, N2
jnz L2
lea di, string1
lea si, S2
mov cl, al
repz cmpsb
jnz L2

cmp bl, M2
jnz L2
lea di, string2
lea si, T2
mov cl, bl
repz cmpsb
jnz L2
jmp right

L2:
cmp al, N3
jnz wrong
lea di, string1
lea si, S3
mov cl, al
repz cmpsb
jnz wrong

cmp bl, M3
jnz wrong
lea di, string2
lea si, T3
mov cl, bl
repz cmpsb
jnz wrong
jmp right

wrong:
mov ah, 09h
mov dx, offset C4
int 21h
jmp end1

right:
mov ah, 09h
mov dx, offset C3
int 21h
jmp end1

end1:
mov ah, 09h
mov dx, offset string2
int 21h
mov ah, 4ch
int 21h

code ends
end start
2010-10-21 19:56
屁洞
Rank: 1
等 级:新手上路
帖 子:7
专家分:0
注 册:2010-10-6
收藏
得分:0 
回复 2楼 xiaomarn
多谢高手指点!!!!长知识了!我太粗心了~下次改正!还有能再请教你我的另一个“数制转换”的题吗?在另一个贴里,X86有直接输出十进制数的dos调用功能吗?(09h功能是输出字符串,可是我想输出内存或寄存器中的数应该如何实现呢?一定要转换为ASCII字符串输出吗?)谢谢~

love Thailand forever
2010-10-21 22:50
husiwen
Rank: 9Rank: 9Rank: 9
等 级:蜘蛛侠
威 望:2
帖 子:227
专家分:1125
注 册:2010-5-23
收藏
得分:0 
回复 3楼 屁洞
用移位shl   移出进位位上的0或1加上20H(转成0和1的asc)再用2号功能显示出来
2010-11-13 18:17
快速回复:口令识别
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.015691 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved