Home > Enterprise >  Subject reviewer quiz with wrong total points
Subject reviewer quiz with wrong total points

Time:01-21

I am creating a basic quiz program in assembly language. I am planning to deduct if the answer is wrong and add 1 point if it is correct. My output is not accurate. I always get the wrong total points.

org 100h

.data

MSG1 DB '..........WELCOME TO SUBJECT REVIEWER SYSTEM..........$'
MSG2 DB 'RULES : $'
MSG3 DB 'FOR EVERY CORRECT PLUS 1 POINT $'
MSG4 DB 'FOR EVERY INCORRECT MINUS 1 POINT $'   
MSG5 DB 'PRESS ENTER TO START THE QUIZ : $'
MSG6 DB 'RIGHT ANSWER $'
MSG7 DB 'WRONG ANSWER $'
MSG8 DB 'YOU SUCCESSFULLY COMPLETED THE QUIZ $'
MSG9 DB 'YOUR TOTAL POINTS IS: $'
MSG10 DB 'PRESS 1 TO REATTEMPT QUIZ $'
MSG11 DB '*******THANK YOU******* $'
Q1 DB '1. 1 1=? $'
QA1 DB 'A) 2 B) 5 C) 23 $' 
Q2 DB '2. 1 1=? $'
QA2 DB 'A) 3 B) 2 C) 65 $'
Q3 DB '3. 1 1=? $'
QA3 DB 'A) 2 B) 44 C) 23 $'
Q4 DB '4. 1 1=? $'
QA4 DB 'A) 2 B) 5 C) 45 $'
Q5 DB '5. 1 1=? $'
QA5 DB 'A) 2 B) 5 C) 56 $'
Q6 DB '6. 1 1=? $'
QA6 DB 'A) 2 B) 4 C) 5 $'
Q7 DB '7. 1 1=? $'
QA7 DB 'A) 2 B) 5 C) 23 $'
Q8 DB '8. 1 1=? $'
QA8 DB 'A) 2 B) 5 C) 7 $'
Q9 DB '9. 1 1=? $'
QA9 DB 'A) 2 B) 5 C) 23 $'
Q10 DB '10. 1 1=? $'
QA10 DB 'A) 2 B) 5 C) 4 $'

