Assembly language loop

assume cs:code
code segment

	mov ax, 2	;ax=2
	mov cx, 11	;将cx赋值为11,
				;CX一大功能用作汇编语言loop循环次数的存储器,
				;loop循环每执行一次CX中存储的数值减一,循环结束的标准是CX为零
				;所以要用loop循环,要提前给CX赋值,CX中存的数字就是你要执行的循环次数
s:	add ax, ax	;s:是循环标号;ax+=ax
	loop s		;如果CX不为0,返回s处执行循环
	
	mov ax, 4c00H
	int 21h

code ends
end

To use a loop loop, you must assign a value to CX in advance. The value assigned to CX is the number of loops you want to perform, because the value stored in CX is reduced by one every time the loop loop is executed. The standard for the end of the loop is CX == 0.
Therefore, the circular writing of assembly language is roughly:

mov cx, 循环次数
s:
循环体(要循环执行的内容)
loop s
78 original articles published · Like 3 · Visits 5596

Guess you like

Origin blog.csdn.net/qq_43071318/article/details/105158212