3 ms·
Depends on how it expects the parameter and the result. If the parameter is the second item down on the stack and the compiler wants the result in hl with the
by Lerc 10y ago
Depends on how it expects the parameter and the result.
If the parameter is the second item down on the stack and the compiler wants the result in hl with the stack unchanged.
pop bc
pop hl
push hl
push bc
isn't redundant stack manipulation. it's moving stack values to bc and hl while keeping the stack unchanged.
Of course at another level a compiler should be able to inline x=>x*1 but that depends on the build architecture. If it's a linkable function then the contents may be opaque to the code that calls it.
- vardump 10y agoOk, seems like you're right. In SDCC function params are always passed on stack, but return value in HL. So pop hl/push hl moves function parameter to return value register HL. (pop/push bc is of course just used to get past return address value in stack.) Seems odd compiler doesn't pass parameters in registers in a relatively register rich z80 arch.