汇编计算1+.....+100的和并输出到屏幕

DATAS SEGMENT
    ;此处输入数据段代码 
    i db 1
    b dw 10000,1000,100,10,1;!!十进制转化成十六进制存到存储区中2710,03E8,0064,000A,0001
    flag db 0
    sum dw 0
DATAS ENDS

STACKS SEGMENT
    ;此处输入堆栈段代码
    db 100h dup(?)
STACKS ENDS

CODES SEGMENT
    ASSUME CS:CODES,DS:DATAS,SS:STACKS
START:
    MOV AX,DATAS
    MOV DS,AX
    ;此处输入代码段代码
    mov cx,100
    mov dl,i
    mov dh,0
    mov ax,sum 
L1: add ax,dx
	inc dx
	loop L1 ;循环算出1+....+100的值存到ax
	
	mov bx,offset b
	mov cx,5
r1: mov dx,0
	div word ptr [bx]
	mov si,dx
	cmp ax,0
	jz r2
	mov flag,1
r2: cmp flag,0
	jz r3
	mov dl,al
	add dl,30h
	mov ah,2
	int 21h
r3: add bx,2
	mov ax,si
	loop r1
    MOV AH,4CH
    INT 21H
CODES ENDS
    END START

 

你可能感兴趣的:(汇编)