---->
LISTING 1
---->

		TTL	"Print String to Screen"
;
; =========================
; Amiga Shopper Assembly Language Course: Part VI
;
; String Printing Example Program. Tested using DevPac and DevPac Lite.
;
		section	PrintString,code
;
ENTRY_POINT:	bra.s	START			; Call start of program.
;
; ---- Embedded version string: ....
VERSION:	dc.b	0,"$VER: print_string.asm 1.00 (15.12.94)",0
;
; ---- Include files ....
		incdir	"inc:"
		include	"exec/exec.i"
		include	"exec/funcdef.i"	; You may not need this.
		include	"exec/exec_lib.i"
		include	"dos/dos.i"
		include	"dos/dos_lib.i"
;
; ---- Equates ....
_EXECBASE:	equ	$04			; exec.library base.
;
; ---- Macro Definitions ....
SYS:		macro
		move.l	_EXECBASE,a6
		jsr	_LVO\1(a6)		; exec.library access macro
		endm

DOS:		macro
		move.l	DosBase,a6
		jsr	_LVO\1(a6)		; dos.library access macro
		endm
;
; ---- Main Program: ....
START:		lea	DosName(pc),a1
		moveq	#$00,d0
		SYS	OpenLibrary
		move.l	d0,DosBase
		beq.s	ST_Failed_Dos	; Quit if no DOS.
;
; ---- Find STDOUT: ....
		DOS	Output
		move.l	d0,STDOUT
;
; ---- Show our string: ....
		lea	test_string,a0
		jsr	PrintString
		lea	test_string_2,a0
		jsr	PrintString
;
; ---- Close dos library and exit: ....
		move.l	DosBase,a1
		SYS	CloseLibrary
;
ST_Failed_Dos:	moveq	#$00,d0		; Return no error code.
		rts
;
; ---- The data we're using ....
test_string:	dc.b	"Hello Mum, Ben, Angie, Colin and Rebecca!",10,0
test_string_2:	dc.b	"Drink Whisky: It is great.",10,0
;
DosName:	dc.b	"dos.library",0	
DosBase:	dc.l	0		; Storage for dos.library base
STDOUT:		dc.l	0		; Storage for STDOUT file handle
;
; .....................................
;
;	PrintString():
;
;	Shows the string pointed to by A0 to STDOUT. This routine assumes
;	STDOUT has already been obtained and filled out. Registers on exit
;	are undefined.
;
PrintString:	move.l	a0,d2
		bsr	StringLength	; Get length of string
		move.l	d0,d3
		move.l	STDOUT,d1
		DOS	Write		; Show string on STDOUT
		rts
;
; .....................................
;
;	StringLength():
;
;	Returns the length of the string pointed to by A0 in D0. On exit,
;	A0 points to the end of the string.
;
StringLength:	moveq	#-1,d0
SL_Count:	addq.l	#$01,d0
		tst.b	(a0)+
		bne.s	SL_Count	; Count string till we reach the end
		rts
;
		END

---->
LISTING 2
---->

		TTL	"Pretty poor lottery program"
;
; =========================
; Amiga Shopper Assembly Language Course: Part VI
;
; Lottery-Mungus!
;
		section	PrintString,code
;
ENTRY_POINT:	bra.s	START			; Call start of program.
;
; ---- Embedded version string: ....
VERSION:	dc.b	0,"$VER: print_string.asm 1.00 (15.12.94)",0
;
; ---- Include files ....
		incdir	"inc:"
		include	"exec/exec.i"
		include	"exec/funcdef.i"	; You may not need this.
		include	"exec/exec_lib.i"
		include	"dos/dos.i"
		include	"dos/dos_lib.i"
;
; ---- Equates ....
_EXECBASE:	equ	$04			; exec.library base.
;
; ---- Macro Definitions ....
SYS:		macro
		move.l	_EXECBASE,a6
		jsr	_LVO\1(a6)		; exec.library access macro
		endm

DOS:		macro
		move.l	DosBase,a6
		jsr	_LVO\1(a6)		; dos.library access macro
		endm
;
; ---- Main Program: ....
START:		lea	DosName(pc),a1
		moveq	#$00,d0
		SYS	OpenLibrary
		move.l	d0,DosBase
		beq.s	ST_Failed_Dos	; Quit if no DOS.
;
; ---- Find STDOUT: ....
		DOS	Output
		move.l	d0,STDOUT
;
; ---- Show our lottery guess ....
		moveq	#$05,d1
ST_Loop:	

ST_Get49:	moveq	#$00,d0
		move.b	$dff006,d0
		addq.w	#$01,d0		; Ensure the number is at least 1
		cmp.w	#49,d0
		bhi.s	ST_Get49	; Loop around if it is > 49

		move.l	d1,-(sp)
		jsr	ShowDecimal5	; Show the result
		move.l	(sp)+,d1
		dbra	d1,ST_Loop
;
; ---- Close dos library and exit: ....
		move.l	DosBase,a1
		SYS	CloseLibrary
;
ST_Failed_Dos:	moveq	#$00,d0		; Return no error code.
		rts
;
DosName:	dc.b	"dos.library",0	
DosBase:	dc.l	0		; Storage for dos.library base
STDOUT:		dc.l	0		; Storage for STDOUT file handle
;
; .....................................
;
;	ShowDecimal5():
;
;	Shows the number in D0.l in Decimal on the screen, up to five
;	digits in length. Zeros are not supressed.
;
ShowDecimal5:	moveq	#$04,d1
		lea	SD5_Dividors(pc),a1
		lea	SD5_Number(pc),a0
;
; ---- Create our number string ....
SD5_Loop:	move.l	(a1)+,d2
		divu	d2,d0		
		add.b	#$30,d0		; Turn result to ASCII number
		move.b	d0,(a0)+	; Put character to output buffer
;
		swap	d0
		and.l	#$ffff,d0	; Get remainder.
;
		dbra	d1,SD5_Loop	; Loop round doing all digits.
;
; ---- All done, show our number on screen ....
		lea	SD5_Number(pc),a0
		bsr	PrintString
		rts
;
; ---- Dividor table & data for the decimal routine ....
SD5_Dividors:	dc.l	10000,1000,100,10,1
SD5_Number:	dc.b	"00000",10,0
;
; .....................................
;
;	PrintString():
;
;	Shows the string pointed to by A0 to STDOUT. This routine assumes
;	STDOUT has already been obtained and filled out. Registers on exit
;	are undefined.
;
PrintString:	move.l	a0,d2
		bsr	StringLength	; Get length of string
		move.l	d0,d3
		move.l	STDOUT,d1
		DOS	Write		; Show string on STDOUT
		rts
;
; .....................................
;
;	StringLength():
;
;	Returns the length of the string pointed to by A0 in D0. On exit,
;	A0 points to the end of the string.
;
StringLength:	moveq	#-1,d0
SL_Count:	addq.l	#$01,d0
		tst.b	(a0)+
		bne.s	SL_Count	; Count string till we reach the end
		rts
;
		END

