如何使用汇编语言编写程序使输入的十进制数转化成十六进制的数又如何使十六进制的数转化成相应的十进制

2024-12-01 07:12:16
推荐回答(2个)
回答1:

        CODE  SEGMENT
              ASSUME    CS:CODE
              ORG       100H
      START:
              PUSH      CS
              POP       DS
              PUSH      CS
              POP       ES
              CALL      INPUTNUM    ; 输入10进制数 转为16进制
              
              LEA       DX,LFCR
              MOV       AH,9
              INT       21H
              
              LEA       SI,ARRAY
              MOV       AX,[SI]
              CALL      DISPAX      ; 以10进制形式显示16进制数

              MOV       AH,4CH
              INT       21H
              
        LFCR  DB        10,13,'$'
 ;===============================================
;  键盘输入数值数组子程序(数组名为array,元素个数存放在num中)
    INPUTNUM  PROC      NEAR
              PUSH      AX
              PUSH      BX
              PUSH      CX
              PUSH      DX
              PUSH      SI
              PUSH      DI
              PUSH      BP
              PUSHF
    ; 输入的数据以一个空格分隔,以回车符结束输入
              LEA       DI,ARRAY    ;将数组第一个元素的有效地址置入DI
              MOV       WORD PTR[NUM],0
       STIN:
              MOV       AX,0
              PUSH      AX
     AGAIN1:
              MOV       AH,1
              INT       21H
              MOV       BYTE PTR[CHAR],AL
              CMP       AL,13
              JE        LINE0
              CMP       AL,' '
              JE        LINE0
              SUB       AL,30H
              MOV       AH,0
              MOV       SI,AX
              POP       AX
              MOV       CL,10
              MOV       CH,0
              MUL       CX
              ADD       AX,SI
              PUSH      AX
              JMP       AGAIN1
      LINE0:
              POP       AX
              MOV       WORD PTR[DI],AX
              INC       WORD PTR[NUM]
              CMP       BYTE PTR[CHAR],13
              JE        STINEND
              INC       DI
              INC       DI
              JMP       STIN
    STINEND:
              POPF
              POP       BP
              POP       DI
              POP       SI
              POP       DX
              POP       CX
              POP       BX
              POP       AX
              RET
       ARRAY  DW        200 DUP(0)
         NUM  DW        0
        CHAR  DB        ?
    INPUTNUM  ENDP
              
;===============================================
              
; 将要显示的无符号数置于 ax 中 
      DISPAX  PROC      NEAR
              PUSH      AX
              PUSH      BX
              PUSH      CX
              PUSH      DX
              PUSH      SI
              PUSH      DI
              PUSH      BP
              PUSHF
              PUSH      DS
              PUSH      CS
              POP       DS
              MOV       BYTE PTR NZ,0
              PUSH      AX
              LEA       SI,DIVARR
              MOV       CX,5
         @1:
              POP       AX
              MOV       DX,0
              MOV       BX,[SI]
              DIV       BX
              PUSH      DX
              CMP       AL,0
              JNE       @2
              CMP       BYTE PTR NZ,1
              JE        @2
              CMP       CX,1
              JE        @2
              MOV       DL,20H
              JMP       @3
         @2:
              ADD       AL,30H
              MOV       DL,AL
              MOV       BYTE PTR NZ,1
         @3:
              MOV       AH,2
              INT       21H
              INC       SI
              INC       SI
              LOOP      @1
              POP       DX
              POP       DS
              POPF
              POP       BP
              POP       DI
              POP       SI
              POP       DX
              POP       CX
              POP       BX
              POP       AX
              RET
      DIVARR  DW        10000,1000,100,10,1
          NZ  DB        0
      DISPAX  ENDP

        CODE  ENDS
              END       START

回答2:

换码吗?