[A86] Re: SDCC v2.3.0 (fib.c)


[Prev][Next][Index][Thread]

[A86] Re: SDCC v2.3.0 (fib.c)




[I don't mean to flame anybody with this mail]
> Van: David Phillips <david@acz.org>
> 
> I think that's a poor example.  It uses printf[..]

Did you want an example or did you want politicaly correct code?

> You were saying that SDCC generates good code?  I'm sorry, but that code
> looks terrible to me.  Why is it passing values on the stack when it
> could be passing them using registers?  Especially when it's a single
> value? And it's creating a stack frame when it's not needed.

Reported that (already) to Micheal Hope, he manages the (GB)Z80 port. And
could you please look for yourself at it, as it seems that you know so well
what we need to test (no flames meant).

Oh, and ever looked at other Z80 C compilers, compared to that, this code
is quite comfy.

If you find some 'obscurity' in SDCC I'd like to compile the same code for
the z88dk (or maybe even with the 'beloved' TISCO), to compare with.

To begin with:

-----fib.c compiled with the z88dk-------
.._main
	dec	sp
	pop	hl
	ld	l,#(1 % 256)
	push	hl
	ld	h,0
..i_5
	ld	hl,0	;const
	add	hl,sp
	ld	e,(hl)
	ld	d,0
	ld	hl,10	;const
	call	l_ult
	jp	nc,i_4
	jp	i_6
..i_3
	ld	hl,0	;const
	add	hl,sp
	inc	(hl)
	ld	l,(hl)
	ld	h,0
	dec	l
	jp	i_5
..i_6
	ld	hl,i_1+0
	push	hl
	ld	hl,2	;const
	add	hl,sp
	ld	l,(hl)
	ld	h,0
	push	hl
	ld	hl,4	;const
	add	hl,sp
	ld	l,(hl)
	ld	h,0
	push	hl
	call	_fib
	pop	bc
	push	hl
	ld	a,3
	call	printf
	pop	bc
	pop	bc
	pop	bc
	jp	i_3
..i_4
	inc	sp
	ret



.._fib
	pop	bc
	pop	de
	push	de
	push	bc
	ld	hl,2	;const
	call	l_ule
	jp	nc,i_7
	ld	hl,1	;const
	ret


..i_7
	pop	bc
	pop	hl
	push	hl
	push	bc
	dec	hl
	push	hl
	call	_fib
	pop	bc
	push	hl
	ld	hl,4	;const
	add	hl,sp
	call	l_gint	;
	dec	hl
	dec	hl
	push	hl
	call	_fib
	pop	bc
	pop	de
	add	hl,de
	ret


..i_1
	defm	"fib(%d) = %d"&13&""&0

-----Folowing code is from the lib------
; DE < HL [unsigned]
..l_ult
        call    l_ucmp
        ret     c
        dec     hl
        ret

; DE <= HL [unsigned]
..l_ule
        call    l_ucmp
        ret     c
        scf
        ret     z
        ccf     ;set nc, i.e. false
        dec     hl
        ret

..l_ucmp
        ld a,d
        cp h
        jr nz,l_ucmp1
        ld a,e
        cp l
..l_ucmp1  
        ld hl,1    ;preset true
        ret

..l_gint
        ld a,(hl)
        inc     hl
        ld h,(hl)
        ld l,a
        ret
-----------

> > At the moment I've got a fibonacci calculator, it works on the z88dk,
> > haven't/couldn't/whatever test it for SDCC.

fib.c was the first c-file (I recently used with the z88dk) that compiled
right (please, don't understand me wrong)...

	Henk Poley <><




Follow-Ups: