Just contact the assembly, a lot of details are not very clear, wrote a decimal and hexadecimal conversion between the program (a bit of a setback.) ) as a practiced hand.
Post code, hope that the passing of Daniel can give some guidance.
Idea: (10->16) decimal number input when single character processing, meet enter end input, finally get a decimal number. Then loop left (processing only 4 times), take the next four bits, which is equivalent to/16
The last output character. (16->10) Similar processing, first converted to 10 binary number (each *16), and then take out each bit of output.
; multi-Segment executable file template.data segment; Add your data here!Num DW0String1 db'Please choose 1 (Dec->hex) or 2 (HEX->DEC)]:$'Inputdec DB'Please input a DEC number: $'Inputhex DB'Please input a HEX number: $'endsstack Segment DW -Dup0) Endscode segment start:;Setsegment Registers:mov ax, data mov ds, ax mov es, ax;-------------selection Mode------------------Model:lea DX, string1 mov ah,9 int21h mov ah,1 int21h Sub al,30h cmp al,1mov cx,Ten, take the JZ option1 call CRLF cmp al,2mov cx, -JZ option2 call CRLF jmp model;---------------------------------------- ;Decimal Turn hex ***************** ;-----------Enter a decimal number-------------option1:call CRLF Lea Dx,inputdec mov ah,9 int21h Rotate1:mov Ah,1 int21h cmp al,0dh; Enter end decimal number input JZ DectoHex sub al,30h CBW push AX mov ax,bx mul CX mov bx,ax Pop ax add Bx,ax; input results are saved in BX in jmp rotate1;----------------------------------------- ;---------Start conversion (Ten- -)-------------dectohex:call CRLF mov ch,4Rotatecur:mov cl,4rol BX,CL mov al,bl and al,0fh add al,30h cmp al,3ah JL print1 add al,7h Print1:mov dl,al m OV Ah,2 int21h Dec ch jnz rotatecur call exit;hexadecimal to decimal ******************* ;-------------Enter a hexadecimal number------------------option2:call CRLF Lea Dx,inputhex mov ah,9 int21h Rotate2:mov Ah,1 int21h cmp al,0dh; Enter end hexadecimal number input JZ Hextodec Sub al,30h cmp al,9JG other L:CBW push AX mov ax,num mul CX mov num,ax pop ax add num,ax; input results are saved in Num JM P rotate2 other:sub al,7h jmp L hextodec:call CRLF mov cx, + ;----------Duplicate Output code ... -----mov ax, num mov dx,0Div CX mov num, DX mov dl, al add dl,30h mov ah,02hint21h;--------------------mov cx, - ;----------mov ax, num mov dx,0Div CX mov num, DX mov dl, al add dl,30h mov ah,02hint21h;----------mov cx,Ten ;----------mov ax, num mov dx,0Div CX mov num, DX mov dl, al add dl,30h mov ah,02hint21h;----------mov cx,1 ;----------mov ax, num mov dx,0Div CX mov num, DX mov dl, al add dl,30h mov ah,02hint21h;----------Call exit;----------take every single------------------;----------------------------------- ;--------carriage return to newline------------------CRLF proc near push ax push DX PUSHF mov dl,0dh; carriage return mov ah, 2 int21h mov dl,0ah; newline mov ah,2 int21h Popf pop dx pop ax ret CRLF ENDP;----------------------------------------- ;-----------------Exit---------------------exit proc mov ax, 4c00h; exit to operating system. int21h exit ENDP;------------------------------------------endsend start;SetEntry point and stop the assembler.
[Assembler] conversions between decimal and hexadecimal numbers