Compile the experiment to convert the octal to decimal

Source: Internet
Author: User
; 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 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.