; R8 is the buffer the function will write the output to.
; most GPRs must be 0'd!
mov al, 'a'
or r8, buf ; Suprise! It's more efficient to write it this way, the equivilent mov requires 3 bytes of padding to follow.
mov byte [r8+rbx], al
mov byte [r8+rbx+1], 0Ah
add ebx, 2
cmp al, 'z'
mov ecx, edx
mov byte [r8+rbx], ' '
; cx is used here. Be aware!
Try it online!
I spent a fair while doing this one. Seriously, some things will slowly drive you insane.
This function outputs a buffer containing the requested data. Said buffer is in the .bss section.
NOTE: It doesn't seem to work on TIO for some reason. Works perfectly fine on my laptop. I built it using the following commands:
nasm -felf64 diagonal-alphabet_125117.s
gcc diagonal-alphabet_125117.o -no-pie
For your viewing pleasure, the TIO version is modified to use the data section instead, so it actually runs.
The bytecount is currently based on the bytecount of the function and the 8 bytes needed to represent the length of .bss
Note to future readers: A CC where most GPRs must be 0'd can be useful, because
or is shorter than
mov, at least in the case demonstrated above.