> For the complete documentation index, see [llms.txt](https://alham-rizvi.gitbook.io/alhamrizvi/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://alham-rizvi.gitbook.io/alhamrizvi/picoctf-writeups/picoctf/reverse-engineering/armssembly-0.md).

# ARMssembly 0

We're given an ARM64 assembly file and two numbers. We need to figure out what the program prints, then convert it to a flag.

### Step 1: Understanding the Structure

The program has two functions:

* **`main`** → takes command line arguments, calls `func1`
* **`func1`** → does some comparison logic, returns a value

### Step 2: Reading func1 (The Important Part)

```asm
func1:
    str  w0, [sp, 12]    ; save first argument (a)
    str  w1, [sp, 8]     ; save second argument (b)
    ldr  w1, [sp, 12]    ; load a
    ldr  w0, [sp, 8]     ; load b
    cmp  w1, w0          ; compare a and b
    bls  .L2             ; if a <= b (unsigned), jump to L2
    ldr  w0, [sp, 12]    ; else return a
    b    .L3
.L2:
    ldr  w0, [sp, 8]     ; return b
```

The key instruction is **`bls`** = "Branch if Lower or Same" (unsigned comparison)

In simple terms:

```
if (a > b):
    return a
else:
    return b
```

> 💡 **This is just a MAX function!** It returns whichever number is bigger.

### Step 3: Reading main

```asm
main:
    ; reads argv[1] → converts to int → stored in w19  (this is 'a')
    ; reads argv[2] → converts to int → stored in w1   (this is 'b')
    ; calls func1(a, b)
    ; prints "Result: %ld\n" with the return value
```

So main just:

1. Takes two numbers from command line
2. Passes them to func1
3. Prints the result

### Step 4: Plug in the Numbers

Given:

* **a = 2593949075**
* **b = 2233560849**

Since `func1` returns the maximum:

```
max(2593949075, 2233560849) = 2593949075
```

**a is bigger, so the answer is 2593949075**

### Step 5: Convert to Flag Format

The flag format requires the number in **32-bit hex, lowercase, no 0x**

```
2593949075 in hex = 9A9C8593
lowercase         = 9a9c8593
```

### Final Flag

```
picoCTF{9a9c8593}
```

### Summary in One Line

> The program finds the **maximum of two numbers** using unsigned comparison (`bls`), and since **2593949075 > 2233560849**, it prints **2593949075**, which is **`9a9c8593`** in hex.


---

# 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://alham-rizvi.gitbook.io/alhamrizvi/picoctf-writeups/picoctf/reverse-engineering/armssembly-0.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.
