用汇编语言! 编一程序把键入的十六进制数转化 成十进制数。

2024-11-17 23:14:24
推荐回答(2个)
回答1:

编一程序把键入的十六进制数,转化成十进制数,并在屏幕上显示。

键入的十六进制数,不限位数。如超出四位,只将最后四位做转换并显示。

若键入非十六进制数,则不予显示,等待继续输入。

键入回车符,结束输入。

程序如下:

回答2:

        CODE  SEGMENT
              ASSUME    CS:CODE

        BUFF  DB        5,?,5 DUP(?)
           X  DW        0
        ERR1  DB        13,10,'error ! $'

      START:  PUSH      CS
              POP       DS
        @00:
              CALL      LFCR
              LEA       DX,BUFF
              MOV       AH,10
              INT       21H

              LEA       SI,BUFF
              MOV       CL,[SI+1]
              MOV       CH,0
              CLD
              ADD       SI,2
              MOV       DX,0
         @1:
              LODSB
              CMP       AL,'0'
              JB        @0
              CMP       AL,'9'
              JBE       @2
              CMP       AL,'A'
              JB        @0
              CMP       AL,'F'
              JBE       @3
              CMP       AL,'a'
              JB        @0
              CMP       AL,'f'
              JBE       @4
              JMP       @0
         @2:
              SUB       AL,'0'
              JMP       @5
         @3:
              SUB       AL,'A'
              ADD       AL,10
              JMP       @5
         @4:
              SUB       AL,'a'
              ADD       AL,10
         @5:
              SHL       DX,4
              MOV       AH,0
              ADD       DX,AX
              LOOP      @1
              MOV       AX,DX
              CALL      LFCR
              CALL      DSPAX
              MOV       AH,4CH
              INT       21H
         @0:
              MOV       AH,9
              LEA       DX,ERR1
              INT       21H
              JMP       @00
              
  ;==============================
       LFCR:
              PUSH      AX
              PUSH      DX
              MOV       AH,2
              MOV       DL,13
              INT       21H
              MOV       DL,10
              INT       21H
              POP       DX
              POP       AX
              RET
 ;===============================
       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