> For the complete documentation index, see [llms.txt](https://digitalgarden.batamladen.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://digitalgarden.batamladen.com/notes/programming/assembly/assembly-8086/examples-projects/addition-of-two-8-bit-numbers.md).

# Addition of two 8-bit numbers

{% tabs %}
{% tab title="First Tab" %}

```
data segment
a db 09h
b db 0fh 
c dw ?
data ends


code segment
assume cs:code, ds:data
start:

mov ax, data
mov ds, ax

mov al, a
mov bl, b
add al, bl
mov c, ax

mov ah,4ch
int 21h

code ends 
end start 
```

{% endtab %}
{% endtabs %}

## Understand the code

### Data Segment:

data segment: This section defines the variables.&#x20;

<mark style="color:yellow;">**a db 09h**</mark>**:** Declares an 8-bit byte variable a initialized to 09h (hexadecimal).&#x20;

<mark style="color:yellow;">**b db 02h**</mark>**:** Declares an 8-bit byte variable b initialized to 02h.&#x20;

<mark style="color:yellow;">**c dw ?**</mark>**:** Declares a 16-bit word variable c to store the sum. We use a 16-bit variable to handle potential overflow if the sum exceeds 255 (FFh).

### Code Segment:

<mark style="color:yellow;">**code segment**</mark>**:** This section contains the program instructions. ; assume cs:code,ds:data: Tells the assembler that the cs register points to the code segment and the ds register points to the data segment.&#x20;

<mark style="color:yellow;">**start**</mark>**:** The label marking the program’s entry point.&#x20;

<mark style="color:yellow;">**mov ax,data**</mark>**:** Loads the address of the data segment into the ax register.&#x20;

<mark style="color:yellow;">**mov ds,ax**</mark>**:** Sets the ds register to point to the data segment. This is crucial for accessing the variables a and b.&#x20;

<mark style="color:yellow;">**mov al,a**</mark>**:** Loads the value of a (09h) into the al register (the lower 8 bits of ax).&#x20;

<mark style="color:yellow;">**mov bl,b**</mark>**:** Loads the value of b (02h) into the bl register (the lower 8 bits of bx).&#x20;

<mark style="color:yellow;">**add al,bl**</mark>**:** Adds the contents of bl to al. The result (0Bh) is stored in al.&#x20;

<mark style="color:yellow;">**mov c,ax**</mark>**:** Moves the contents of ax (which now contains the sum in its lower byte, al) into the variable c.&#x20;

<mark style="color:yellow;">**int 3**</mark>**:** The breakpoint instruction halts execution for debugging purposes.


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## 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, and the optional `goal` query parameter:

```
GET https://digitalgarden.batamladen.com/notes/programming/assembly/assembly-8086/examples-projects/addition-of-two-8-bit-numbers.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

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.
