Re:How recursion got into Algol 60: a comedy of errors
by userbinator on Friday August 28, 2015 @12:05AM
(#10133685)
The "calling itself inline" pattern is well known in the demoscene/sizecoding community as a way to repeat something a small fixed number of times with neither an explicit loop nor duplicating code, and probably was independently discovered by quite a few individuals.
Here is one of the more interesting applications, a function that converts a 16-bit word in a register to a string of 4 hex digits in only 24 bytes of code, and can also be called to convert bytes and nybbles (x86):
; output value of AX as four hex digits to ES:DI
write_hex_word:
xchg al, ah
call write_hex_byte
xchg al, ah
; output value of AL as two hex digits to ES:DI
write_hex_byte:
push ax
shr al, 4
call write_hex_nybble
pop ax
; output lower nybble of AL as hex digit to ES:DI
write_hex_nybble:
and al, 15
cmp al, 10
sbb al, 69h
das
stosb
ret
Here is one of the more interesting applications, a function that converts a 16-bit word in a register to a string of 4 hex digits in only 24 bytes of code, and can also be called to convert bytes and nybbles (x86):