assembly language implementation from 1 to 100 (1+2+...+100)

Source: Internet
Author: User

Implement 1+2+...+100 with assembly language

;Classroom Assignments;Calculate 1+2+...+100DATA SEGMENT COUNT DW0    ;CountDATA ENDS stack SEGMENT PARA stack BUF DW 20H DUP (0) LEN EQU $-bufstack endscodeseg segmentassumeCS:CODESEG,SS:STACK,DS:DATASTART:;Initialize stack segment SS and data segment DS  MOVAx,stackMOVSs,axMOVSp,lenMOVAx,dataMOVDs,axMOVcx,64h;Cycle 100 times  MOVAx0S:    ADDcount,01hADDax,count LOOP SMOVDl,alMOVAl,ahPagerDisp_2_hexMOVAL,DLPagerDisp_2_hexPagerDisp_crefMOVah,4chINT21H;outputs the high four bits of Al and the lower four bits respectivelyDisp_2_hex:  PUSHAXPUSHBXPUSHF  MOVAH,0 ;Qing 0  MOVbl,10h;for Division  DIVBL;AL: Quotient high AH remainder low  PagerDisp_1_hex;results of output Al  MOVAl,ahPagerDisp_1_hexPopf  POPBXPOPAXRET;output The numbers and letters of AlDisp_1_hex:    PUSHAXPUSHDXPUSHF  MOVDl,alCMPDl the  JbeL_1;less than or equal to 9 skips the next statement  ADDdl,27h;greater than 10 is converted to lowercase letters and executed to the end of the RET to the following L_1                ;The Number 10 and the character a difference is (27H);Digital output (ASCII code of 1 is 31H)L_1:    ADDdl,30h;convert numbers to characters  MOVah,02hINT21HPopf  POPDXPOPAXRET;output carriage return line breakDisp_cref:  PUSHDXPUSHAXMOVah,02hMOVDL,0DHINT21HMOVdl,0ahINT21HPOPAXPOPDXRETcodeseg ENDSEND START

Output is 13ba (hex of 5050)

assembly language implementation from 1 to 100 (1+2+...+100)

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.