; Compile Lab 8- Hexadecimal to decimal. Experimental requirements: Use the keyboard to give a four-digit hexadecimal number,ProgramConvert it to a decimal number and output the converted decimal number. shiyan_8.asmcseg segment assume Cs: csegmain proc far call readhex mov ah, 2 MoV DL, 13 Int 21 h mov DL, 10 Int 21 h call printdec mov ah, 7 ; Press any key to exit Int 21 h mov ax, 4c00h; after the program ends, return to the Operating System Int 21 hmain endp; ========================================================== ====================================== Readhex proc near; read a hexadecimal number and save it in binary format to BX mov BX, 0 MoV CX, 4 Nextdig: mov ah, 1 Int 21 h CMP Al, 61 h; ' A ' - ' Z ' Jge upper CMP Al, 41 h; ' A ' - ' Z ' Jge lower sub Al, 30 h; ' 0 ' - ' 9 ' JMP adjustupper: Sub Al, 61 H add Al, 10d JMP adjustlower: Sub Al, 41 h add Al, 10 dadjust: CBW; BX = Bx * 16 + Ax xchg ax, BX mov dx, 16D Mul DX xchg ax, BX Add Bx, ax loop nextdig retreadhex endp; ========================================================== ====================================== Printdec proc near; outputs a decimal number. Parameter: BX ten DW 10 Digs DW 0 ; Starting from a single position, push the stack one by one, and then exit the stack to output mov digs from the high position to the position, 0 Lable1: mov ax, BX mov dx, 0 ; (Dx, ax) is the divisor Div ten; divided by 10, the remainder is the lowest Bit, stored in dx cmp dx, bx jz lable2; BX % 10 = BX, there is only one left. You can directly press the stack Inc digs push DX mov BX, ax JMP lable1lable2: Inc digs push BX mov CX, digsnext: Pop ax mov dx, ax add DL, 30 h mov ah, 2 Int 21 h loop next retprintdec endp; ========================================================== ====================================== Cseg endsend main