News for hackers. Stuff that matters.
Re:Writing a Self-Mutating x86_64 C Program (2013) by Someone on Friday January 11, 2019 @01:33PM (#18885659)
Before COUs supported stacks, quite a few compilers produced self-modifying code.

Instead of using a stack, many CPUs stored the address to return to in a specific register. If a function wanted to call other functions and return afterwards, it had to store that return address somewhere. Popular solutions where “directly before the start of the function” and “in the jump instruction at the end of the function”. The former is easier for the compiler writer, the latter leads to faster code (the return becomes a simple unconditional jump. With the other approach, you have to load the return address and then jump to it)

And yes, you can’t have reentrant code or even recursion that way. That’s one reason early COBOL and early FORTRAN didn’t support recursion.

Re:Writing a Self-Mutating x86_64 C Program (2013) by benj111 on Friday January 11, 2019 @02:59PM (#18886385)
Thanks for that.

Presumably you could have tail call recursion. Although if this is pre stacks, tail call detection is probably asking a bit much.

Re:Writing a Self-Mutating x86_64 C Program (2013) by Someone on Sunday January 13, 2019 @12:03PM (#18897445)
You could, but I’m not sure the idea had been discovered yet. https://en.wikipedia.org/wiki/Tail_call#History gives 1977 as its first mention (Steele’s ”Debunking the 'Expensive Procedure Call' Myth“ https://dspace.mit.edu/handle/1721.1/5753#files-area)

Also, many tail-calling functions eventually have to return.