aforth

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

memory.s (1532B)


      1 #	Memory management
      2 
      3 verb	code	fetch	"@>"
      4 	minstk	1
      5 	mov	$0x0000FFFFFFFFFFFF, ACC
      6 	and	ACC,	TOS
      7 	mov	(TOS),	TOS
      8 	jmp	next
      9 
     10 fetchb:		codeword
     11 	minstk	1
     12 	movb	(TOS),	TOSB
     13 	and	$0xFF,	TOS
     14 	jmp	next
     15 
     16 verb	code	store	">@"
     17 	minstk	2
     18 	mov	$0x0000FFFFFFFFFFFF, ACC
     19 	and	ACC,	TOS
     20 	mov	(SP),	ACC
     21 	mov	ACC,	(TOS)
     22 	jmp	_drop2
     23 
     24 .macro	storei value:req variable
     25 .ifnb	\variable
     26 	const	value
     27 	const	variable
     28 .else
     29 	const	value
     30 	do	SWAP
     31 .endif
     32 	do	store
     33 .endm
     34 
     35 storeb:		codeword
     36 	minstk	2
     37 	mov	(SP),	ACC
     38 	movb	ACCB,	(TOS)
     39 	jmp	_drop2
     40 
     41 verb	forth	QUADCMP
     42 2:	do	DUP
     43 	if	1f
     44 		do	drop2
     45 		do	DROP
     46 		do	TRUE
     47 		endword
     48 1:	do	pushret				# Count
     49 	do	dup2				#
     50 	do	indneq				#
     51 	if	0f				#
     52 		do	inc			#
     53 		do	SWAP			#
     54 		do	inc			#
     55 		do	SWAP			#
     56 		do	popret			#
     57 		do	dec
     58 		goto	2b
     59 
     60 0:	do	drop2				# (Count)
     61 	do	popret				#
     62 	do	DROP
     63 	do	FALSE
     64 	endword
     65 
     66 verb	forth	STRCMP
     67 	do	dup2
     68 	do	fetch
     69 	do	SWAP
     70 	do	fetch
     71 	do	equal
     72 	unless	0f
     73 		do	OVER
     74 		do	fetch
     75 		const	8
     76 		do	divmod
     77 		do	SWAP
     78 		do	pushret			# Quotient
     79 		do	DUP			#
     80 		do	pushret			# # Remainder
     81 		do	plus			# #
     82 		do	SWAP			# #
     83 		do	popret			# #
     84 		do	plus			#
     85 		do	popret			#
     86 		do	inc
     87 		do	QUADCMP
     88 		endword
     89 0:	do	drop2
     90 	do	FALSE
     91 	endword
     92 
     93 verb	forth	CMOVE
     94 2:	test	equal	0	1f
     95 		do	dec
     96 		do	pushret					# Count
     97 		do	OVER					#
     98 		do	fetchb					#
     99 		do	OVER					#
    100 		do	storeb					#
    101 		const	8					#
    102 		do	plus					#
    103 		do	SWAP					#
    104 		const	8					#
    105 		do	plus					#
    106 		do	SWAP					#
    107 		do	popret					#
    108 		goto	2
    109 1:	do	DROP
    110 	do	drop2
    111 	endword
    112 
    113 verb	forth	STRMOVE
    114 	do	OVER
    115 	do	fetch
    116 	const	8
    117 	do	plus
    118 	do	CMOVE
    119 	endword