官术网_书友最值得收藏!

The Linux Assembly template (32-bit)

On Linux, although files on disc are divided into sections, executables in memory are divided into code and data segments. The following is our template for the ELF 32-bit executable for Linux:

; File: src/template_lin.asm

; Just as in the Windows template - we tell the assembler which type
; of output we expect.
; In this case it is 32-bit executable ELF
format ELF executable

; Tell the assembler where the entry point is
entry _start

; On *nix based systems, when in memory, the space is arranged into
; segments, rather than in sections, therefore, we define
; two segments:
; Code segment (executable segment)
segment readable executable

; Here is our entry point
_start:


; Set return value to 0
xor ebx, ebx
mov eax, ebx

; Set eax to 1 - 32-bit Linux SYS_exit system call number
inc eax

; Call kernel
int 0x80


; Data segment
segment readable writeable
db 0


; As you see, there is no import/export segment here. The structure
; of an ELF executable/object file will be covered in more detail
; in chapters 8 and 9

As was mentioned in the preceding code, these two templates will be used as a starting point for any code we will write in this book.

主站蜘蛛池模板: 永昌县| 嘉兴市| 凌海市| 巨鹿县| 克东县| 博兴县| 日喀则市| 通道| 措美县| 乌兰县| 汨罗市| 玉林市| 兰考县| 丰镇市| 马公市| 东兰县| 五原县| 溆浦县| 阿巴嘎旗| 望城县| 五台县| 石棉县| 桦甸市| 聂荣县| 大邑县| 交口县| 二连浩特市| 临桂县| 馆陶县| 德化县| 会东县| 自治县| 广灵县| 滨州市| 鹿邑县| 元阳县| 广西| 东城区| 原平市| 梨树县| 任丘市|