Nasm
  • Introduction
  • X86
  • 使用GDB
  • Section (.data .text .bss)
  • 運算子與變數
  • 推薦書籍
Powered by GitBook
On this page
  • 在Nasm檔案中分為三個區塊。
  • .data
  • .bss
  • .text
  • 註解

Was this helpful?

Section (.data .text .bss)

在Nasm檔案中分為三個區塊。

會用以下來區分。

section .data
.....

section .text
.....

section .bss
....

.data

此區塊主要用來定義常數與初始化的值

section .data

  filename db "this.txt"

.bss

可用來保存變數。

section .bss

  variable: resb 4

上面這段代表宣告了一個變數名為variable,含有4 bytes。

之後可以用類似如下方法,把某個暫存器的值移到該變數。

mov [variable], eax

或是將變數移回暫存器

mov eax, [variable]

.text

此區段為主要的程式碼區塊。

section.text
   global _start
_start:
 .....

註解

使用分號來代表註解。

add eax, ebx   ; 分號後面是註解 adds ebx to eax
Previous使用GDBNext運算子與變數

Last updated 5 years ago

Was this helpful?

https://stackoverflow.com/a/8145374