# read 'total' value and push to the stack as the bottom element [Space] [Space] [Space] [Space] [LF] # push heap cell address (0) on a stack [Tab][LF] [Tab][Tab] # read a 'total' number and place it in the location given by the top of the stack [Space] [Space] [Space] [Space] [LF] # push heap cell address (0) on a stack [Tab][Tab][Tab] # retrieve 'total' number of iterations and push to the stack # print newline [Space] [Space] [Space] [Tab][Space][Tab][Space] [LF] # push 10 on a top of the stack [Tab][LF][Space][Space] # pop and print character at the top of the stack # validate input on a stack # jump to the end if the input is 0 [Space][LF][Space] # duplicate top element [LF] [Tab][Space] [Tab][Space][Space][Space][Space][Space][Space][Space] [LF] # jump to the end if the input is negative [Space][LF][Space] # duplicate top element [LF] [Tab][Tab] [Tab][Space][Space][Space][Space][Space][Space][Space] [LF] [Space] [Space] [Space] [Tab] [LF] # push main loop counter start value 1 on a stack # set a label for main loop [LF] [Space][Space] [Space][Space][Space][Space][Space][Space][Space][Space] [LF] [Space] [Space] [Space] [Tab] [LF] # push forward-loop counter start value 1 on a stack # set a label for subloop start [LF] [Space][Space] [Space][Space][Space][Space][Space][Tab][Space][Space] [LF] [Space] [LF][Space] # duplicate the number at the top of the stack # choose subloop type (forward/backward) by the value of main loop counter modulo of 2 [Space] [Tab][Space] [Space] [Tab][Space] [LF] # copy item at depth 2, main loop counter [Space] [Space] [Space] [Tab][Space] [LF] # push 2 at the stack [Tab][Space] [Tab][Tab] # calculate modulo of counter % 2 [Space] [Space] [Space] [Tab] [LF] # push 1 on a stack [Tab][Space] [Space][Tab] # decrement output value # if modulo equals to 0, jump to subloop element output label [LF] [Tab][Space] [Space][Space][Space][Space][Space][Space][Space][Tab] [LF] # else, calculate output value as (main loop counter - subloop counter + 1) [Space] [Tab][Space] [Space] [Tab][Space] [LF] # copy item at depth 2, main loop counter [Space] [LF][Tab] # swap two top elements [Tab][Space] [Space][Tab] # decrement (main loop counter - subloop counter) [Space] [Space] [Space] [Tab] [LF] # push 1 on a stack [Tab][Space] [Space][Space] # increment output value # set a label for output element sign calculation [LF] [Space][Space] [Space][Space][Space][Space][Space][Space][Space][Tab] [LF] # if not first element in subloop - negate # calculate top of the stack as (1 - subloop counter) [Space] [Tab][Space] [Space] [Tab] [LF] # copy item at depth 1, subloop counter [Space] [Space] [Space] [Tab] [LF] # push 1 on a stack [Tab][Space] [Space][Tab] # decrement (subloop counter - 1) # if result is 0 - jump to subloop element output [LF] [Tab][Space] [Space][Space][Space][Space][Space][Space][Tab][Space] [LF] # else negate top of the stack (output value) [Space] [Space] [Space] [Space] [LF] # push 0 on a stack [Space] [LF][Tab] # swap two top elements [Tab][Space] [Space][Tab] # negate (0 - output value) # set a label for subloop element output [LF] [Space][Space] [Space][Space][Space][Space][Space][Space][Tab][Space] [LF] [Tab][LF][Space][Tab] # output the number at the top of the stack # increment subloop counter [Space] [Space] [Space] [Tab] [LF] # push 1 on a stack [Tab][Space] [Space][Space] # increment forward loop counter # test subloop end condition [Space] [LF][Space] # duplicate item at the top of the stack (forward loop counter) [Space] [Tab][Space] [Space] [Tab][Space] [LF] # copy item at depth 2, main loop counter [Tab][Space] [Space][Tab] # decrement (forward counter - main counter) [Space] [Space] [Space] [Tab] [LF] # push 1 on a stack [Tab][Space] [Space][Tab] # decrement 1 from result # if result is negative - jump to forward loop start label [LF] [Tab][Tab] [Space][Space][Space][Space][Space][Tab][Space][Space] [LF] # cleanup local counter from stack [Space] [LF][LF] # print newline [Space] [Space] [Space] [Tab][Space][Tab][Space] [LF] # push 10 on a top of the stack [Tab][LF][Space][Space] # pop and print character at the top of the stack # increment main loop counter [Space] [Space] [Space] [Tab] [LF] # push 1 on a stack [Tab][Space] [Space][Space] # add element at the top of the stack (1) to the next element in stack (main loop counter) # test main loop result [Space] [Tab][Space] [Space] [Tab] [LF] # copy item at depth 1, 'total' count [Space] [Tab][Space] [Space] [Tab] [LF] # copy item at depth 1, main loop counter [Tab][Space] [Space][Tab] # decrement (total - counter) # if there is a negative number on the top of the stack, jump to the exit [LF] [Tab][Tab] [Tab][Space][Space][Space][Space][Space][Space][Space] [LF] # else jump unconditionally to the main loop label [LF] [Space][LF] [Space][Space][Space][Space][Space][Space][Space][Space] [LF] # set a label for exit [LF] [Space][Space] [Tab][Space][Space][Space][Space][Space][Space][Space] [LF] [LF][LF][LF] # finish