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)