Hi, folks.
We added a file (debug.mac) to all exercises, with various macros for debugging support. This file was based on a similar one in the test runner repo, but expanded and documented.
The macros have a name with the following format:
debug + type + size
The type here indicates how the value should be interpreted:
- d - signed integer in decimal format.
- u - unsigned integer in decimal format.
- x - unsigned integer in hexadecimal format.
- f - a floating-point number.
- c - a character.
- s - a NUL-terminated string.
The size indicates the number of bits of the operand. It can be 8, 16, 32 or 64. It is necessary for all macros except those that print characters (debugc) or strings (debugs).
For example, debugd64 prints 64-bit signed integers and debugf32 prints 32-bit floating-point numbers.
There are also macros to print the contents of a 128-bit SIMD operand. In that case, the size indicates the width of each lane, and they have a “_xmm” at the end, e.g., debugu8_xmm.
For example, debugu32_xmm interprets its arguments as 4 packed 32-bit unsigned integers, while debugf64_xmm interprets its arguments as 2 packed 64-bit floating-point numbers.
All macros should be called with one or more arguments of the appropriate size. In case of multiple arguments, they should be separated by a comma: debugx8 al, cl, dl, r8b.
Memory arguments should be passed in brackets, e.g., [rax] or [my_label]. The exception is debugs, which expects a memory address without brackets.
To use these macros, the file must be explicitly included at the top of the solution file:
%include "debug.mac"
All of this is documented on the file itself and should also be mentioned on help.md (if you work locally) or below the instructions for the exercise (if you use the online editor).
In the future, we will try to add support for 256-bit and 512-bit SIMD operands and for printing flags such as ZF or CF.