怎么用语言编写:从键盘输入一个十进制数,将其转变为十六进制数并输出?

2024-12-13 05:29:11
推荐回答(1个)
回答1:

DATAS   SEGMENT

X  DB  0

DATAS   ENDS

;--------------------------------

CODES   SEGMENT

ASSUME   CS:CODES, DS:DATAS

START:

MOV   AX, DATAS

MOV   DS, AX

I0: MOV   AH, 1

INT   21H

CMP   AL, 0DH

JZ    L1

CMP   AL, '0'

JB    I0

CMP   AL, '9'

JA    I0

SUB   AL, 30H

MOV   X, AL

I1: MOV   AH, 1

INT   21H

CMP   AL, 0DH

JZ    L1

CMP   AL, '0'

JB    I1

CMP   AL, '9'

JA    I1

SUB   AL, 30H

MOV   BH, AL

MOV   AL, X

MOV   BL, 10

MUL   BL

ADD   AL, BH

MOV   X, AL

;--------------------

L1:

MOV   DL, 10

MOV   AH, 2

INT   21H

MOV   DL, 13

INT   21H

;--------------------

MOV   AL, X

MOV   AH, 0

MOV   BL, 16

DIV   BL

ADD   AL, 30H

MOV   DL, AL

PUSH  AX

MOV   AH, 2

INT   21H

POP   AX

CMP   AH, 10

JB    L3

ADD   AH, 07H

L3:

ADD   AH, 30H

MOV   DL, AH

MOV   AH, 2

INT   21H

EXIT:

MOV   AH, 4CH

INT   21H

CODES   ENDS

END   START

;===================================