;==============================================
;1+...+n < 100
;----------------------------------------------
DATA SEGMENT ;数据段
i DW 1
sum DW 0
DATA ENDS
;----------------------------------------------
CODE SEGMENT ;代码段
ASSUME CS: CODE, DS: DATA
START:
PUSH CS
POP DS
MOV i, 1
MOV sum, 0
LOP:
MOV AX, sum
ADD AX, i
CMP AX, 100
JNB EXIT
MOV sum, AX
MOV AX, i
CALL PRINTAX
MOV DL, ':'
CALL PUTC
MOV DL, ' '
CALL PUTC
MOV AX, sum
CALL PRINTAX
INC i
CALL OUT_0D0A
JMP LOP
EXIT:
MOV AH, 4CH
INT 21H
;------------------------------
PRINTAX PROC ;
MOV BX, 10 ;
OR AX, AX
JZ _0_
LOOP_P:
XOR DX, DX
DIV BX
MOV CX, AX ;
OR CX, DX
JZ _E_ ;
PUSH DX ;
CALL LOOP_P
POP DX ;
ADD DL, '0' ;
JMP _1_
_0_:MOV DL, '0' ;
_1_:CALL PUTC
_E_:RET
PRINTAX ENDP
;------------------------------
PUTC PROC
MOV AH, 2
INT 21H
RET
PUTC ENDP
;------------------------------
OUT_0D0A PROC ;回车换行.
MOV DL, 13
CALL PUTC
MOV DL, 10
CALL PUTC
RET
OUT_0D0A ENDP
;------------------------------
CODE ENDS
END START
;==============================================
程序运行后屏幕显示的画面如图所示:650) this.width=650;" class="blogimg" border="0" src="http://hiphotos.baidu.com/%D7%F6%B6%F8%C2%DB%B5%C0/pic/item/761522c92ecfac777e3e6fef.jpg" small="0" alt="" />