16-bit operations
userland
Perform operations on 16 bit data with an 8 bit machine.
This section uses a concept called accumulator staging. Similar to exchanging, accumulator staging provides the writeback two cycles later which allows the programmer to do a single-cycle instruction before the accumulator is automatically reflected as the register again.
fetch | fetch | decode | decode | execute | writeback |
---|---|---|---|---|---|
xch ra |
load ra |
write acc to reg | written to acc |
From the instruction above, this behaviour is changed to:
fetch | fetch | decode | decode | execute | writeback |
---|---|---|---|---|---|
stg ra |
load ra |
written to acc | |||
(e.g.) bsl 1 |
barrel shift left | written to acc, write to reg (from staging) |
A hazard is that the second next instruction after stg
cannot be a register store.
1 16-bit accumulative addition
xy += lh
(4 bytes)
stg rx ; low byte
add rl ; low byte offset
stg ry ; high byte addc rh ; high byte offset
2 16-bit increment
xy += 1
(3 bytes)
inc rx ; write back rx
stg ry ; stages/writes back ry addc zr ; propagate carry (adds zero)
3 16-bit add immediate with 8-bit constant
xy + imml
(5 bytes)
stg rx ; stages/writes back rx
addi 0x## ; adds 8 bit to rx
stg ry ; stages/writes back ry addc zr ; 3 instructions ago, but imm doesn't change acc, so valid
4 16-bit copy
lh = xy
(4 bytes)
ast rx
rst rl
ast ry rst rh