Email: Password: Remember Me | Create Account (Free)

Back to Subject List

Old thread has been locked -- no new posts accepted in this thread
???
05/03/08 14:54
Read: times


 
#154344 - *(buffer+8+index)?
Responding to: ???'s previous message
That's not what I would call high-level; it's rather abusing the pointer arithmetics of C (which in itself is not a HLL idea either).

I don't have Keil's at hand here. Can you please try to compile the following snippet (this is sdcc so please modify whatever needed for Keil's), and present the resulting asm here, so that we can chew more at it?

JW

typedef unsigned char uint8_t;
uint8_t buffer[10];
uint8_t xdata xbuffer[300];
uint8_t code cbuffer[10] = {'A','B','C','D','E','F','G','H','I','J'};
uint8_t index;

void main(void) {
  for (index = 250; index < 255; index++) {
    if (*(buffer+8+index) == 0x47) break;
    if (buffer[index + 8] == 0x47) break;
    if (*(xbuffer+8+index) == 0x47) break;
    if (xbuffer[index + 8] == 0x47) break;
    if (*(cbuffer+8+index) == 0x47) break;
    if (cbuffer[index + 8] == 0x47) break;
  }
}


 


SDCC v2.7.4:
                            141 ;	p1.c:8: for (index = 250; index < 255; index++) {
   0000 75*0A FA            142 	mov	_index,#0xFA
   0003                     143 00113$:
   0003 74 01               144 	mov	a,#0x100 - 0xFF
   0005 25*0A               145 	add	a,_index
   0007 50 01               146 	jnc	00127$
   0009 22                  147 	ret
   000A                     148 00127$:
                            149 ;	p1.c:9: if (*(buffer+8+index) == 0x47) break;
   000A E5*0A               150 	mov	a,_index
   000C 24r08               151 	add	a,#(_buffer + 0x0008)
   000E F8                  152 	mov	r0,a
   000F 86 02               153 	mov	ar2,@r0
   0011 BA 47 01            154 	cjne	r2,#0x47,00128$
   0014 22                  155 	ret
   0015                     156 00128$:
                            157 ;	p1.c:10: if (buffer[index + 8] == 0x47) break;
   0015 74 08               158 	mov	a,#0x08
   0017 25*0A               159 	add	a,_index
   0019 24r00               160 	add	a,#_buffer
   001B F8                  161 	mov	r0,a
   001C 86 02               162 	mov	ar2,@r0
   001E BA 47 01            163 	cjne	r2,#0x47,00129$
   0021 22                  164 	ret
   0022                     165 00129$:
                            166 ;	p1.c:11: if (*(xbuffer+8+index) == 0x47) break;
   0022 E5*0A               167 	mov	a,_index
   0024 24r08               168 	add	a,#(_xbuffer + 0x0008)
   0026 F5 82               169 	mov	dpl,a
   0028 E4                  170 	clr	a
   0029 34s00               171 	addc	a,#((_xbuffer + 0x0008) >> 8)
   002B F5 83               172 	mov	dph,a
   002D E0                  173 	movx	a,@dptr
   002E FA                  174 	mov	r2,a
   002F BA 47 01            175 	cjne	r2,#0x47,00130$
   0032 22                  176 	ret
   0033                     177 00130$:
                            178 ;	p1.c:12: if (xbuffer[index + 8] == 0x47) break;
   0033 AA*0A               179 	mov	r2,_index
   0035 7B 00               180 	mov	r3,#0x00
   0037 74 08               181 	mov	a,#0x08
   0039 2A                  182 	add	a,r2
   003A FA                  183 	mov	r2,a
   003B E4                  184 	clr	a
   003C 3B                  185 	addc	a,r3
   003D FB                  186 	mov	r3,a
   003E EA                  187 	mov	a,r2
   003F 24r00               188 	add	a,#_xbuffer
   0041 F5 82               189 	mov	dpl,a
   0043 EB                  190 	mov	a,r3
   0044 34s00               191 	addc	a,#(_xbuffer >> 8)
   0046 F5 83               192 	mov	dph,a
   0048 E0                  193 	movx	a,@dptr
   0049 FA                  194 	mov	r2,a
   004A BA 47 01            195 	cjne	r2,#0x47,00131$
   004D 22                  196 	ret
   004E                     197 00131$:
                            198 ;	p1.c:13: if (*(cbuffer+8+index) == 0x47) break;
   004E E5*0A               199 	mov	a,_index
   0050 90s00r08            200 	mov	dptr,#(_cbuffer + 0x0008)
   0053 93                  201 	movc	a,@a+dptr
   0054 FA                  202 	mov	r2,a
   0055 BA 47 01            203 	cjne	r2,#0x47,00132$
   0058 22                  204 	ret
   0059                     205 00132$:
                            206 ;	p1.c:14: if (cbuffer[index + 8] == 0x47) break;
   0059 74 08               207 	mov	a,#0x08
   005B 25*0A               208 	add	a,_index
   005D 90s00r00            209 	mov	dptr,#_cbuffer
   0060 93                  210 	movc	a,@a+dptr
   0061 FA                  211 	mov	r2,a
   0062 BA 47 01            212 	cjne	r2,#0x47,00133$
   0065 22                  213 	ret
   0066                     214 00133$:
                            215 ;	p1.c:8: for (index = 250; index < 255; index++) {
   0066 05*0A               216 	inc	_index
   0068 02s00r03            217 	ljmp	00113$

 




List of 20 messages in thread
TopicAuthorDate
"Real C" vs '51 C            01/01/70 00:00      
   there is nothing wrong except...            01/01/70 00:00      
      if you are not , why are you even here            01/01/70 00:00      
         *(buffer+8+index)?            01/01/70 00:00      
            none of the above            01/01/70 00:00      
               OK then how?            01/01/70 00:00      
   like this            01/01/70 00:00      
      but it's basically the same...            01/01/70 00:00      
      YCMV            01/01/70 00:00      
      No            01/01/70 00:00      
         assumptions            01/01/70 00:00      
            Re: assumptions            01/01/70 00:00      
               I took a \'known\' example            01/01/70 00:00      
                  Compiler-independent efficient C            01/01/70 00:00      
                     a clarification and an example            01/01/70 00:00      
                        Two kinds of "efficiency"            01/01/70 00:00      
                     Compiler smarter than coder            01/01/70 00:00      
                        Getting the least out of your compiler            01/01/70 00:00      
   Real C is inherently reentrant            01/01/70 00:00      
      which, even when possible, often is ill advised            01/01/70 00:00      

Back to Subject List