# Assemby + C - Part # 2

<figure><img src="/files/wmVtT28xfVmzLZH6TGvp" alt=""><figcaption></figcaption></figure>

### Background: Endianess

* Endianess comes from jonathan Swift's Gulliver's Travels. In which people go to war over the correct way to eat soft boiled eggs!
* Little Endian - 0x12345678 stored in RAM "little end first". The least significant byte (LSB) of a word or larger is stored in the lowest address. E.g 0x78, 0x56, 0x34, 0x12
* Big Endian - 0x12345678 stored in RAM "big end" first. The most significant byte (MSB) of a word or larger is stored in the lowest address. Eg: 0x12,0x34, 0x56, 0x78
  * Network traffic is sent Big Endian (do "man byteorder" to see POSIX network-to-host oredering functions)
  * Many RISC systems (PowerPC, SPARC, MIPS, Motorola 68k) started as Big Endian but can now be configured as either (Bi-Endian). ARM started out Littled Endian and now is Bi-Endian.
* Endianess applies to memory, not registers
* Endianess applies to bytes, not bits

<figure><img src="/files/2h4Pq6XuXkccUS1YH1zB" alt=""><figcaption></figcaption></figure>

#### Endianess visualization

<figure><img src="/files/CVrF1vBFEXdI3ss7WDyy" alt=""><figcaption></figcaption></figure>

#### How you'll probably usually see endianness expressed:

<figure><img src="/files/LG3rE3zOx0QrKO7M9pcA" alt=""><figcaption></figcaption></figure>

If you start asking the debugging to display things, 2, 4, or 8 bytes at a time. it will typically take those chunks and display them each big endian order.

<figure><img src="/files/2FqbiXRmIRzpSYY75z8B" alt=""><figcaption></figcaption></figure>

#### Endianness example in GBD

<figure><img src="/files/0XCA64sT0onjugHEP7hH" alt=""><figcaption></figcaption></figure>

If you start asking the debugging to display things, 2, 4, or 8 bytes at a time. it will typically take those chunks and display them each big endian order.

### Computer Memory Hierarchy

<figure><img src="/files/nZpPBAAm4yjm6okbk72m" alt=""><figcaption></figcaption></figure>

### x86-64 general purpose registers

<figure><img src="/files/m1J1dcsSEvOtRMg4AGSm" alt=""><figcaption></figcaption></figure>

#### Architecture - Registers

* Registers are small memory storage areas built into the processor (still volatile memory)
* Intel has 16 "general purpose" registers + instruction pointer which points at the next instruction to execute
  * But 2 of the 16 are not that general
* On x86-32, registers are 32 bits wide
* On x86-64, registers are 64 bits wide

#### Intel Register Evolution

* 8-bit 8008

<figure><img src="/files/K8Ic2DKV9PppZSD27UIc" alt=""><figcaption></figcaption></figure>

* 16-bit 8086

<figure><img src="/files/MgPTYAvKVQ9sg6tUFGeO" alt=""><figcaption></figcaption></figure>

* 32 bit 80386

<figure><img src="/files/OEWQxiu9omY1VwfFNdoY" alt=""><figcaption></figcaption></figure>

* 64-bit AMD Opteron / Intel Pentuim 4&#x20;

<figure><img src="/files/lWiPCPayqNHa5hFL7EaW" alt=""><figcaption></figcaption></figure>

&#x20;Or the new naming format as the following:

<figure><img src="/files/QrYiWUAKJgt5kIcMCuow" alt=""><figcaption></figcaption></figure>

For more you can visit the following link: <https://www.csie.ntu.edu.tw/\\~cyy/courses/assembly/09fall/lectures/handouts/lec12\\_x86arch\\_4up.pdf>

#### Intel recommended register conventions

There are Intel's suggestions to compiler developers (and assembly handcoders). Registers don't have to be used these ways, but if you see them being used like this, you'll know why. But I simplified some descriptions. I also coded as GREEN for the ones which we will actually see in the following parts (as opposed to future ones), and RED for not.

<figure><img src="/files/dBdZV5cNRtvd05cgZTb6" alt=""><figcaption></figcaption></figure>

<https://learn.microsoft.com/en-us/cpp/build/x64-software-conventions?view=msvc-160>


---

# 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://w43l.gitbook.io/ctihandboook/learning-assembly/assemby-+-c-part-2.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.
