.model small
.stack 64
.data
.data
username_buffer DB 20 DUP(?) ; Buffer to store the username
prompt_username DB "Enter your username: $"
msg_wrong_username DB "Wrong username entered. Access denied.$"
correct_username DB 'A21-31312$'
fullname label byte
maxfullname db 50
curfullname db ?
fullnamefield db 50 dup(?)
cors label byte
maxcors db 50
curcors db ?
corsfield db 50 dup(?)
newline db 13, 10, "$"
msg_header db "Manuel S. Enverga University Foundation",13,10,"$"
msg_header2 db "Lucena City",13,10,"$"
msg_fullname db "Name: $"
msg_studnum db "Student Number: $"
msg_cors db "Course/ Year: $"
menu db "MAIN MENU",13,10,"$"
mission db "[M]ission", 13,10,"$"
vision db "[V]ision", 13,10,"$"
goal db "[G]oal", 13,10,"$"
core_values db "[C]ore Values", 13,10, "$"
resume db "[R]esume", 13,10,"$"
msg_exit db "[E]xit", 13,10,"$"
choice db "Enter your choice: $"
passwordd db "Password:",13,10,"$"
accept db "Code Accepted:",13,10,"$"
denied db "Error Message: ",13,10,"$"
denied2 db "***Unauthorized User***$",13,10,"$"
invalid_choice db "Invalid choice, try again.", 13, 10, "$"
invalid_studnum db "Invalid Student Number. Please try again.", 13, 10, "$"
mission_msg db "Mission: In 2030, the Manuel S. Enverga University Foundation is a globally competitive university with high concentrations of talent, excellent teaching environment, rigorous program quality, sufficient resources, and a culture of collaboration.", 13, 10, "Press R to resume", 13, 10, "$"
vision_msg db "Vision: The Manuel S. Enverga University Foundation is a private, non-stock, non-profit, non-sectarian educational foundation with a three-fold function – instruction, research and community service – offering responsive and alternative programs supportive of national development goals and standards of global excellence.", 13, 10, "Press R to resume", 13, 10, "$"
goal_msg db "Goal: The Manuel S. Enverga University Foundation shall produce graduates who have research-based knowledge, leadership and managerial skills, and professionalism.", 13, 10, "Press R to resume", 13, 10, "$"
core_values_msg db "Core Values: MINDFULNESS, SERVICE, EXCELLENCE, UNITY, FORTITUDE", 13, 10, "Press R to resume", 13, 10, "$"
.code
begin:
mov ax, @data
mov ds, ax
start:
call clrs
mov ah, 02h ;aligning
mov bh, 00
mov dh, 11
mov dl, 27
int 10h
; Display prompt for username
MOV AH, 09h
MOV DX, OFFSET prompt_username
INT 21h
; Read username characters
MOV SI, OFFSET username_buffer ; Initialize SI to point to the username buffer
MOV CX, 20 ; Set CX to the maximum number of characters to read
read_username:
MOV AH, 01h ; Read a single character input
INT 21h
CMP AL, 0Dh ; Check for carriage return
JE end_username ; Exit loop if carriage return is encountered
MOV [SI], AL ; Store the input character in the buffer
INC SI ; Move to the next position in the buffer
LOOP read_username ; Repeat until all characters are read
end_username:
; Compare entered username with correct username
MOV SI, OFFSET username_buffer ; Initialize SI to point to the entered username
MOV DI, OFFSET correct_username ; Initialize DI to point to the correct username
compare_username:
MOV AL, [SI] ; Load a byte from the entered username
CMP AL, [DI] ; Compare it with the corresponding byte in the correct username
JNE wrong_username ; Jump if they don't match
INC SI ; Move to the next character in the entered username
INC DI ; Move to the next character in the correct username
CMP AL, '$' ; Check if end of entered username is reached
JE username_correct ; Jump if end of entered username is reached
JMP compare_username ; Repeat until end of entered username is reached
username_correct:
JMP password
; Jump to password input section
; You can add the password input section here
; Exit program
MOV AH, 4Ch
INT 21h
wrong_username:
call clrs
; Display wrong username message
mov ah, 02h ;aligning
mov bh, 00
mov dh, 12
mov dl, 20
int 10h
mov ah, 09h
mov dx, offset msg_wrong_username
int 21h
mov ah, 07h
int 21h
cmp al, "1"
mov ah, 02h
mov dl, " "
int 21h
jmp right1
jne wrong1
jmp start
wrong1:
jmp start
right1:
jmp start
password:
mov ah, 02h ;aligning
mov bh, 00
mov dh, 12
mov dl, 27
int 10h
mov ah, 09h
mov dx, offset passwordd
int 21h
mov ah, 02h ;aligning
mov bh, 00
mov dh, 12
mov dl, 36
int 10h
mov ah, 07h ;ask input
int 21h
cmp al, "1"
mov ah, 02h
mov dl, "*"
int 21h
mov ah, 07h
int 21h
cmp al, "2"
mov ah, 02h
mov dl, "*"
int 21h
mov ah, 07h
int 21h
cmp al, "3"
mov ah, 02h
mov dl, "*"
int 21h
mov ah, 07h
int 21h
cmp al, "4"
mov ah, 02h
mov dl, "*"
int 21h
jne incorrect
jmp correct
incorrect:
call clrs
mov ah, 02h ;aligning
mov bh, 00
mov dh, 11
mov dl, 21
int 10h
mov ah, 09h
mov dx, offset denied
int 21h
mov ah, 02h ;aligning
mov bh, 00
mov dh, 12
mov dl, 20
int 10h
mov ah, 09h
mov dx, offset denied2
int 21h
mov ah, 07h
int 21h
cmp al, "1"
mov ah, 02h
mov dl, " "
int 21h
jmp right
jne wrong
jmp start
wrong:
jmp start
right:
jmp start
correct:
call clrs
mov ah, 02h ;aligning
mov bh, 00
mov dh, 11
mov dl, 27
int 10h
mov ah , 9h ;for Name
mov dx, offset msg_fullname
int 21h
mov ah, 0ah
mov dx, offset fullname
int 21h
mov bx, 0
mov bl, curfullname
mov fullnamefield[bx],"$"
mov ah, 02h ;aligning
mov bh, 00
mov dh, 12
mov dl, 27
int 10h
mov ah , 9h ;for cors
mov dx, offset msg_cors
int 21h
mov ah, 0ah
mov dx, offset cors
int 21h
mov bx, 0
mov bl, curcors
mov corsfield[bx],"$"
main_menu:
call clrs
mov ah, 02h ; HEADER!!!
mov bh, 00
mov dh, 05
mov dl, 23
int 10h
mov ah, 9h
mov dx, offset msg_header
int 21h
mov ah, 02h ;aligning
mov bh, 00
mov dh, 06
mov dl, 35
int 10h
mov ah, 9h
mov dx, offset msg_header2
int 21h
mov ah, 02h ;aligning
mov bh, 00
mov dh, 08
mov dl, 55
int 10h
mov ah, 9h
mov dx, offset msg_studnum
int 21h
mov ah, 9h
mov dx, offset username_buffer
int 21h
mov ah, 02h ;aligning
mov bh, 00
mov dh, 09
mov dl, 00
int 10h
mov ah, 9h
mov dx, offset msg_fullname
int 21h
mov ah, 9h
mov dx, offset fullnamefield
int 21h
mov ah, 9h
mov dx, offset newline
int 21h
mov ah, 9h
mov dx, offset msg_cors
int 21h
mov ah, 9h
mov dx, offset corsfield
int 21h
mov ah, 02h ;aligning
mov bh, 00
mov dh, 13
mov dl, 34
int 10h
mov ah, 9h
mov dx, offset menu
int 21h
mov ah, 02h ;aligning
mov bh, 00
mov dh, 14
mov dl, 31
int 10h
mov ah, 9h
mov dx, offset mission
int 21h
mov ah, 02h ;aligning
mov bh, 00
mov dh, 15
mov dl, 31
int 10h
mov ah, 9h
mov dx, offset vision
int 21h
mov ah, 02h ;aligning
mov bh, 00
mov dh, 16
mov dl, 31
int 10h
mov ah, 9h
mov dx, offset goal
int 21h
mov ah, 02h ;aligning
mov bh, 00
mov dh, 17
mov dl, 31
int 10h
mov ah, 9h
mov dx, offset core_values
int 21h
mov ah, 02h ;aligning
mov bh, 00
mov dh, 18
mov dl, 31
int 10h
mov ah, 9h
mov dx, offset resume
int 21h
mov ah, 02h ;aligning
mov bh, 00
mov dh, 19
mov dl, 31
int 10h
mov ah, 9h
mov dx, offset msg_exit
int 21h
mov ah, 02h ;aligning
mov bh, 00
mov dh, 20
mov dl, 31
int 10h
mov ah, 9h
mov dx, offset choice
int 21h
; Get user input and handle choices
mov ah, 07h
int 21h
cmp al, 'm'
je show_mission
cmp al, 'M'
je show_mission
cmp al, 'v'
je show_vision
cmp al, 'V'
je show_vision
cmp al, 'g'
je show_goal
cmp al, 'G'
je show_goal
cmp al, 'c'
je show_core_values
cmp al, 'C'
je show_core_values
cmp al, 'r'
je show_resume
cmp al, 'R'
je show_resume
cmp al, 'e'
je exit_program
cmp al, 'E'
je exit_program
jmp invalid_selection
show_mission:
call clrs
mov ah, 02h ;aligning
mov bh, 00
mov dh, 11
mov dl, 00
int 10h
mov ah, 09h
mov dx, offset mission_msg
int 21h
call wait_for_exit
jmp main_menu
show_vision:
call clrs
mov ah, 02h ;aligning
mov bh, 00
mov dh, 11
mov dl, 00
int 10h
mov ah, 09h
mov dx, offset vision_msg
int 21h
call wait_for_exit
jmp main_menu
show_goal:
call clrs
mov ah, 02h ;aligning
mov bh, 00
mov dh, 11
mov dl, 00
int 10h
mov ah, 09h
mov dx, offset goal_msg
int 21h
call wait_for_exit
jmp main_menu
show_core_values:
call clrs
mov ah, 02h ;aligning
mov bh, 00
mov dh, 11
mov dl, 00
int 10h
mov ah, 09h
mov dx, offset core_values_msg
int 21h
call wait_for_exit
jmp main_menu
show_resume:
call clrs
; Display resume information here
call wait_for_exit
jmp main_menu
exit_program:
mov ah, 4ch
int 21h
invalid_selection:
call clrs
mov ah, 09h
mov dx, offset invalid_choice
int 21h
jmp main_menu
wait_for_exit proc
mov ah, 07h
wait_loop:
int 21h
cmp al, 'R'
jne wait_loop
ret
wait_for_exit endp
clrs proc
mov ax, 0600h
mov bh, 07h
mov cx, 0000h
mov dx, 184fh
int 10h
ret
clrs endp
end begin
您总是收到有关“访问被拒绝”的警告的原因是,当您比较用户名/学号的输入时,您认为username_buffer使用$-终止符。不是这种情况! 一旦用户按下 Enter 键或输入了总共 20 个字符,您就必须自己存储 $ 字符。
为了保证有足够的空间来执行此操作,请向缓冲区添加 1 个字节:
username_buffer DB 20+1 DUP(?) ; Buffer to store the username
然后使用下一个改进的代码:
MOV SI, OFFSET username_buffer
MOV CX, 20 ; Maximum number of characters to read
read_username:
MOV AH, 01h ; Read a single character input
INT 21h
CMP AL, 0Dh ; Check for carriage return
JE end_username ; Exit loop if carriage return is encountered
MOV [SI], AL
INC SI
LOOP read_username
end_username:
mov byte ptr [si], "$" <<<< Add terminator yourself
; Compare entered username with correct username
MOV SI, OFFSET username_buffer
MOV DI, OFFSET correct_username
compare_username:
MOV AL, [SI]
CMP AL, [DI]
JNE wrong_username ; Jump if they don't match
INC SI
INC DI
CMP AL, '$' ; Check if end of entered username is reached
jne compare_username <<<< Repeat while not at end of username
username_correct:
.stack 64
对于 DOS 程序来说,合理的堆栈大小是 512 字节。 64 字节会在你最意想不到的时候自找麻烦!