Task

Produce a sequential count in octal,   starting at zero,   and using an increment of a one for each consecutive number.

Each number should appear on a single line,   and the program should count until terminated,   or until the maximum value of the numeric type in use is reached.



Related task

   Integer sequence   is a similar task without the use of octal numbers.


	xor a          ;LD A,0
	ld b,&40       ;how many numbers to print.
loop_showOctal:
	push af
		push af
			call ShowOctal
			ld a,' '
			call PrintChar  ;put a blank space after the value
		pop af
 
;;;;;;;;;;;;;;;;;;;;; this code starts a new line after every 8th output.
		ld a,b
		and &07 
		dec a             
		call z,NewLine  
;;;;;;;;;;;;;;;;;;;;;; 
	pop af
	inc a  ;next number
	djnz loop_showOctal
 
	jp $   ;end program
 
ShowOctal:
	push bc
		ld c,a
		add a
		push af
			ld a,7
			and c
			ld c,a
		pop af
		and &F0
		or c
		and &7F
	pop bc
	jp ShowHex
 
ShowHex:	 ;this isn't directly below ShowOctal, it's somewhere else entirely.
                 ;thanks to Keith of Chibiakumas for this routine!
	push af
		and %11110000
		ifdef gbz80
			swap a     ;game boy can use this, but Zilog Z80 cannot.
		else
			rrca
			rrca
			rrca
			rrca
		endif
		call PrintHexChar
	pop af
	and %00001111
        ;execution flows into the subroutine below, effectively calling it for us without having to actually do so.
PrintHexChar:
	or a	       ;Clear Carry Flag
	daa
	add a,&F0
	adc a,&40      ;this sequence of instructions converts hexadecimal values to ASCII.
	jp PrintChar   ;hardware-specific routine, omitted. Thanks to Keith of Chibiakumas for this one!