# x86-64 Assembly

## Intel Register Evolution <a href="#intel-register-evolution" id="intel-register-evolution"></a>

<figure><img src="https://vietzettt.files.wordpress.com/2022/08/image-8.png?w=726" alt=""><figcaption></figcaption></figure>

> * **RSI** – **S**ource **i**ndex pointer for string operations
> * **RDI** – **D**estination **i**ndex pointer for string operations
> * **RSP** – **S**tack (top) **p**ointer
> * **RBP** – Stack frame **b**ase **p**ointer
> * **RIP** – Pointer to next instruction to execute (“**i**nstruction **p**ointer”)

## RFLAGS <a href="#rflags" id="rflags"></a>

<figure><img src="https://vietzettt.files.wordpress.com/2022/08/image-9.png?w=1024" alt=""><figcaption></figcaption></figure>

## Big Endian ans Little Endian <a href="#big-endian-ans-little-endian" id="big-endian-ans-little-endian"></a>

<figure><img src="https://vietzettt.files.wordpress.com/2022/08/image-1.png?w=789" alt=""><figcaption></figcaption></figure>

## IMUL <a href="#imul" id="imul"></a>

<figure><img src="https://vietzettt.files.wordpress.com/2022/08/image-10.png?w=1024" alt=""><figcaption></figcaption></figure>

<figure><img src="https://vietzettt.files.wordpress.com/2022/08/image-13.png?w=1024" alt=""><figcaption></figcaption></figure>

<figure><img src="https://vietzettt.files.wordpress.com/2022/08/image-14.png?w=1024" alt=""><figcaption></figcaption></figure>

<figure><img src="https://vietzettt.files.wordpress.com/2022/08/image-15.png?w=1024" alt=""><figcaption></figcaption></figure>

<figure><img src="https://vietzettt.files.wordpress.com/2022/08/image-16.png?w=1024" alt=""><figcaption></figcaption></figure>

> **Treat 0xF65D29AE99E15E88 mod 2^32 and 0xF28195FB as signed numbers. If they’re negative, then flip them back to positive (with two’s complement) and multiply them. Then if only one of the numbers was negative, flip the sign of the end result (with two’s complement).**
>
> (Ta cần chú ý về số lượng bit của biến đích để lấy từng đó đem nhân với nguồn)
>
> (Đối với imul thì ta cần lưu ý về giá trị âm. Nếu cả 2 giá trị đều là âm thì ta bù 2 cho cả 2 số đó rồi đem nhân là ra kết quả. Nếu chỉ có 1 trong 2 là số âm thì ta bù 2 cho số âm đó, rồi nhân với số còn lại, sau đó ta bù 2 kết quả vừa nhận được thì ta ra được kết quả cần tìm)

> **Divide ax = 0x690F by 0xA5 as signed numbers. That means flip the signs (with two’s complement) until you have a positive dividend (pDividend) and a positive divisor (pDivisor) and do pDividend / pDivisor. That’s your quotient q, which goes into al. Then, if only one of the dividend or divisor was negative, flip the sign of q (with two’s complement.)**
>
> (đối với chia thì ta cũng làm tương tự với nhân)
>
> (ta cần biết là thanh ghi **al, ax, eax, rax** là thanh ghi nhận giá trị thương còn **ah, dx, edx, rdx** là các thanh ghi nhận giá trị số dư của phép chia)

<figure><img src="https://vietzettt.files.wordpress.com/2022/08/image-18.png?w=657" alt=""><figcaption></figcaption></figure>

## CALLER & CALLEE <a href="#caller-callee" id="caller-callee"></a>

<figure><img src="https://vietzettt.files.wordpress.com/2022/08/image-17.png?w=1024" alt=""><figcaption></figcaption></figure>


---

# 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/x86-64-assembly.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.
