# Instructions thường gặp

## Một số câu lệnh hay gặp mà khó hiểu))):

* `std` (Set Direction Flag) - câu lệnh dùng để set cờ `DF = 1`
* `setalc` or `salc`- câu lệnh dùng set thanh ghi `al` dựa trên cờ `CF` (nếu `CF = 0` thì `al` = 0 còn nếu `CF = 1` thì giá trị của `al` = 0xff)
* `repe scasb` - câu lệnh dùng để lặp cho tới khi gặp ô nhớ đầu tiên nào đó khác giá trị thanh ghi `al`, or stops at the limit set by ECX.
  * `SCAS/SCASB/SCASW/SCASD` - scan string ([Link](https://c9x.me/x86/html/file_module_x86_id_287.html))
* `cld` (Clear Direction Flag) - câu lệnh làm sạch cờ `DF` (đại lại là set cờ `DF` = 0) và không làm ảnh hưởng đến các cờ khác
* `LODS/LODSB/LODSW/LODSD` - câu lệnh load string into AL, AX, EAX ([Link](https://c9x.me/x86/html/file_module_x86_id_160.html))
* `int 1` - câu lệnh dùng để đi tới vị trí đầu tiên của Interrupt Vector Table, nếu muốn nhận giá trị sau khi xử lý ngoại lệ thì trước khi thực thi ta sẽ gán giá trị của EAX = 0 sau đó chạy thì ta sẽ nhận được giá trị được lưu vào thanh ghi eax, rồi đem biến đổi theo phương pháp toán học + - \* / là nhận được kết quả mong muốn.
* `call $+num` - là câu lệnh dùng để gọi đến address hiện tại của câu lệnh call + với num là 1 số bất kỳ. Khi đó thanh ghi EIP sẽ thay đổi (giá trị đó tương đương với địa chỉ tiếp theo được thực hiện).
* `ds:[address]` - câu lệnh dùng để gán giá trị mới cho thanh ghi EIP or RIP từ vùng nhớ tại `address` (đây là con trỏ function) và nó sẽ trả về địa chỉ return (vì nó là a call not just a jump)

## Ref

1. [Hiểu hơn về rep (repe hay repne)](https://stackoverflow.com/questions/58121065/im-trying-to-understand-the-rep-scasb-byte-edi-instruction)
2. [Các câu lệnh assembly x86 được toán lược hóa](https://c9x.me/x86/)
3. [SEH là gì?](http://diendan.congdongcviet.com/threads/t66004::structured-exception-handling-seh-c-exception-handling-khac-nhau-nhu-the-nao.cpp)
4. [Anti-Debug?](https://anti-debug.checkpoint.com/techniques/assembly.html)
5. [ds:\[address\] là gì?](https://stackoverflow.com/questions/3819699/what-does-ds40207a-mean-in-assembly)


---

# 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://viettaliii.gitbook.io/home/education/reverse-engineering/assembly-x86-64/instructions-thuong-gap.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.
