# interlocked\_exchange\_add

### Function

> interlocked\_exchange\_add

### Syntax

> interlocked\_exchange\_add( \*Variable, Expression );

### Parameters

**\[\*Variable (Addend)]**

A reference to a variable (most of the time a global variable) to add the value of the resulting instruction to it.

**\[Expression (Value)]**

The value which is added to the global variable.

### Description

Performs an atomic addition of two values.

### Return value

The function returns the initial value of the `Variable(Addend)` parameter.

### Examples

`Result = interlocked_exchange_add(.my_gloabl_counter, 0x55);`

Adds the value (`0x55`) to the global variable and saves the initial value of the `.my_gloabl_counter` into a local variable named `Result`.

### Remarks

You can also perform the subtraction by addition (using the 2's-complement system).

### Related

[interlocked\_compare\_exchange](https://docs.hyperdbg.org/commands/scripting-language/functions/interlocked/interlocked_compare_exchange)

[interlocked\_increment](https://docs.hyperdbg.org/commands/scripting-language/functions/interlocked/interlocked_increment)

[interlocked\_exchange](https://docs.hyperdbg.org/commands/scripting-language/functions/interlocked/interlocked_exchange)

[interlocked\_decrement](https://docs.hyperdbg.org/commands/scripting-language/functions/interlocked/interlocked_decrement)


---

# 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://docs.hyperdbg.org/commands/scripting-language/functions/interlocked/interlocked_exchange_add.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.
