Skip to content

Commit de25f0d

Browse files
Add OP_MIN page
1 parent 4f1f2d4 commit de25f0d

2 files changed

Lines changed: 54 additions & 4 deletions

File tree

.vitepress/config.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ export default {
176176
{ text: "<code>160 | OP_GREATERTHAN</code>", link: "/opcodes/OP_GREATERTHAN.md" },
177177
{ text: "<code>161 | OP_LESSTHANOREQUAL</code>", link: "/opcodes/OP_LESSTHANOREQUAL.md" },
178178
{ text: "<code>162 | OP_GREATERTHANOREQUAL</code>", link: "/opcodes/OP_GREATERTHANOREQUAL.md" },
179-
{ text: "<code>163 | 🚧 OP_MIN</code>", link: "/opcodes/OP_MIN.md" },
179+
{ text: "<code>163 | OP_MIN</code>", link: "/opcodes/OP_MIN.md" },
180180
{ 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" },

opcodes/OP_MIN.md

Lines changed: 53 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,55 @@
1-
# Work In Progress
1+
# OP_MIN
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:** 163
5+
**Byte representation:** `0xa3`
6+
**Short description:** Pop the top two items; push the smaller of the two onto the stack.
57
:::
8+
9+
`OP_MIN` compares the top two items on the stack as integers and pushes the smaller value back onto the stack. Both original items are removed, and the smaller value becomes the new top item.
10+
11+
### Operation
12+
1. Pop the top item and the second item from the stack.
13+
2. Compare the two items, and push the smaller of the two values onto the stack.
14+
15+
### Notes
16+
17+
- Both items must be valid integers. Bitcoin Script interprets byte arrays up to **4 bytes** as integers.
18+
- An empty array (`[]`) is treated as 0 when compared.
19+
- If there are fewer than two items on the stack when `OP_GREATERTHAN` is executed, the script will fail.
20+
21+
## Examples
22+
23+
### Example 1: Comparing two positive integers
24+
25+
```shell
26+
# ASM script
27+
OP_3 OP_2 OP_MIN
28+
29+
# Raw script
30+
5352a3
31+
32+
# Stack (before OP_MIN)
33+
2 # top
34+
3
35+
36+
# Stack (after OP_MIN)
37+
2 # smaller value
38+
```
39+
40+
### Example 2: Comparing a positive and a negative integer
41+
42+
```shell
43+
# ASM script
44+
OP_1NEGATE OP_2 OP_MIN
45+
46+
# Raw script
47+
4f52a3
48+
49+
# Stack (before OP_MIN)
50+
2 # top
51+
-1
52+
53+
# Stack (after OP_MIN)
54+
-1 # smaller value
55+
```

0 commit comments

Comments
 (0)