aforth

FORTH for Linux x86-64, written in assembly.
git clone git://henryandlizzy.uk/aforth
Log | Files | Refs | README

output.s (1108B)


      1 #	Output
      2 
      3 verb	code	EMIT
      4 	minstk	1
      5 	movq	TOS,	buff
      6 	mov	$1,	CMD	# system call 1 is write
      7         mov	$1,	ARGA	# file handle 1 is stdout
      8         mov	$buff,	ARGB	# address of string to output
      9         mov	$1,	ARGC	# number of bytes
     10         syscall
     11 	jmp	_drop
     12 
     13 verb	forth	CR
     14 	const	'\n'
     15 	do	EMIT
     16 	endword
     17 
     18 verb	forth	SPACE
     19 	const	' '
     20 	do	EMIT
     21 	endword
     22 
     23 verb	code	PRINT
     24 	minstk	1
     25 	mov	$1,	CMD
     26         mov	$1,	ARGA
     27         mov	(TOS),	ARGC
     28 	advance	TOS
     29         mov	TOS,	ARGB
     30 	syscall
     31 	jmp	_drop
     32 
     33 verb	code	TYPE
     34 	minstk	2
     35 	mov	$1,	CMD
     36 	mov	$1,	ARGA
     37 	mov	(SP),	ARGB
     38 	mov	TOS,	ARGC
     39 	syscall
     40 	jmp	_drop2
     41 
     42 verb	forth	dot	"."
     43 	test	gequal	0	1f
     44 	const	'-'
     45 	do	EMIT
     46 	do	NEGATE
     47 1:	do	_dot
     48 	endword
     49 
     50 _dot:		forthword
     51 	test	less	10	1f
     52 		const	10
     53 		do	divmod
     54 		do	SWAP
     55 		do	_dot
     56 1:
     57 		const	'0'
     58 		do	plus
     59 		do	EMIT
     60 	endword
     61 
     62 verb	forth	dotdot	"..."
     63 	say	"..."
     64 	do	top
     65 	const	stack
     66 	do	nequal
     67 	if	1f
     68 		say	"Stack Empty"
     69 1:	do	_dotdot
     70 	saycr	"..."
     71 	endword
     72 
     73 _dotdot:	forthword
     74 	do	top
     75 	const	stack
     76 	do	equal
     77 	if	1f
     78 		do	pushret			# Top of stack
     79 		do	_dotdot			#
     80 		do	popret			#
     81 		const	'\t'
     82 		do	EMIT
     83 		do	DUP
     84 		do	dot
     85 1:	endword