Mini-HOWTO
Using ASxxxx for Model 100 Development
Willard Goosey
4/16/2016

This mini-HOWTO has been updated for ASX version 5.31.

The ASxxxx suite of 8-bit cross assemblers is one of the only
relocating, linkable-file generating cross assembler for the 8085. (It
also supports just about every other 8-bit CPU ever. For Model 100 we
care about 8085.) It is very powerful, very complicated, and has its
own ways of doing things, apparently inherited from the old DECUS
cross-assemblers.

(Available from http:shop-pdp.net/)

Other software tools required: objcopy(1), one of the standard GNU
binutils, and hex2co from Chris Osburn's personal library on club100.

Also note that these examples were assembled using the default make
rules included in the archive containing this HOWTO.

Producing a single binary from a single source file is pretty straight
forward:
	.area M100 (cseg,abs,con)
	.include "m100.def"
	.org #0xf000

start:: lxi h,mss
loop:  mov a,m
      cpi #00
      jz done
      call LCD
      inx h
      jmp loop
done:  call CHGET
fin:      ret
mss:  .ascii 'hello world'
   .dw #0x0d0a
   .db #0
   .end start

But what's the fun of that? The point of an assembler with a linker is
to have linkable binary subroutines that don't need to be edited every
time a binary is built!

Only the linker threw me a curve ball! If you have code with both a
CODE segment and a DATA segment, it *really* wants to put the data
segment in a seperate hex file. Worse both the code and data segments
start at address 0000h! What????

The first way to handle this is to start with an absolute segment and
force the relative area to occur after the abs segment. Thus:

a2b.a85
	.module LIBMILLER
	.area LIBMILLER_CODE

a2b::
       stc	 ;set carry 
	[boring 8080 code]
       ret

ta2b.a85:

.include "m100.def"

	.module TA2B
	.area TA2B_CODE (abs,con,cseg)
        .org #0xF000
main::

	[more 8080 code]

msg1:    .asciz 'Input a number >'
msg2:    .asciz 'Number is '

ta2bend::
        .end main
        
And then linked with:
aslink -n -i1 -m -b LIBMILLER_CODE=ta2bend -o ta2b.ihx ta2b.rel a2b.rel

As you see, segment LIBMILLER_CODE starts at ta2bend and goes up. Just
like it's supposed to!

 
But as soon as relative files are introduced, the linker creates an
Intel HEX file that is non-continous! While this allowed under the
file specification, hex2co doesn't like it. It is, however, easily
fixed with objcopy(1), a standard GNU binutil.
	objcopy -I ihex -O ihex infile outfile

And I thought I was done! But then I said, "Let's see how Small-C 8085
handles this nonsense!"

It handles it thus:
                ;program area SMALLC_GENERATED is RELOCATABLE
                .area   SMALLC_GENERATED        (REL,CON)
                .module SMALLC_GENERATED
                .area  SMALLC_GENERATED  (REL,CON,CSEG)
srand:
	[8080 code]
       ret
                .area  SMALLC_GENERATED_DATA  (REL,CON,DSEG)
$0:     .db     #84,#121,#112,#101,#32,#97,#32,#99

;eof

Therefore, a program built entirely of relative areas looks like:

tc2b.a85:	
	.module TC2B
	.area M100 (cseg,rel,con)

main::  lxi h,msg1  ; hl->message
        call LCDSTR ; print message
	[8080 code]


	.area M100_DATA (rel,con,dseg)
               
	[data..]

and c2b.a85:

	.module LIBMILLER
	.area LIBMILLER_CODE

c2b::  push h       ;save hl on stack
	[8080 code]
	ret

Is linked by the linker command line:
	aslink -n -i1 -m -b M100=0xF000 -o tc2b.ihx tc2b.rel ah2i.rel c2b.rel fixpower.rel

Produces exactly the binary we want.

So I now believe I have solved this problem and can get back to making
[boring 8080 code] do what I want it to...

While I'm leaving most of the quirks of the ASX suite to the official
documentation I need to talk briefly about .END here... As with most
assemblers, the END pseudo-op supplies the binary's starting
address. 2 things are interesting about this. 1) HEX2CO doesn't
support it (binary code starts at the lowest address) and 2) as of ASX
5.2x, the linker, by default, generates a 32bit starting
address... Hence the use of the -I1 option to the linker, forcing a
16-bit starting address. 

 
