So, despite warnings not to, I decided to give ZDSII a try for some generic (not calculator related) and fairly trivial tests.

I have the following small program:


Code:

volatile signed char vvar;

void main(void)
{
   unsigned char i;
   
   i=8;
   do
   { vvar++;   }
   while((unsigned char) --i != (unsigned char) 0);
      
   
   return;
}


The compiler turns this into


Code:

   PUSH   IX
   LD   IX,0
   ADD   IX,SP
   DEC   SP
;    5      unsigned char i;
;    6      
;    7      i=8;
.LINE 7

   LD   (IX+%FFFFFFFF),%8
;    8      do
L_1:
.LINE 8

;    9      { vvar++;   }
.LINE 9

   LD   A,(_vvar)
   LD   B,A
   LD   A,(_vvar)
   INC   A
   LD   (_vvar),A
;   10      while((unsigned char) --i != (unsigned char) 0);
.LINE 10

   DEC   (IX+%FFFFFFFF)
   LD   A,(IX+%FFFFFFFF)
   OR   A,A
   JR   NZ,L_1
;   11         
;   12      
;   13      return;
.LINE 14

   LD   SP,IX
   POP   IX
   RET   


i.e. at the end of the do/while loop, the code first decrements i, then explicitly compares its value to zero, and then does a conditional jump.

Shouldn't the compiler be able to skip the explicit comparison, as DEC (IX/Y+d) changes the zero flag according to the result of the decrement?
Yes.
It should, but zds no optimize gud. On that note, I should probably look into adding the inc/dec (reg) opt to llvm...
  
Register to Join the Conversation
Have your own thoughts to add to this or any other topic? Want to ask a question, offer a suggestion, share your own programs and projects, upload a file to the file archives, get help with calculator and computer programming, or simply chat with like-minded coders and tech and calculator enthusiasts via the site-wide AJAX SAX widget? Registration for a free Cemetech account only takes a minute.

» Go to Registration page
Page 1 of 1
» All times are UTC - 5 Hours
 
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum

 

Advertisement