diff examples/printval.asm @ 57:2088fd998865

sbc09 directry clean up
author Shinji KONO <kono@ie.u-ryukyu.ac.jp>
date Mon, 23 Jul 2018 16:07:12 +0900
parents
children
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/examples/printval.asm	Mon Jul 23 16:07:12 2018 +0900
@@ -0,0 +1,46 @@
+	;print value as decimal 
+
+	org $100
+
+	ldx	#$ff00
+loop:
+	bsr printdec
+	ldb #32
+	swi2
+	leax 1,x
+    bne loop
+	sync
+
+
+printdec:
+    pshs cc,d,x		; save regs
+    lda #$80		; init. terminator
+nxtdg:
+	sta ,-s			; push digit term
+    ldb #16			; 16 bit counter for rotate
+    clra			; clear accu and carry
+roll:
+	rola			; divide by 10 using binary
+	adda #$f6		; long division, shifting X one
+    bcs sub			; bit at a time info A and
+    suba #$f6		; subtracting 10 which sets
+sub:
+    exg d,x			; C if sub goes, else add 10
+    rolb			; back and reset C. Rotating X
+    rola			; by means of A & B both shifts
+	exg d,x			; X bits into A and shifts
+	decb			; result bits into X. Do 17
+	bpl roll		; times to get last result bit.
+	leax ,x			; test X and repeat if
+    bne nxtdg		; X is not zero
+	tfr a,b
+prog:
+	orb #$30		; make into ASCII digit, call
+    swi2			; print char
+	ldb ,s+			; pull next digit of stack and
+	bpl	prog		; repeat if not terminator
+	puls cc,d,x,pc	; restore regs and return
+
+  
+	end
+