# An example of the CMOV instruction. (条件传送指令)
# 查找数组中最大的一个
.section .data
output:
.asciz "The largest value is %d\n"
values:
.int 105, 235, 61, 315, 134, 221, 53, 145, 117, 5
.section .text
.globl main
main:
nop
movl values, %ebx # 数组的第一个值加载到ebx
movl $1, %edi
loop:
movl values(, %edi, 4), %eax # 数组元素被逐个加载到eax中,并和EBX中的值进行比较
cmp %ebx, %eax
cmova %eax, %ebx # ebx 保存当前找到的最大整数;如果eax中的值更大,就把它传给ebx。
inc %edi
cmp $10, %edi
jne loop
push %ebx
push $output
call printf # printf(output, ebx)
add $8, %esp # 还原esp
push $0
call exit
# gcc -o 03-cmov 03-cmov.s -m32