This is our first assembly language puzzle for the new site! These puzzles are tests to seeÂ whether you are good enough of an assembly nerd, and to learn some tricks if you’re not =^_^=
Our first puzzle is of a classic type: size optimization.Â It is for x86-32 assembly language, certainly the most widely known assembly language.Â We will definitely do other puzzles for other processors though!
You might find that many of these puzzles are good ideas to place into compilers and other automated assembly/machine code generators.
The puzzle: In terms of opcode bytes, find the smallest sequence of x86-32 instructions to implement the following C/C++ code:
if ((x == 0) || (y == 0))
Â Â Â goto label;
- x and y are 32-bit integers or pointers.
- x and y are each already in general-purpose registers or memory locations of your choice.
- Do not assume a particular state of the flags, except that you may assume the direction flag is always clear as that is its usual state.
- You may destroy any general-purpose registers or memory locations as you see fit, including the locations of x and y.
- Assume that label is within range of a short jump.
- Do not assume that you have access to protected instructions.
- In general, answers that are the same size but faster or less destructive are considered better than others.
I was rather verbose in the rules because it’s the first puzzle.Â Future puzzles won’t necessarily mention these restrictions.
Answers that don’t fit all the rules but have other merits like creativity are certainly welcomed!
The smallest answer I could find was 6 bytes.Â The straightforward answer is 8 bytes.Â Good luck!
(check comments for solution(s))