Skip to content

AS1802 and ASLINK

April 26, 2018

One of the things that the 1802 historically lacks is a linker to combine and relocate pre-compiled object modules.  LCC1802 combines everything at the source level and compiles/assembles it every time.  This has the advantage of clarity but it does make the output bulkier.

Through an odd happenstance I came across AS1802 and ASLINK which accompanies it.  AS1802 is part of the ASxxxx series of cross assemblers which are also used by SDCC.

I downloaded the assembler and linker and tried them out today. I created assembly modules fblink.asm which calls an external routine _onems, and delay.asm which contains that routine.  I assembled the two generating files fblink.rel and delay.rel with commands like “as1802 fblink.asm”.

	.globl _onems
label1:	seq
	sep call
	.dw _onems
	req
	sep call
	.dw _onems
	br label1
	.BNDRY  8
	.globl	_onems
_onems:		;execute 1ms worth of instructions including call(15)/return(10) sequence. takes about 1 ms
;subroutine overhead soaks up 27 instruction time.
;each loop is 2 instruction times
;so the number of loops needed is 
;CPU speed/16000 less the 27 all divide by two
  .IFNDEF LCC1802CPUSPEED
LCC1802CPUSPEED .EQU 1600	;1.6MHZ default
  .ENDIF
  
  .IFLT LCC1802CPUSPEED-8000
	ldi	((LCC1802CPUSPEED/16)-15-10-2)/2
1$:	smi	1
	bnz	1$
  .ELSE
	ldi	((LCC1802CPUSPEED/16)-15-10-2)/4
2$:	smi	1
	sex	sp
	sex	sp
	bnz	2$
  .ENDIF
	sep	return

I created a library file basic.lib which just contains one line with delay.rel on it.

The link command “aslink -i -u -l basic.lib fblink.rel” loads the fblink program, notices the reference to _onems and goes through the files pointed to by basic.lib finding it in delay.rel.

The result goes into fblink.ihx with fblink at 0000 and _onems at 0010.  This is actually pretty magnificent. It would be an awful lot of work to convert from using my current assembler to AS1802 but if i ever get ambitious i might think about using it as a back end to the ASW macro-processor.

:0A0000007BD400107AD40010300009
:07001000F824FF013A12D5AC
:00000001FF

It occurs to me that this is a fairly dumb example. The onems routine really needs to be compiled each time so that changes in cpu speed can be accommodated. I can see separately building it in a makefile but it wouldn’t be a good library candidate. Better examples would be the 16 bit math routines which are always compiled and included even if they’re not needed.

Advertisements

From → Uncategorized

Leave a Comment

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: