Wednesday, 24 December 2008

Write Number (implemented using a data stack)

Here's an alternative version of the routine to display numbers using exMARS Stream's sts opcode. The code executes in 8x+1 cycles, where x is the number of digits. This implementation uses a data stack.
printd  mov.a  *stack,    {stack
div.a #10, }stack
mod.a #10, *stack
add.a #48, *stack
add #1, pcount
jmn.a printd, {stack
add.a #1, stack
ploop sts.a }stack, 0
pcount djn ploop, #0

Sunday, 7 December 2008

Hello World in Redcode

Here's the shortest "Hello, World!" program I could implement, written using the sts opcode which is available in exMARS Streams.

write   sts.a  hello,     0
sts.b }write, 0
djn write, #7

hello dat 72, 101
dat 108, 108
dat 111, 44
dat 32, 87
dat 111, 114
dat 108, 100
dat 33, 10