.code      
MAIN PROC
    
    MOV AX,@DATA
    MOV DS,AX
    
    LEA DX,MSG1
    MOV AH,9
    INT 21H
    
    CALL NL 
    
    LEA DX,MSG2
    MOV AH,9
    INT 21H

    CALL NL  
    
    LEA DX,MSG3
    MOV AH,9
    INT 21H

    CALL NL 
    
    LEA DX,MSG4
    MOV AH,9
    INT 21H

    CALL NL   
    
    START:
    MOV BL, 0  
    CALL NL 
    
    LEA DX,MSG5
    MOV AH,9
    INT 21H

    MOV AH, 1
    INT 21H
    
    CMP AL, 0DH
    JE QSN1
    JNE START
    
    QSN1:
    CALL NL
    
    LEA DX,Q1
    MOV AH,9
    INT 21H  
    
    CALL NL
    
    LEA DX,QA1
    MOV AH,9
    INT 21H  
    
    CALL NL
    
    
    MOV AH, 1
    INT 21H
    CMP AL, 'A'
    JE QSN2
    JNE QSNW2
    
    
    QSN2:
    CALL NL
    
    LEA DX,MSG6
    MOV AH,9
    INT 21H  
    
    INC BL
    CALL NL
    
    CALL QN2
    
    CALL INPUT
    
    CMP AL, 'B'
    JE QSN3
    JNE QSNW3
    
    QSNW2:
    CALL NL
    
    LEA DX,MSG7
    MOV AH,9
    INT 21H  
    
    INC BL
    CALL NL
    
    CALL QN2
    
    CALL INPUT
    
    CMP AL, 'A'
    JE QSN3
    JNE QSNW3
    
    
    ; Q3
    
    QSN3:
    CALL NL
    
    LEA DX,MSG6
    MOV AH,9
    INT 21H  
    
    INC BL
    CALL NL
    
    CALL QN3
    
    CALL INPUT
    
    CMP AL, 'A'
    JE QSN4
    JNE QSNW4
    
    QSNW3:
    CALL NL
    
    LEA DX,MSG7
    MOV AH,9
    INT 21H  
    
    INC BL
    CALL NL
    
    CALL QN3
    
    CALL INPUT
    
    CMP AL, 'A'
    JE QSN4
    JNE QSNW4   
    
    
    ; Q4
    
    QSN4:
    CALL NL
    
    LEA DX,MSG6
    MOV AH,9
    INT 21H  
    
    INC BL
    CALL NL
    
    CALL QN4
    
    CALL INPUT
    
    CMP AL, 'A'
    JE QSN5
    JNE QSNW5
    
    QSNW4:
    CALL NL
    
    LEA DX,MSG7
    MOV AH,9
    INT 21H  
    
    INC BL
    CALL NL
    
    CALL QN4
    
    CALL INPUT
    
    CMP AL, 'A'
    JE QSN5
    JNE QSNW5
    
    ; Q5
    
    
    QSN5:
    CALL NL
    
    LEA DX,MSG6
    MOV AH,9
    INT 21H  
    
    INC BL
    CALL NL
    
    CALL QN5
    
    CALL INPUT
    
    CMP AL, 'A'
    JE QSN6
    JNE QSNW6
    
    QSNW5:
    CALL NL
    
    LEA DX,MSG7
    MOV AH,9
    INT 21H  
    
    INC BL
    CALL NL
    
    CALL QN5
    
    CALL INPUT
    
    CMP AL, 'A'
    JE QSN6
    JNE QSNW6
    
    
    ; Q6
    
    
    QSN6:
    CALL NL
    
    LEA DX,MSG6
    MOV AH,9
    INT 21H  
    
    INC BL
    CALL NL
    
    CALL QN6
    
    CALL INPUT
    
    CMP AL, 'A'
    JE QSN7
    JNE QSNW7
    
    QSNW6:
    CALL NL
    
    LEA DX,MSG7
    MOV AH,9
    INT 21H  
    
    INC BL
    CALL NL
    
    CALL QN6
    
    CALL INPUT
    
    CMP AL, 'A'
    JE QSN7
    JNE QSNW7
    
    
    ; Q7
    
    
    QSN7:
    CALL NL
    
    LEA DX,MSG6
    MOV AH,9
    INT 21H  
    
    INC BL
    CALL NL
    
    CALL QN7
    
    CALL INPUT
    
    CMP AL, 'A'
    JE QSN8
    JNE QSNW8
    
    QSNW7:
    CALL NL
    
    LEA DX,MSG7
    MOV AH,9
    INT 21H  
    
    INC BL
    CALL NL
    
    CALL QN7
    
    CALL INPUT
    
    CMP AL, 'A'
    JE QSN8
    JNE QSNW8
    
    
    ; Q8
    
    
    QSN8:
    CALL NL
    
    LEA DX,MSG6
    MOV AH,9
    INT 21H  
    
    INC BL
    CALL NL
    
    CALL QN8
    
    CALL INPUT
    
    CMP AL, 'A'
    JE QSN9
    JNE QSNW9
    
    QSNW8:
    CALL NL
    
    LEA DX,MSG7
    MOV AH,9
    INT 21H  
    
    INC BL
    CALL NL
    
    CALL QN8
    
    CALL INPUT
    
    CMP AL, 'A'
    JE QSN9
    JNE QSNW9 
    
    
    
    ; Q9
    
    
    QSN9:
    CALL NL
    
    LEA DX,MSG6
    MOV AH,9
    INT 21H  
    
    INC BL
    CALL NL
    
    CALL QN9
    
    CALL INPUT
    
    CMP AL, 'A'
    JE QSN10
    JNE QSNW10
    
    QSNW9:
    CALL NL
    
    LEA DX,MSG7
    MOV AH,9
    INT 21H  
    
    INC BL
    CALL NL
    
    CALL QN9
    
    CALL INPUT
    
    CMP AL, 'A'
    JE QSN10
    JNE QSNW10 
    
    
    ; Q10
    
    
    QSN10:
    CALL NL
    
    LEA DX,MSG6
    MOV AH,9
    INT 21H  
    
    INC BL
    CALL NL
    
    CALL QN10
    
    CALL INPUT
    
    CMP AL, 'A'
    JE EXIT
    JNE EXITW
    
    QSNW10:
    CALL NL
    
    LEA DX,MSG7
    MOV AH,9
    INT 21H  
    
    DEC BL
    CALL NL
    
    CALL QN10
    
    CALL INPUT
    
    CMP AL, 'A'
    JE EXIT
    JNE EXITW
    
    EXIT:
    CALL NL
    
    LEA DX, MSG6
    MOV AH,9
    INT 21H
    
    INC BL
    CALL NL
    CALL NL
    
    LEA DX, MSG8
    MOV AH,9
    INT 21H
    
    CALL NL
    
    LEA DX, MSG9
    MOV AH,9
    INT 21H
    
     
    ADD BL, 48
    
    CMP BL,57
    JG TEN
    MOV AH, 2
    MOV DL, BL
    INT 21H
    JMP EXIT1
    
    EXITW:
    CALL NL
    
    LEA DX, MSG7
    MOV AH,9
    INT 21H
    
    DEC BL
    CALL NL
    CALL NL
    
    LEA DX, MSG8
    MOV AH,9
    INT 21H
    
    CALL NL
    CALL NL
    
    LEA DX, MSG9
    MOV AH,9
    INT 21H
    
    ADD BL,48
    MOV AH,2
    MOV DL, BL
    INT 21H
    
    JMP EXIT1
    
    TEN:
    MOV AH,2
    MOV DL,"1"
    INT 21H
    MOV DL, "0"
    INT 21H
    JMP EXIT1
    
    NL:
    MOV AH,2
    MOV DL, 0AH
    INT 21H
    MOV DL, 0DH
    INT 21H
    RET
    
    QN2:
    LEA DX,Q2
    MOV AH,9
    INT 21H
    
    CALL NL
    
    LEA DX,QA2
    MOV AH,9
    INT 21H
    RET
    
    QN3:
    LEA DX,Q3
    MOV AH,9
    INT 21H
    
    CALL NL
    
    LEA DX,QA3
    MOV AH,9
    INT 21H
    RET
    
    QN4:
    LEA DX,Q4
    MOV AH,9
    INT 21H
    
    CALL NL
    
    LEA DX,QA4
    MOV AH,9
    INT 21H
    RET
    
    
    QN5:
    LEA DX,Q5
    MOV AH,9
    INT 21H
    
    CALL NL
    
    LEA DX,QA5
    MOV AH,9
    INT 21H
    RET

    
    QN6:
    LEA DX,Q6
    MOV AH,9
    INT 21H
    
    CALL NL
    
    LEA DX,QA6
    MOV AH,9
    INT 21H
    RET


    
    QN7:
    LEA DX,Q7
    MOV AH,9
    INT 21H
    
    CALL NL
    
    LEA DX,QA7
    MOV AH,9
    INT 21H
    RET
    
    
    QN8:
    LEA DX,Q8
    MOV AH,9
    INT 21H
    
    CALL NL
    
    LEA DX,QA8
    MOV AH,9
    INT 21H
    RET 
    
    
    QN9:
    LEA DX,Q9
    MOV AH,9
    INT 21H
    
    CALL NL
    
    LEA DX,QA9
    MOV AH,9
    INT 21H
    RET
    
    
    QN10:
    LEA DX,Q10
    MOV AH,9
    INT 21H
    
    CALL NL
    
    LEA DX,QA10
    MOV AH,9
    INT 21H
    RET 
    
    
    INPUT:
    CALL NL
    
    MOV AH, 1
    INT 21H
    RET
    
    EXIT1:
    CALL NL
    CALL NL
    
    LEA DX,MSG10
    MOV AH,9
    INT 21H  
    
    MOV AH,1
    INT 21H
    
    CMP AL,'1'
    JE START
    
    CALL NL
    CALL NL
    
    LEA DX,MSG11
    MOV AH,9
    INT 21H
    
    MOV AH, 4CH
    INT 21H
    
    MAIN ENDP
