> 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-16-bit-numbers.md).

# Addition of two 16-bit numbers

{% tabs %}
{% tab title="code.asm" %}

```
data segment 
a dw 0202h
b dw 0408h
c dw ?
data ends


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

mov ax, data
mov ds, ax
mov ax, a 
mov bx, b
add ax, bx
mov c, ax

int 3

code ends
end start
```

{% endtab %}

{% tab title="flowchart.pgn" %}

<figure><img src="/files/BwviT8N9MDtaP3yZuK38" alt=""><figcaption></figcaption></figure>
{% endtab %}
{% endtabs %}

## Understand the code

### Data Segment&#x20;

<mark style="color:yellow;">**a dw 0202h**</mark>: This line declares a 16-bit word variable named a and initializes it with the hexadecimal value 0202.&#x20;

<mark style="color:yellow;">**b dw 0408h**</mark>: Similarly, this declares a 16-bit word variable b and initializes it with the hexadecimal value 0408.&#x20;

<mark style="color:yellow;">**c dw ?**</mark>: This declares a 16-bit word variable c but does not initialize it. It will store the result of the addition operation.

### Code Segment&#x20;

<mark style="color:yellow;">**mov ax,data**</mark>**:** This instruction moves the address of the data segment into the AX register.

**mov ds,ax**: This sets the Data Segment (DS) register to the value in AX, effectively making the data segment accessible for data operations.

<mark style="color:yellow;">**mov ax,a**</mark>**:** This moves the value of a (0202h) into the AX register.

<mark style="color:yellow;">**mov bx,b**</mark>**:** This moves the value of b (0408h) into the BX register.

<mark style="color:yellow;">**add ax,bx**</mark>**:** This adds the contents of BX to the contents of AX. The result (060Ah) is stored in AX. ; mov c,ax: This moves the result from AX to the variable c.&#x20;

<mark style="color:yellow;">**int 3**</mark>**:** This is a breakpoint instruction that causes the program to halt, allowing for debugging and inspection of registers and memory.

### Overall Functionality&#x20;

The code performs the following steps:&#x20;

<mark style="color:yellow;">**Initialization**</mark>**:** Sets up the data segment and initializes variables a and b. ; Addition: Loads the values of a and b into registers AX and BX, respectively. Adds the two values and stores the result in AX.

<mark style="color:yellow;">**Result Storage**</mark>**:** Stores the result from AX into the variable c.&#x20;

<mark style="color:yellow;">**Program Termination**</mark>**:** Halts the program execution using the int 3 instruction.&#x20;

In essence, this code adds two 16-bit hexadecimal numbers (0202h and 0408h) and stores the result (060Ah) in the variable c.


---

# 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-16-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.
