> 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="https://2490252025-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FUwIKQPujWqWSVFxQaX98%2Fuploads%2FfYG3jOtV5asRq5alwdxk%2Fflowchart1.PNG?alt=media&amp;token=50e97f44-6d81-4d06-9595-a022595446e1" 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 by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

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

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

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.