END MAIN

CodePudding user response:

This isn't a direct answer per se but it may solve your problem. I find something like this much easier to write with a little bit of indirection. Rather than having the same code structure repeated over and over, you can actually make the question being asked a variable itself. It takes a little bit of extra data up front but you might save more data down the line depending on how many quiz questions there are. (Disclaimer: I haven't tested this but try it if you think it will help.)

org 100h

.data
TOTAL_QUESTIONS equ 10


MSG1 DB '..........WELCOME TO SUBJECT REVIEWER SYSTEM..........$'
MSG2 DB 'RULES : $'
MSG3 DB 'FOR EVERY CORRECT PLUS 1 POINT $'
MSG4 DB 'FOR EVERY INCORRECT MINUS 1 POINT $'   
MSG5 DB 'PRESS ENTER TO START THE QUIZ : $'
MSG6 DB 'RIGHT ANSWER $'
MSG7 DB 'WRONG ANSWER $'
MSG8 DB 'YOU SUCCESSFULLY COMPLETED THE QUIZ $'
MSG9 DB 'YOUR TOTAL POINTS IS: $'
MSG10 DB 'PRESS 1 TO REATTEMPT QUIZ $'
MSG11 DB '*******THANK YOU******* $'
Q1 DB '1. 1 1=? $'
QA1 DB 'A) 2 B) 5 C) 23 $' 
Q2 DB '2. 1 1=? $'
QA2 DB 'A) 3 B) 2 C) 65 $'
Q3 DB '3. 1 1=? $'
QA3 DB 'A) 2 B) 44 C) 23 $'
Q4 DB '4. 1 1=? $'
QA4 DB 'A) 2 B) 5 C) 45 $'
Q5 DB '5. 1 1=? $'
QA5 DB 'A) 2 B) 5 C) 56 $'
Q6 DB '6. 1 1=? $'
QA6 DB 'A) 2 B) 4 C) 5 $'
Q7 DB '7. 1 1=? $'
QA7 DB 'A) 2 B) 5 C) 23 $'
Q8 DB '8. 1 1=? $'
QA8 DB 'A) 2 B) 5 C) 7 $'
Q9 DB '9. 1 1=? $'
QA9 DB 'A) 2 B) 5 C) 23 $'
Q10 DB '10. 1 1=? $'
QA10 DB 'A) 2 B) 5 C) 4 $'

