perrynzhou

专注于系统组件研发

0%

理解简单汇编程序

  • 寄存器以及中断号对应表
eax(系统调用号) 系统调用 ebx(系统调用参数1) ecx(系统调用参数2) ecx(系统调用参数3) edx(系统调用参数4 ) esx(系统调用参数5) edi(系统调用参数6)
1 sys_exit int
4 sys_write unsigned int const char * size_t
  • hello.asm汇编代码解释
    //定义数据段
    SECTION .data;
    

//db 代表一个字节占8个字节,读完一个偏移量加1字节
//dw 是汇编中的一个字,就是占用2个字节,读完一个偏移量加2
//dd 是汇编中的一个双字节,占用4个字节,读完一个偏移量加4
MyMsg: db “hello,word”;
MyMsgLen: equ $-MyMsg;

//定义bbs段
SECTION .bbs;
//定义代码段
SECTION .text;

global _start;

_start:
nop;
mov eax,4; //把4号系统调用写入到eax,sys_write写入到eax寄存器
mov ebx,1; //把1号文件描述符写入到ebx
mov ecx,MyMsg; //把MyMsg的地址写入到ecx
mov edx,MyMsgLen; //把MyMsgLen写入到edx
int 80H; //调用系统sys_write,回去eax取出对应的中断号,同时从ebx,ecx,edx出去系统调用参数进行调用
mov eax,1; //把1号系统调用写入到eax
mov ebx ,0; //把0写入到ebx中
int 80H; //调用系统exit


- linux系统中断对应表


![image.png](https://upload-images.jianshu.io/upload_images/2582954-c5536607f4a7b75d.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)