Z80 Divide by 10

Sean Conner spc at conman.org
Sun Jan 27 03:06:33 CST 2008


It was thus said that the Great Sean Conner once stated:
> 
> 	ld	b,h			; 1	4 
> 	ld	c,l			; 1	4
> 	srl	b			; 2	8
> 	rr	c			; 2	8
> 	srl	b			; 2	8
> 	rr	c			; 2	8
> 	add	hl,bc	; HL = q	; 1	11
> 	ld	b,h	; BC also = q	; 1	4
> 	ld	c,l			; 1	4
> 	ex	de,hl	; HL = n, DE = q; 1	4
> 	or	a	; CF = 0	; 1	4
> 	sbc	hl,de	; n - q		; 2	15
> 
> ; return q + ((r + 6) >> 4
> 
> 	ld	de,(const6)		; 4	20
> 	add	hl,de			; 1	11
> 	ld	(savehl),hl		; 3	16
> 	ld	hl,savehl		; 3	10
> 	and	a			; 1	4
> 	rdd				; 1	18
> 	ld	hl,(savehl)		; 3	16
> 	add	hl,bc			; 1	11
> 
> 	ret				; 1	10

  I find it amazing that there's an instruction set even more annoying than
the 8086 (segments and all).  I was amazed at the lopsidedness of the
instruction set.  I'm beginning to think I was lucky in skipping this
particular chip (my first 8-bit was the 6809, so I think I got spoiled). 
There doesn't even seem to be an easy way to get the stack pointer, and the
only way I can see of doing it is:

	or	a
	sbc	hl,hl
	add	hl,sp

  and no real good way of indexing the stack.  

  Sheesh.

  -spc (What an ... interesting chip ... )




More information about the cctech mailing list