Hello everyone,
I was wondering how I could use unions to combine registers elegantly. For example I have the 8 bit registers B and C & I have opcodes that work on each independent register such as add b, c, which is simple, but then I also have opcodes that work on both of them as if they're one like ld a, bc. I know I could go about that by just masking them together but I've seen it done with unions before & it made everything so much more simple.
Thanks in advance
On most but not necessarily all compilers... and on little endian systems... this will result in 'a' occupying the low 8 bits of 'ab' and 'b' occupying the high 8 bits of 'ab'.
But again... not portable, relies on undefined behavior... etc, etc, etc. I don't recommend it.
EDIT:
If you want a portable way to do this that doesn't rely on nasty tricks that may break.... wrap this stuff in a class and use getters/setters: