# 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]
```

<https://stackoverflow.com/a/8145374>

### .text

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

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

## 註解

使用分號來代表註解。

```
add eax, ebx   ; 分號後面是註解 adds ebx to eax
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://easonwang.gitbook.io/nasm/section-data-text-bss.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
