z80asm Usage Notes

This writeup is a spot for my notes regarding oddities of using z80asm in my upcoming projects.


Write the program

		ORG	$2000
		LD	SP,$FFFF
MAIN:	CALL TIMER5
TIMER5:	LD E,$35
J60:	LD B,$FF
J61:	LD D,$FF
J62:	DEC D
		JP NZ,J62
		DEC B
		JP NZ,J61
		DEC E
		JP NZ,J60
		RET
END

Assemble the program

z80asm -ltest.lst -i test.asm -o test.bin

View ASM/HEX side by side (listing)

# File test.asm
0000					ORG	$2000  
2000 31 ff ff				LD	SP,$FFFF  
2003 cd 06 20		MAIN:	CALL TIMER5  
2006 1e 35		TIMER5:	LD E,$35  
2008 06 ff		J60:	LD B,$FF  
200a 16 ff		J61:	LD D,$FF  
200c 15			J62:	DEC D  
200d c2 0c 20				JP NZ,J62  
2010 05					DEC B  
2011 c2 0a 20				JP NZ,J61  
2014 1d					DEC E  
2015 c2 08 20				JP NZ,J60  
2018 c9					RET  
2019			END
# End of file test.asm
2019
  • or provide z80asm -l infile outfile and the listing will dump to stdout

View binary file

0000000: 31ff ffcd 0620 1e35 06ff 16ff 15c2 0c20  1.... .5.......
0000010: 05c2 0a20 1dc2 0820 c9                   ... ... .
  • Note how the listing has the $2000 offset applied but the binary does not!

Create HEX for programming

  • the binary file has no start offset so we need to insert nulls in front of the code sequence
  • $((0xFFFF)) lets BASH do the hex2dec conversion
25+0 records in
25+0 records out
25 bytes (25 B) copied, 0.000673997 s, 37.1 kB/s
  • -a to skip the null entries
0000000: 0000 0000 0000 0000 0000 0000 0000 0000  ................
*
0002000: 31ff ffcd 0620 1e35 06ff 16ff 15c2 0c20  1.... .5.......
0002010: 05c2 0a20 1dc2 0820 c9                   ... ... .

Program your target

  • My Arduino sketch requires a serial dump starting at address $0000 so thats why we had to insert all those nulls. 90% of the time your programs will start at $0000 anyways.