Linux下汇编语言------找出最大数
基于AT&T汇编语法编写
#HOW TO Compile: as name_file.s -o name_file.o
#HOW TO Link: ld name_file.o -o name_file
.section .data
data_item:
.long 23,45,67,3,122,22,11,66,0
.section .text
.globl _start
_start:
movl $0, %edi
movl data_item(, %edi, 4), %eax
movl %eax, %ebx # %ebx store max allways
start_loop:
cmpl $0, %eax
je loop_exit
incl %edi
movl data_item(, %edi, 4), %eax
cmpl %ebx, %eax
jle start_loop
movl %eax, %ebx
jmp start_loop
loop_exit:
movl $1, %eax
int $0x80
执行程序:
./example_gas
查看最后结果在命令行中使用如下命令:
echo $?