Skip to content

Commit a79ccc2

Browse files
Add OP_MAX page
1 parent 6b1ba8a commit a79ccc2

File tree

2 files changed

+55
-4
lines changed

2 files changed

+55
-4
lines changed

.vitepress/config.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ export default {
177177
{ text: "<code>161 | OP_LESSTHANOREQUAL</code>", link: "/opcodes/OP_LESSTHANOREQUAL.md" },
178178
{ text: "<code>162 | OP_GREATERTHANOREQUAL</code>", link: "/opcodes/OP_GREATERTHANOREQUAL.md" },
179179
{ text: "<code>163 | OP_MIN</code>", link: "/opcodes/OP_MIN.md" },
180-
{ text: "<code>164 | 🚧 OP_MAX</code>", link: "/opcodes/OP_MAX.md" },
180+
{ text: "<code>164 | OP_MAX</code>", link: "/opcodes/OP_MAX.md" },
181181
{ text: "<code>165 | 🚧 OP_WITHIN</code>", link: "/opcodes/OP_WITHIN.md" },
182182
{ text: "<code>166 | OP_RIPEMD160</code>", link: "/opcodes/OP_RIPEMD160.md" },
183183
{ text: "<code>167 | OP_SHA1</code>", link: "/opcodes/OP_SHA1.md" },

opcodes/OP_MAX.md

Lines changed: 54 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,56 @@
1-
# Work In Progress
1+
# OP_MAX
22

3-
:::warning
4-
This page has not yet been written. If you have experience with bitcoin Script and would like to contribute, please do! You can open a PR [on the repository for this website](https://github.com/thunderbiscuit/opcode-explained).
3+
:::info
4+
**Opcode number:** 164
5+
**Byte representation:** `0xa4`
6+
**Short description:** Pop the top two items; push the larger of the two onto the stack.
57
:::
8+
9+
`OP_MAX` compares the top two items on the stack as integers and pushes the larger value back onto the stack. Both original items are removed, and the larger value becomes the new top item.
10+
11+
### Operation
12+
13+
1. Pop the top item and the second item from the stack.
14+
2. Compare the two items, and push the larger of the two values onto the stack.
15+
16+
### Notes
17+
18+
- Both items must be valid integers. Bitcoin Script interprets byte arrays up to **4 bytes** as integers.
19+
- An empty array (`[]`) is treated as 0 when compared.
20+
- If there are fewer than two items on the stack when `OP_MAX` is executed, the script will fail.
21+
22+
## Examples
23+
24+
### Example 1: Comparing two positive integers
25+
26+
```shell
27+
# ASM script
28+
OP_3 OP_2 OP_MAX
29+
30+
# Raw script
31+
5352a4
32+
33+
# Stack (before OP_MAX)
34+
2 # top
35+
3
36+
37+
# Stack (after OP_MAX)
38+
3 # larger value
39+
```
40+
41+
### Example 2: Comparing a positive and a negative integer
42+
43+
```shell
44+
# ASM script
45+
OP_1NEGATE OP_2 OP_MAX
46+
47+
# Raw script
48+
4f52a4
49+
50+
# Stack (before OP_MAX)
51+
2 # top
52+
-1
53+
54+
# Stack (after OP_MAX)
55+
2 # larger value
56+
```

0 commit comments

Comments
 (0)