在macOS Terminal中輸入
cc -arch i386 -Wl,-no_pie movetest3.s
./a.out
輸出
The value is 10
The value is 15
The value is 20
The value is 25
The value is 30
The value is 35
The value is 40
The value is 45
The value is 50
The value is 55
The value is 60
代碼如下
# cc -arch i386 -Wl,-no_pie movetest3.s
.data
values:
.long 10, 15, 20, 25, 30, 35, 40, 45, 50, 55, 60
.cstring
output:
.asciz "The value is %d\n"
.text
.globl _main
.p2align 2
_main:
pushl %ebp
movl $0, %edi
loop:
movl values(,%edi,4), %eax
pushl %eax
pushl $output
call _printf
addl $8, %esp
incl %edi
cmpl $11, %edi
jne loop
xorl %eax, %eax
popl %ebp
retl