Questions_Lookup:
dw Q1, Q2, Q3, Q4, Q5, Q6, Q7, Q8, Q9, Q10
QuestionAnswers_Lookup:
dw QA1, QA2, QA3, QA4, QA5, QA6, QA7, QA8, QA9, QA10
Answers_Lookup:
db "ABAAAAAAAA"

Then in your code, you can do this once you've finished printing the rules, instead of handling each question separately you can make it a loop.

LEA BX, Questions_Lookup
LEA SI, QuestionAnswers_Lookup
LEA DI, Answers_Lookup
MOV CX, TOTAL_QUESTIONS  ;constant 10 (adjust this yourself based on how many questions you have.)
XOR BP,BP  ;correct answer count

Ask_Loop:
MOV DX,[BX]  ;get the address of Q1
MOV AH,9
INT 21H      ;PRINT THE QUESTION
CALL NL

MOV DX,[SI]
MOV AH,9
INT 21H      ;PRINT THE ANSWER
CALL NL

CALL INPUT
CMP AL,[DI]
JNE WRONG
   ;RIGHT
   ADD BP,1
   JMP NEXTQUESTION
WRONG:
   SUB BP,1

NEXTQUESTION:
ADD BX,2  ;next question
ADD SI,2  ;next answer list
INC DI    ;next answer
loop Ask_Loop

;rest of program.

CodePudding user response:

I am planning to deduct if the answer is wrong and add 1 point if it is correct.

You are not obeying your own rules!
Just looking at how you deal with the 1st ('A' is correct) and 2nd ('B' is correct) questions:

    CMP AL, 'A'
    JE QSN2              <<<< "A" is indeed correct for Q1
    JNE QSNW2
QSN2:
    CALL NL
    LEA DX,MSG6    ; "correct"
    MOV AH,9
    INT 21H  
    INC BL
    CALL NL
    CALL QN2
    CALL INPUT
    CMP AL, 'B'
    JE QSN3              <<<< Here "B" is correct for Q2
    JNE QSNW3
    
QSNW2:
    CALL NL
    LEA DX,MSG7    ; "wrong"
    MOV AH,9
    INT 21H  
    INC BL               <<<< Here you award a point instead of deducting
    CALL NL
    CALL QN2
    CALL INPUT
    CMP AL, 'A'
    JE QSN3              <<<< But here "A" is correct for (the same) Q2
    JNE QSNW3
  • The case where the answer was wrong should not be using INC BL but rather DEC BL.
  • The 2nd question gets rated differently depending on how the user did on the 1st question! Should be 'B' on both occasions.

Because your code is not well-structured, you got lost. Consider the solution that @puppydrum64 proposed. I didn't test it but it already looks promising...

  • Related