Aug 14, 2019
Stack manipulations in SubX

I've been noodling on a Forth-inspired (but likely insane) syntactic sugar for stack manipulations in raw machine code. Behold:

{ 0 0 ->%ecx
...
}

This expands to:

push 0/imm32
push 0/imm32
copy %esp to %ecx
...
add 8 to %esp

Basically you get a (fairly unsafe) block scope containing an 8-byte local in %ecx.

To temporarily spill a register:

{ %ecx
...
}

Function call:

{ z y x
call f/disp32
}

The `}` turns into code to undo pushes in the `{` line.

This post is part of my Freewheeling Apps Devlog.

Comments gratefully appreciated. Please send them to me by any method of your choice and I'll include them here.

archive
projects
writings
videos
subscribe
Mastodon
RSS (?)
twtxt (?)
Station (?)