汇编作业,汇编语言,输入一串字符,将数字相加输出

汇编语言,输入一串字符,将数字相加输出
2024-12-18 19:58:02
推荐回答(1个)
回答1:

        CODE  SEGMENT
              ASSUME    CS:CODE

        STR1  DB        255,?,255 DUP('$')
        STR2  DB        13,10,'$'

      START:  PUSH      CS
              POP       DS
              PUSH      CS
              POP       ES

              MOV       AH,10
              LEA       DX,STR1
              INT       21H
              MOV       AH,9
              LEA       DX,STR2
              INT       21H
              
              LEA       SI,STR1
              MOV       CL,[SI+1]
              XOR       CH,CH
              ADD       SI,2
              MOV       BP,CX
              CLD
              MOV       DI,0
         @1:
              LODSB
              CMP       AL,'0'
              JB        @2
              CMP       AL,'9'
              JA        @2
              AND       AL,0FH
              CBW
              ADD       DI,AX
         @2:
              LOOP      @1
              MOV       AX,DI
              CALL      DSPAX
              
              MOV       AH,4CH
              INT       21H
;===============================
       DSPAX  PROC      NEAR
              PUSH      AX
              PUSH      BX
              PUSH      CX
              PUSH      DX
              PUSHF
              XOR       CX,CX
              MOV       BX,10
    @DSPAX1:
              XOR       DX,DX
              DIV       BX
              INC       CX
              OR        DX,30H
              PUSH      DX
              CMP       AX,0
              JNE       @DSPAX1
              MOV       AH,2
   @DISPAX2:
              POP       DX
              INT       21H
              LOOP      @DISPAX2
              MOV       DL,32
              INT       21H
              POPF
              POP       DX
              POP       CX
              POP       BX
              POP       AX
              RET
       DSPAX  ENDP
;================================               
        CODE  ENDS
              END       START