Article Directory
Install assembly tools
apt install nasm
Write assembly code
Create file huibian.asm
[section .data] ;数据在此
strHello db "Hello, world",0Ah
STRLEN equ $ - strHello
[section .text] ;代码在此
global _start ;必须导出_start这个入口,以便让链接器识别
_start:
mov edx,STRLEN
mov ecx,strHello
mov ebx,1
mov eax,4 ;sys_write
int 0x80 ;系统调用
mov ebx,0
mov eax,1 ;sys_exit
int 0x80 ;系统调用
run
Compile and generate files to be linked
! ! ! ! Note that elf64 changes according to your machine.
I am using a 64-bit x86 machine, so it is elf64.
32-bit x86 is elf
. I don’t know.
nasm -f elf64 huibian.asm -o hello.o
Link .o file
ld -s hello.o -o hello
Perform assembly
./hello
expand
View the variable table of the linkable .o file
nm -o -v hello.o
Disassemble the source code of the .o file
Uppercase-S
objdump -S hello.o
View the machine code of the .o file
Lowercase -s
objdump -s hello.o