Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

sccz80: silently pushing 32-bit constant when result of computation is 16-bit #321

Open
aralbrec opened this issue Aug 20, 2017 · 1 comment

Comments

@aralbrec
Copy link
Member

#include <stdio.h>

#define BUFFER_SIZE     16384
#define MAINBANK_ADDR  (65536 - BUFFER_SIZE*2)

void main(void)
{
   printf("M RAMTOP no good (%u)", MAINBANK_ADDR);
}

zcc +zx -vn -a test.c

._main
	ld	hl,i_1+0
	push	hl
	ld	hl,32768	;const
	ld	de,0
	push	de
	push	hl
	ld	a,3
	call	printf
	pop	bc
	pop	bc
	pop	bc
	ret

MAINBANK_ADDR is being pushed as a 32-bit value when the result is 16-bits and a 16-bit value is expected. This is happening because there is a 32-bit value "65536" in the expression used to calculate MAINBANK_ADDR. If the constant is changed to 65535, 16-bits is pushed.

zsdcc pushes 16-bits for the value if it is in range of 16-bits.

@suborb
Copy link
Member

suborb commented Aug 21, 2017

Yes, as soon as a constant references < -32767, or >= 65536 then it becomes a long.

I think this is really only an issue with vaarg or otherwise unprototyped functions.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants