简体   繁体   中英

emu8086 Assembly Input output with three characters

good day everyone, i'm new to this language and here is a code i modified that should accept input ABC and return ABC but it returns ABB. i tried it with AH,BH and Ax,Bx it gets worse. How do I modify this ( for now our teacher wants us to stick to MOV,INT,LEA and what is on the code here). thanks for tips and answers

.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

At line 14, you save the third character in DL, but, later, you lose this value by assigning ODH and OAH to DL. The solution is simple : store the third character in another register instead of DL, for example, CH, at the bottom you display CH instead of DL (arrows <============== point to the changes) :

.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

I chose CH because it's a register that is not been used in the code.

There is a more Efficient way

MAIN PROC

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

END MAIN

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM