0xmiden/agent-tools/cheap-masm-equivalents
Claude Code and agent skill by 0xmiden/agent-tools
- community
Checking that the SKILL.md file is still in the repository.
Use when writing or reviewing MASM hot paths or loops — prefer the cheaper equivalent: loop counters and pointers on the operand stack instead of procedure locals, `neq.0` over `push.0 gt` for non-zero checks, `cdrop` over an `if/else` selecting between two values, `dup.N` over `loc_load` for a value still on the stack, `eqw` over hand-rolled element-wise word comparison, `u32gt`/`u32lt` over generic `gt`/`lt` on known-u32 operands.
Install
npx vskill@latest install 0xmiden/agent-tools/cheap-masm-equivalentsSKILL.md
Prefer Cheap MASM Equivalents
Rule
Several MASM idioms have a cheap and an expensive form. Use the cheap one when both produce the same result on the inputs the procedure can see:
- Loop variables (counters, pointers, indices): keep them on the operand stack across iterations instead of in procedure locals. See below.
- Non-zero check:
neq.0(3 cycles) overgt.0(16 cycles). - Selecting between two values on a flag:
cdropover anif.true ... else ... endbranch with the same effect. - Re-fetch a recently-pushed value:
dup.Noverloc_load.Nwhen the value is still on the stack. - Whole-word equality:
eqwover element-wise comparisons. - u32-known operands:
u32gt/u32ltover genericgt/lt.
Don't apply the cheap form when the operands violate its precondition (e.g. u32gt on a value that might exceed u32::MAX).
Why
MASM cycle costs are not uniform — gt.0 does signed-comparison work that neq.0 skips, so a hot path using the expensive form pays for it on every call. The swaps are semantically equivalent under their preconditions, so the saving is free.
Examples
Loop Variables Belong on the Stack
A procedure local is not a register: loc_load.i costs 5 cycles and loc_store.i costs 6. Reaching the same value on the stack with dup.n, swap, movup.n or movdn.n (usually) costs 1 cycle. So a loop that keeps its counter and pointer in locals pays 5-11 cycles per access, per iteration, for data the stack could hold for 1.
Read once, mutate in place:
Working around call
The reason to reach for a local is a call: the callee takes the top 16 elements, so while those 16 slots are being filled, nothing below them is addressable by dup.n. Values that only have to survive the call are fine on the stack - they sit in the overflow and come back untouched. Only a value that must be re-read while the frame is being built has to live in a local, and even then it is one local, not one per loop variable.
Security
- Security scanPassed, 100 of 100Pattern checks on the skill's files.
- Model reviewPassed
Quality evaluation
- Task evaluationNot runNo evaluation yet. Run one in Skill Studio.
Source
- SKILL.md in the repositoryCheckingskills/cheap-masm-equivalents/SKILL.md
Popularity
- Repository stars
- 2
- Repository forks
- 3
- 7-day trend score
- 0
Stars and forks are for the whole GitHub repository, not this skill alone. Not refreshed yet.
Works with
Any agent vskill installs to: 56 targets in all. These 39 have a page on this site.
- Claude Code
- Cursor
- GitHub Copilot
- Windsurf
- Codex
- Gemini CLI
- Cline
- Amp
- Roo Code
- Goose
- Continue
- Kilo Code
- Junie
- Trae
- OpenHands
- Qwen Code
- AI Agent
- Tabnine Chat
- Sourcegraph Cody
- Amazon Q
- Firebase Genkit
- Sweep
- Devin
- Phind
- Mentat
- Claude Desktop
- Aider
- GPT Pilot
- Plandex
- bolt.new
- v0
- Replit Agent
- Anse
- TypingMind
- BetterChatGPT
- LibreChat
- Warp AI
- Pieces
- Fig AI
Embed badge
[](https://verified-skill.com/skills/0xmiden/agent-tools/cheap-masm-equivalents)