149 cycles, 62 bytes
@loop: subleq @tmp, @IN subleq @tmp2, @tmp2 subleq @tmp2, @tmp, @dequeue @queue: subleq @stack, @tmp2 subleq @count, @n_one subleq @queue, @n_one subleq @tmp, @tmp, @loop @dequeue: subleq @OUT, @stack subleq @tmp, @IN subleq @OUT, @tmp subleq @dequeue+1, @n_one subleq @tmp, @tmp subleq @count, @one, @done subleq @tmp, @tmp, @dequeue @done: subleq @OUT, @IN, @loop ; Constants @one: .data 1 @n_one: .data -1 ; Variables @tmp: .data 0 @tmp2: .data 0 @count: .data 0 ; Base of stack (stack will grow upwards) @stack: .data 0