Johnny Afable
Johnny Afable

Reputation: 1

there is always an warning message and also when I type in the right student number it always show access denied

.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

Upvotes: 0

Views: 20

Answers (1)

Sep Roland
Sep Roland

Reputation: 39516

The reason that you're always receiving a warning about 'Access denied' is that when you compare the input for the user name / student number, you think that the username_buffer uses the $-termination. This is not the case! You have to store the $-character yourself once the user pressed the Enter key or the total of 20 characters was inputted.

To guarantee there's enough room to do this add 1 byte to your buffer:

username_buffer DB 20+1 DUP(?)      ; Buffer to store the username

Then use next improved code:

  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

A reasonable stack for a DOS program would be 512 bytes. 64 bytes is asking for trouble when you least expect them!

Upvotes: 0

Related Questions