0

大家好,我是这种语言的新手,这是我修改的代码,它应该接受输入 ABC 并返回 ABC,但它返回 ABB。我用 AH,BH 和 Ax,Bx 试过了,它变得更糟了。我该如何修改它(现在我们的老师希望我们坚持使用 MOV、INT、LEA 以及这里的代码内容)。感谢您的提示和答案

.MODEL SMALL
    .STACK 100H
    .CODE
     MOV AH, 01H ; Character input with echo
     INT 21H ; Character in AL
     MOV BL, AL ; Save in BL    

     MOV AH, 01H ; Character input with echo
     INT 21H ; Character in AL
     MOV CL, AL ; Save in CL

     MOV AH, 01H ; Character input with echo
     INT 21H ; Character in AL
     MOV DL, AL ; Save in DL

     MOV AH, 02H ; Display character function    

     MOV DL, 0DH ; carriage return
     INT 21H

     MOV DL, 0AH ; line feed
     INT 21H  

     MOV DL, BL ; Get character stored in BL and display
     INT 21H   
     MOV DL, CL ; Get character stored in CL and display
     INT 21H  
     MOV DL, DL ; Get character stored in DL and display
     INT 21H  

     MOV AH, 4CH
     INT 21H
     END
4

2 回答 2

1

在第 14 行,您将第三个字符保存在 DL 中,但后来,通过将 ODH 和 OAH 分配给 DL,您丢失了该值。解决方案很简单:将第三个字符存储在另一个寄存器中而不是 DL,例如 CH,在底部显示 CH 而不是 DL(箭头 <============== 指向变化) :

.MODEL SMALL
    .STACK 100H
    .CODE
     MOV AH, 01H ; Character input with echo
     INT 21H ; Character in AL
     MOV BL, AL ; Save in BL    

     MOV AH, 01H ; Character input with echo
     INT 21H ; Character in AL
     MOV CL, AL ; Save in CL

     MOV AH, 01H ; Character input with echo
     INT 21H ; Character in AL
;    MOV DL, AL ; Save in DL
     MOV CH, AL ; <============================

     MOV AH, 02H ; Display character function    

     MOV DL, 0DH ; carriage return
     INT 21H

     MOV DL, 0AH ; line feed
     INT 21H  

     MOV DL, BL ; Get character stored in BL and display
     INT 21H   
     MOV DL, CL ; Get character stored in BL and display
     INT 21H  
;    MOV DL, DL ; Get character stored in BL and display
     MOV DL, CH ; <============================
     INT 21H  

     MOV AH, 4CH
     INT 21H
     END

我选择 CH 是因为它是一个没有在代码中使用的寄存器。

于 2016-07-12T14:36:38.323 回答
-1

有一种更有效的方法

主程序

MOV BH,0
MOV BL,10D


   INPUT:
   MOV AH,1
   INT 21H
   CMP AL,13D
   JNE NUMBER 

   JMP EXIT


   NUMBER:
   SUB AL,30H
   MOV CL,AL
   MOV AL,BH
   MUL BL
   ADD AL,CL
   MOV BH,AL

   JMP INPUT

EXIT:

   AND AX,0
   MOV AL,BH
   MOV CL,10D

   MOV BX,0000H    

   STORE:
   DIV CL
   MOV [0000H+BX],AH
   ADD BX,2H
   MOV AH,0
   CMP AL,0
   JNE STORE

   MOV AH,2
   MOV  DL,0DH
   INT 21H
   MOV DL,0AH
   INT 21H

   PRINT: 
   SUB BX,2H
   MOV DL,[0000H+BX]
   ADD DL,30H
   INT 21H
   CMP BX,0
   JNE PRINT



MAIN ENDP

结束主要

于 2018-09-24T01:29:06.713 回答