# An example of the loop instruction
# loop 循环直到ECX为零
# loope/loopz 循环直到ECX为零,或者没有设置ZF标志
# loopne/loopnz 循环直到ECX为零,或者设置了ZF标志
.section .data
output:
.asciz "The value is:%d\n"
.section .text
.globl main
main:
movl $100, %ecx # 如果movl $0, %ecx会造成loop灾难。0-1非零,会溢出。
movl $0, %eax
loop1:
add %ecx, %eax
loop loop1 # loop指令首先把EXC中的值递减
push %eax
push $output
call printf
add $8, %esp
movl $1, %eax
movl $0, %ebx
int $0x80
# gcc -o 07-loop 07-loop.s -m32
# The value is:5050