Arithmetics inside constants not working?

Other misc things
Post Reply
WORP3
Member
Posts: 32
Joined: Thu Dec 29, 2022 12:51 pm

Arithmetics inside constants not working?

Post by WORP3 »

I'm kind of stuck, for some reason a constant defined out of a formula always gives a zero when loading this inside a register. I've made several different tests which you can see in the assembler output below, I also added the command I'm using to compile the project (where this is a part of). As it's the output, you can directly see what has been generated.
It seems that only when a calculation is doen, the value is always zero, if I use the calculation directly at the point where it's is used then the correct value pop's up.
In the end I'm trying to define a block of code where I need specific constant that described offsets from the start of the block. Also the total length of this block is needed, so I can transfer it. This works inside an specific z80 assembler but i'm not getting it working inside Z88dk for some reason?

Thanks in advance.

Code: Select all

   
   136                          BlockStart:
   137   000052 00              Var1:	DEFB	0
   138   000053 00              Var2:	DEFB	0
   139   000054 00              Var3:	DEFB	0
   140                          BlockEnd:
   141                          
   142                          BlockSize 		EQU 	(BlockEnd - BlockStart)
   143                          BlockSize2 = (BlockEnd - BlockStart)
   144                          DEFC	BlockSize3=(BlockEnd - BlockStart)
   145                          BlockTest		EQU		123
   146                          
   147   000055 0000            TestVar:		DEFW	BlockSize
   148   000057 0300            TestVar2:		DEFW	(BlockEnd - BlockStart)
   149                          
   150   000059 0600            				LD		B,BlockSize
   151   00005b 0600            				LD		B,BlockSize2
   152   00005d 0600            				LD		B,BlockSize3
   153   00005f 067b            				LD		B,BlockTest
   154   000061 010000          				LD		BC,BlockSize
   155   000064 ed4b0300        				LD		BC,(BlockEnd - BlockStart)                  
 
zcc +z80 -vn -compiler=sdcc -O3 --list @ProjectFiles.lst -o test -lm -create-app -pragma-include:..\lib\zpragma.inc
WORP3
Member
Posts: 32
Joined: Thu Dec 29, 2022 12:51 pm

Re: Arithmetics inside constants not working?

Post by WORP3 »

Maybe it's also possible to create a section for this block of data, but then how do I get individual offsets inside this section and the complete section size?
User avatar
dom
Well known member
Posts: 2269
Joined: Sun Jul 15, 2007 10:01 pm

Re: Arithmetics inside constants not working?

Post by dom »

I can't reproduce this at the moment - what version of z88dk are you using?
WORP3
Member
Posts: 32
Joined: Thu Dec 29, 2022 12:51 pm

Re: Arithmetics inside constants not working?

Post by WORP3 »

dom wrote: Sat Feb 01, 2025 3:50 pm I can't reproduce this at the moment - what version of z88dk are you using?
Hi Dom,
To be sure that it was version related, I upgraded my version to the latest version before posting this, so it should be version "z88dk is 2.3, released in December 2023".
Overall I can assign all kind of value's to a constant, but if I try to assign a subtracted value, then the assigned value is zero. Just let me know if you need more information on this subject.
User avatar
dom
Well known member
Posts: 2269
Joined: Sun Jul 15, 2007 10:01 pm

Re: Arithmetics inside constants not working?

Post by dom »

I'll be honest I'm struggling to reproduce this one with 2.3 and later. I've even run the Windows binaries since I think you're on Windows.

I do see the same as you when using 2.2. This does actually make sense because there were some fixups in this area just before the release of 2.3.

When I say I can reproduce it I mean that the .lis file shows the same as you (that is loading 0), but the generated binary is correct.

Is there any chance you can share a complete minimal example that shows this issue? It seems that I'm missing something in my reproduction attempts.
WORP3
Member
Posts: 32
Joined: Thu Dec 29, 2022 12:51 pm

Re: Arithmetics inside constants not working?

Post by WORP3 »

dom wrote: Sat Feb 01, 2025 7:09 pm Is there any chance you can share a complete minimal example that shows this issue?
Sure, i'm will create a minimal example for you tomorrow. To be absolutely sure about the version, I will double check if the update went as expected.
WORP3
Member
Posts: 32
Joined: Thu Dec 29, 2022 12:51 pm

Re: Arithmetics inside constants not working?

Post by WORP3 »

Hi Dom,

It's working :D
That's just great that this has already been fixed in the new 2.3 version. The problem is in sourceforge, the latest download link is still pointing to the 2.2 version while the date was from the latest. So unfortunately although I updated to the latest version before posting, I was still not using the latest version.

Code: Select all

   137                          BlockStart:
   138  0052  00                Var1:	DEFB	0
   139  0053  00                Var2:	DEFB	0
   140  0054  00                Var3:	DEFB	0
   141                          BlockEnd:
   142                          
   143                          BlockSize 		EQU 	(BlockEnd - BlockStart)
   144                          BlockSize2 = (BlockEnd - BlockStart)
   145                          DEFC	BlockSize3=(BlockEnd - BlockStart)
   146                          BlockTest		EQU		123
   147                          
   148  0055  0300              TestVar:		DEFW	BlockSize
   149  0057  0300              TestVar2:		DEFW	(BlockEnd - BlockStart)
   150                          
   151  0059  0603              				LD		B,BlockSize
   152  005b  0603              				LD		B,BlockSize2
   153  005d  0603              				LD		B,BlockSize3
   154  005f  0645              				LD		B,Test_Size
   155  0061  067b              				LD		B,BlockTest
   156  0063  010300            				LD		BC,BlockSize
   157  0066  ed4b0300          				LD		BC,(BlockEnd - BlockStart)
Thanks for the help!
User avatar
dom
Well known member
Posts: 2269
Joined: Sun Jul 15, 2007 10:01 pm

Re: Arithmetics inside constants not working?

Post by dom »

That’s good news!

Sourceforge is just setup as a mirror of GitHub. I’ve just found out that it doesn’t update the “default download” when you do that.

Release versions lag a fair bit (eg there’s been about 1000 changes since 2.3) so taking a nightly build is usually the better option.
WORP3
Member
Posts: 32
Joined: Thu Dec 29, 2022 12:51 pm

Re: Arithmetics inside constants not working?

Post by WORP3 »

dom wrote: Sun Feb 02, 2025 11:15 am Release versions lag a fair bit (eg there’s been about 1000 changes since 2.3) so taking a nightly build is usually the better option.
That is good to know, I already thought why is the current latest version already that old :)
Timmy
Well known member
Posts: 423
Joined: Sat Mar 10, 2012 4:18 pm

Re: Arithmetics inside constants not working?

Post by Timmy »

And if you don't know where to find the nightly version, there is at least a link from the main forums page.

Or at the download link at the main z88dk site.
Post Reply