AT&T
mov $0 , % r8d
gcc -c mov_test.s
输出 mov_test.o
,objdump -D mov_test.o
查看 mov_test.o
:
mov_test. o: file format elf64- x86- 64
Disassembly of section . text:
0000000000000000 < . text> :
0 : 41 b8 00 00 00 00 mov $0x0 , % r8d
mov % r8d, 0
nop
执行命令: gcc -c mov_.S
会输出 mov_.o 文件: objdump -D mov_.o
:
mov_. o: 文件格式 elf64- x86- 64
Disassembly of section . text:
0000000000000000 < . text> :
0 : 44 89 04 25 00 00 00 mov % r8d, 0x0
7 : 00
8 : 90 nop
void main ( ) {
}
执行命令: gcc -S main.c
输出文件 main.s
main.s
:
. file "main.c"
. text
. globl main
. type main, @function
main:
. LFB0:
. cfi_startproc
pushq % rbp
. cfi_def_cfa_offset 16
. cfi_offset 6 , - 16
movq % rsp, % rbp
. cfi_def_cfa_register 6
nop
popq % rbp
. cfi_def_cfa 7 , 8
ret
. cfi_endproc
. LFE0:
. size main, . - main
. ident "GCC: (Uos 8.3.0.3-3+rebuild) 8.3.0"
. section . note. GNU- stack, "" , @progbits
section . text
global _start
_start:
; 将 0 存入 r8d 寄存器
mov r8d, 0
; 退出程序
mov eax, 1
xor ebx, ebx
int 0x80
asm
# include <stdio.h>
int main ( ) {
int num = 10 ;
__asm__ (
"movl %1, %%eax\n\t"
"movl %%eax, %0\n\t"
: "=m" ( num)
: "r" ( num)
: "%eax"
) ;
printf ( "The value of num is: %d\n" , num) ;
return 0 ;
}
Intel
mov r8d, 0
asm_test.c , 指定使用 Intel 语法,需要执行 gcc -masm=intel -S asm_test.c