Wang Shuang assembly language lab 10 Course Design 1

Source: Internet
Author: User

Assume Cs: codecode segmentdata segment dB '000000', '000000', '000000', '000000', '000000', '000000', '000000 ', '000000' dB '000000', '000000', '000000', '000000', '000000', '000000', '000000 ', '000000' dB '000000', '000000', '000000'; The above is a 21-year string 4*21 = 84 dd 1992, 22, 1993, 1994, 1995, 5937000 million, DD 345980,590827, 80 million, 1183000, 1843000,2759000, 3753000,4649000,; The above indicates the company's total revenue in 21 years DWORD data 4*21 = 84 DW 3, 7, 130,220,476,778,100, 8226; the preceding figure shows the 21-year staff of the company. The 21-year word data is 2x21 = 42 data endsdatads segment dB 100 DUP (0) datads endsstart: mov BX, data mov es, BX mov BX, datads mov ds, BX mov CX, 21 mov DH, 2 mov Si, 0 mov BX, 0; year mov Di, 0; income mov bp, 0; nums:; ----------- years -------------------- mov DL, 3 mov word ptr ds: [0], 0; DS: Mov word ptr ds: [2], 0 mov word ptr ds: [4], 0 mov ax, ES: [BX] mov DS: [0], ax mov ax, ES: [bx + 2] mov DS: [2], ax push CX mov CX, 4 call show_str pop CX; ------------- income ------------------- add DL, 10 push DX; When dtocex is used, DX should be used for high positions to protect mov word ptr ds: [0], 0 mov word ptr ds: [2], 0 mov word ptr ds: [4], 0 mov ax, ES: [84 + DI] mov dx, ES: [86 + DI] Call dtocex pop DX push CX mov CX, 4 Cal L show_str pop CX; ------------- num ----------------------- add DL, 10 push DX mov word ptr ds: [0], 0 mov word ptr ds: [2], 0 mov word ptr ds: [4], 0 mov ax, ES: [168 + bp] Call DTOC pop DX push CX mov CX, 4 call show_str pop CX; ------------------ aver ------------------- add DL, 10 push DX mov word ptr ds: [0], 0 mov word ptr ds: [2], 0 mov word ptr ds: [4], 0 mov ax, ES: [di + 84] mov dx, ES: [di + 86] Div word ptr es: [bp + 168] Call DTOC pop DX push CX mov CX, 4 call show_str pop CX; -------------------------------------- Add Bx, 4 Add Di, 4 Add bp, 2 Inc DH dec cx cmp cx, 0 JNE s_helpmov ax, 4c00hint 21hs_help: JMP far PTR s; Name: dtocex; function: Convert DWORD data to a decimal string, the string ends with 0 .; Parameter: (ax) = low 16 bits of DWORD data, (dx) = high 16 bits of DWORD data, DS: Si points to the first address of the string, and return: No dtocex: dataseg_dtocex segmentdb 100 DUP (0); DB 100 DUP (0); Result and intermediate variable dataseg_dtocex endspush BX push espush dipush cxmov BX, dataseg_dtocexmov es, bxmov ES: [0], axmov ES: [2], dsmov ES: [4], SiMoV ES: [6], dxmov Di, 0mov ax, ES: [0] dtocex_s: moV CX, 10 call divdw; DX: ax/Cx = DX: ax ~ Cxadd Cl, 30 hmov byte ptr es: [100 + DI], CL Inc dicmp dx, 0je dxiszjmp dtocex_sdxisz: CMP ax, 0jne dtocex_smov CX, DIMOV ds, ES: [2] mov Si, ES: [4] dtocex_reverse: mov BL, ES: [99 + DI] mov DS: [Si], blinc sidec diloop dtocex_reversemov byte ptr ds: [Si], 0mov ds, ES: [2] mov Si, ES: [4] Pop cxpop dipop ESPOP bxret; Name: divdw; function: Perform Division operations without Overflow, divisor: DWORD, divisor: Word, and Result: DWORD. Parameter: (ax) = DWORD: Low 16 bits, (dx) = DWORD High 16 bits, (CX) = divisor; Return: (dx) = high 16 bits of the result, (ax) = low 16 bits of the result, (CX) = remainder divdw: dataseg_divdw segmentdb 100 DUP (0); DB 100 DUP (0); Result and intermediate variable dataseg_divdw endspush bxpush esmov BX, dataseg_divdwmov es, bxmov ES: [0], ax; LMoV ES: [2], DX; hmov ES: [4], CX; nmov dx, 0mov ax, ES: [2] Div word ptr es: [4] mov ES: [100], ax; Result dxmov ax, ES: [0] Div word ptr es: [4] mov ES: [102], ax; Result axmov ES: [104], DX; Result cxmov dx, ES: [10 0] mov CX, ES: [104] Pop bxpop esret; Name: show_str; function: display a string ending with 0 in the specified color at the specified position; parameter: (DH) = row number (value range: 0 ~ 24), (DL) = column number (value range: 0 ~ 79), (CL) = color, DS: Si points to the first address of the string; Return: No show_str: Push axpush bxpush cxpush dxpush sipush bppush dipesmov Al, DH; row number add Al, 1mov BL, 0a0hmul blmov DH, 0sub dx, 1; add dx, DX; because one character occupies two bytes add ax, DX; add column numbers in DL to mov di in ax, ax; the initial position of di display on the screen mov ah, Cl; the characters and colors mov CH, 0 to be displayed by ax; CX determine the cycle conditions mov BX, 0b800hmov es, BX; the address mov bp, 0 displayed by es; the cursor s_showstr: mov Cl, DS: [Si] mov Al, DS: [Si] jcxz retsegmov ES: [di + bp], Axi NC siadd bp, 2 loop s_showstrretseg: Pop ESPOP dipop bppop sipop dxpop cxpop bxpop axret; Name: DTOC; function: convert Word data to a decimal string, the string ends with 0 .; Parameter: (ax) = word data, DS: Si points to the first address of the string; Return: No DTOC: dataseg_dtoc segmentdb 100 DUP (0 ); store the database 100 DUP (0) parameter and register value; store the result and the intermediate variable dataseg_dtoc endspush bxpush espush dxpush cxpush dimov bx, dataseg_dtocmov es, bxmov ES: [0], axmov ES: [2], dsmov ES: [4], SiMoV BX, 10mov Di, 0mov ax, ES: [0] dtocs: mov dx, 0div bxmov CX, axadd DL, 30 hmov byte ptr es: [100 + DI], DL Inc dijcxz getcountmov CX, 2; when the quotient is 1, CX --, it is 1, loop dtocsgetcount: mov CX, DIMOV ds, ES: [2] mov Si, ES: [4] dtocreverse: mov BL, ES: [99 + DI] mov DS: [Si], blinc sidec diloop dtocreversemov byte ptr ds: [Si], 0mov ds, ES: [2] mov Si, ES: [4] Pop di pop CX pop DX pop es pop bxretcode endsend start

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.