assembly 受试者审查员测验总分错误

wtzytmuj  于 2023-01-21  发布在  其他
关注(0)|答案(1)|浏览(99)

我正在用汇编语言编写一个基本的测验程序。我打算如果答案错了就扣,如果正确就加1分。我的输出不准确。我总是得到错误的总分。

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
wi3ka0sx

wi3ka0sx1#

这不是一个直接的答案,但它可能会解决你的问题。我发现这样的东西更容易写一点间接。而不是有相同的代码结构重复一遍又一遍,你实际上可以让被问的问题本身成为一个变量。它需要一点额外的数据,但你可能会保存更多的数据,这取决于有多少测验问题。(免责声明:我还没有测试过这个,但是如果你认为它会有帮助的话,可以试试。)

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"

然后在你的代码中,你可以在打印完规则后完成这个操作,而不是单独处理每个问题,你可以让它成为一个循环。

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.

相关问题