1
mov ah,01h
int 21h

我知道这是您输入一位数字或字符的方式,但我如何输入例如数字 38。谢谢

4

2 回答 2

1

这应该适合你:

.model small
.data
.code

mov ax, @data
mov ds, ax 

mov dl, 10  
mov bl, 0         

scanNum:

      mov ah, 01h
      int 21h

      cmp al, 13   ; Check if user pressed ENTER KEY
      je  exit 

      mov ah, 0  
      sub al, 48   ; ASCII to DECIMAL

      mov cl, al
      mov al, bl   ; Store the previous value in AL

      mul dl       ; multiply the previous value with 10

      add al, cl   ; previous value + new value ( after previous value is multiplyed with 10 )
      mov bl, al

      jmp scanNum    

exit:

      mov ah, 04ch   
      int 21h

 end
于 2017-11-25T08:11:06.150 回答
-2
.MODEL SMALL
 .STACK 100H

 .DATA
    PROMPT_1  DB  'Enter the First digit : $'
    PROMPT_2  DB  'Enter the Second digit : $'
    PROMPT_3  DB  'Sum of First and Second digit : $'

 .CODE
   MAIN PROC
     MOV AX, @DATA                ; initialize DS
     MOV DS, AX

     LEA DX, PROMPT_1             ; load and display the PROMPT_1
     MOV AH, 9
     INT 21H

     MOV AH, 1                    ; read a character\\digit
     INT 21H

     MOV BL, AL                   ; save First digit in BL in ASCII code
     SUB BL, 30H

     MOV AH, 2                    ; carriage return
     MOV DL, 0DH
     INT 21H

     MOV DL, 0AH                  ; line feed
     INT 21H

     LEA DX, PROMPT_2             ; load and display the PROMPT_2
     MOV AH, 9
     INT 21H

     MOV AH, 1                    ; read a character
     INT 21H

     MOV BH, AL                   ; save Second digit in BH in ASCII CODE
     SUB BH, 30H

     MOV AH, 2                    ; carriage return
     MOV DL, 0DH
     INT 21H

     MOV DL, 0AH                  ; line feed
     INT 21H

     LEA DX, PROMPT_3             ; load and display the PROMPT_3
     MOV AH, 9
     INT 21H

     ADD BL, BH                   ; add First and Second digit
     ADD BL, 30H                  ; convert ASCII to DECIMAL code

     MOV AH, 2                    ; display the character
     MOV DL, BL     
     INT 21H

     MOV AH, 4CH                  ; return control to DOS
     INT 21H
   MAIN ENDP
 END MAIN
于 2020-07-01T04:18:55.660 回答