Search code examples
assemblyx86dosx86-16

Project Assembly -How To Add Mark to Project Assembly " Learning Vowel Letters" code?


This is my small project assembly code , about "earning Vowel Letters". It is working but the mark was not added when the questions ended. 5 questions and at latest at have to added mark but it doesn't add. For every right answer will added a mark.

page 1 : study
page 2: exam
page 3: exit

Just like this it working.

; multi-segment executable file template.

data segment                                                                                                                         
 firstpage db "learning Vowel letters e,o,a,i,u",10,13,"create by:alex",10,13,"1.stady",10,13,"2.exam",10,13,"3.exit" ,10,13,"$"
  std1 db "Umbrella  ----> an Umbrella" ,10,13,"$"
  std2 db "bird ----> a bird ",10,13,"$"
  std3 db "Ice cream ----> an Ice cream",10,13," $"
  std4 db "car----> a car ",10,13,"$"  
  std5 db "Orange ---->an Orange",10,13," $"

    qone db "desk ____ desk"   ,10,13,"a) a",10,13,"b) an",10,13,"$"
    qtow db "apple ____apple"   ,10,13,"a) a",10,13,"b) an",10,13,"$"
    qth db "table ____ table"  ,10,13,"a) a",10,13,"b) an",10,13,"$"
    qfo db "egg ____ egg"     ,10,13,"a) a",10,13,"b) an",10,13,"$"
    qfi db "red ____ red"     ,10,13,"a) a",10,13,"b) an",10,13,"$"  

    nl    db 0,10,13,"$"

   markze db "your mark is :0$"
   markone db "your mark is :10$" 
   marktow db "your mark is :40$" 
   markth db "your mark is :60$" 
   markfo db "your mark is :80$" 
   markfi db "your mark is :100$" 

   count db 0

ends

stack segment
    dw   128  dup(0)
ends                                
code segment
start:

    mov ax, data
    mov ds, ax

    lea dx, firstpage
    mov ah, 9
    int 21h           
    mov ah,7
    int 21h
    mov dl,al
    cmp dl,"1" 
    je  t1
    cmp dl,"2"
    je t2 
    cmp dl,"3"
    je soof 

 t1:  mov ax,3
    int 10h


    lea dx,std1
    mov ah,9
    int 21h
    mov ah,7
    int 21h


       lea dx,std2 
    mov ah ,9   
    int 21h
    mov ah,7
    int 21h

       lea dx,std3 
    mov ah,9
    int 21h
    mov ah,7
    int 21h


       lea dx,std4
    mov ah,9
    int 21h
    mov ah,7
    int 21h

       lea dx,std5
    mov ah,9
    int 21h
    mov ah,7
    int 21h   


    lea dx, firstpage
    mov ah, 9
    int 21h           
    mov ah,7
    int 21h



 t2:   mov ax,3
       int 10h

    lea dx ,qone
    mov ah,9
    int 21h 
    lea dx,nl
    mov ah,9
    int 21h
    mov ah,1
    int 21h
     mov ah,7
    int 21h

    mov bl,ah 
    cmp bl,"a"
    je c1 

    cmp bl,"b"
    je c0



       lea dx ,qtow

    mov ah,9
    int 21h 
    lea dx,nl
    mov ah,9
    int 21h
    mov ah,1
    int 21h


    mov bl,ah
    cmp bl,"b"
    je c2 

    cmp bl,"a"
    je c0





       lea dx ,qth
     mov ah,9
    int 21h 
    lea dx,nl
    mov ah,9
    int 21h
    mov ah,1
    int 21h
    mov bl,ah 

    cmp bl,"a"
    je c3

    cmp bl,"b"
    je c0





      lea dx ,qfo
    mov ah,9
    int 21h 

    lea dx,nl
    mov ah,9
    int 21h 

    mov ah,1
    int 21h



   mov bl,ah    
   cmp bl,"b"
   je c4

   cmp bl,"a"
   je c0



       lea dx ,qfi
     mov ah,9
    int 21h 
    lea dx,nl
    mov ah,9
    int 21h
    mov ah,1
    int 21h 

    mov bl,ah
    cmp bl,"a" 
    je c5
    cmp bl,"b"
    je c0  

 c0:
    cmp count,0
    je mark0 

 c1:
    cmp count,1
    je mark1


 c2:
    cmp count, 2
    je mark2

 c3:
    cmp count, 3
    je mark3 

 c4:
     cmp count,4
    je mark4

 c5:
    cmp count,5
    je mark5



 mark0:
       lea dx,markze
       mov ah,9
       int 21h
       jmp soof

 mark1:
       lea dx,markone
       mov ah,9
       int 21h
       jmp soof

 mark2:
       lea dx,marktow
       mov ah,9
       int 21h
       jmp soof 

 mark3:
       lea dx,markth
       mov ah,9
       int 21h
       jmp soof

 mark4:
       lea dx,markfo
       mov ah,9
       int 21h
       jmp soof
 mark5:
       lea dx,markfi
       mov ah,9
       int 21h
       jmp soof 




  soof:  mov ax, 4c00h 
    int 21h    
ends

end start 

Solution

  • nl    db 0,10,13,"$"
    

    I think that the answerer from My assembly "quiz Multiply" code is not working? rather meant you to write : nl db 10,13,"$" (without the zero/comma)


    Why this version doesn't work

    The input is wrong.

    mov ah,1
    int 21h
    mov ah,7
    int 21h
    mov bl,ah 
    

    Both these DOS functions input one character from the keyboard. Function 01h does it with echo and function 07h without echo.
    What neither function does is leaving the result in the AH register that you later copy to the BL register. The result is always only in the AL register. Of course you only need to include one of these functions here.

    mov ah, 01h
    int 21h
    mov bl, al 
    

    The program flow is wrong.

    cmp bl,"a"
    je c1
    cmp bl,"b"
    je c0
    lea dx ,qtow
    mov ah,9
    int 21h
    

    If the user gives the correct answer (a) to the first question, you jump away to c1 where you try to award a score and terminate the program.
    If the user gives the incorrect answer (b) to the first question, you jump away to c0 where you try to award a (zero) score and terminate the program.
    Only if the user provides an illegal input do you present them with a second question.
    Clearly the logic is faulty!

    What you should do is increment the count variable each time the correct answer was given. In code it means that you by-pass the inc instruction if the correct answer was not given.

        ...
        mov ah, 01h
        int 21h
        cmp al, "a"     ; Correct answer to 1st question
        jne Q2          ; was not given
        inc count
    Q2:
        lea dx, qtow
        mov ah, 09h
        int 21h
        mov ah, 01h
        int 21h
        cmp al, "b"     ; Correct answer to 2nd question
        jne Q3          ; was not given
        inc count
    Q3:
        lea dx, qth
        mov ah, 09h
        int 21h
        ...
    

    The part that deals with the fifth an last question can then fall through in the code that will print the mark on the screen.

        ...
    Q5:
        lea dx, qfi
        mov ah, 09h
        int 21h
        mov ah, 01h
        int 21h
        cmp al, "a"     ; Correct answer to 5th question
        jne c0          ; was not given
        inc count
    c0:
        ...