十进制转十六进制
stack segment'stack'
dw 32 dup(?)
stack ends
data segment
IBUF DB 6,0,6 DUP(?)
W DW 0
HEX DB "0123456789ABCDEF"
OBUF DB 4 DUP(?),'$'
data ends
code segment
begin proc far
assume ss:stack,cs:code,ds:data
push ds
sub ax,ax
push ax
mov ax,data
mov ds,ax
MOV DX,OFFSET IBUF
MOV AH,10
INT 21H
MOV DL,0AH
MOV AH,2
INT 21H
MOV CL,IBUF+1
MOV CH,0
MOV SI,OFFSET IBUF+2
MOV AX,0
AGAIN:MOV DX 10
MUL DX
AND BYTE PTR [SI],0FH
ADD AL,[SI]
ADC,AH,0
INC SI
LOOP AGAIN
MOV W,AX
MOV CX,02
MOV DI,OFFSET W
MOV SI,OFFSET OBUF+3
NEXT:MOV AL,BYTE PTR [DI]
MOV W,AX
MOV CX,4
MOV SI,W
LEA BX,HEX
ONE:ROL SI,1
ROL SI,1
ROL SI,1
ROL SI,1
MOV AX,SI
AND AL,000FH
XLAT
MOV DL,AL
MOV AH,2
INT 21H
LOOP ONE
MOV AX,4C00H
MOV DX,OFFSET OBUF
MOV AH,9
INT 21H
RET
begin endp
code ends
end begin呵呵,这个是汇编的,C语音应该用库函数吧。
|
|