>-----Original Message----- >From: piclist-bounces@mit.edu [mailto:piclist-bounces@mit.edu] >On Behalf Of Peter Todd >Sent: 16 October 2007 12:00 >To: piclist@mit.edu >Subject: [PIC] movff ignores banksel, correct? > > >Using this macro: > >#define i2c_write(c) \ > PIR1bits.SSPIF = 0; \ > SSPBUF = (c); \ > while (!PIR1bits.SSPIF); // cleared at 9th (ACK) clock > > >i2c_write(i); > >!= > >i2c_write(0x40 + i); > > >Looking at the outputted asm code the former produces: > >00346 ; .line 71; mcp23017.c i2c_write(i); >0030 9600 00347 BCF _PIR1bits, 3 >0032 C000 F000 00348 MOVFF r0x00, _SSPBUF >0036 00349 _00108_DS_: >0036 A600 00350 BTFSS _PIR1bits, 3 >0038 EF00 F000 00351 GOTO _00108_DS_ > >and the latter: > >00346 ; .line 71; mcp23017.c i2c_write(0x40 + ((i))); >0030 9600 00347 BCF _PIR1bits, 3 >0032 0E40 00348 MOVLW 0x40 >0034 2400 00349 ADDWF r0x00, W >0036 6E00 00350 MOVWF _SSPBUF >0038 00351 _00108_DS_: >0038 A600 00352 BTFSS _PIR1bits, 3 >003A EF00 F000 00353 GOTO _00108_DS_ > > >Basically identical. However the latter outputs 0x00 on the >i2c bus regardless of what value i is. The former works fine, >although I rather need that 0x40 bit. I'm guessing that sdcc >is missing a banksel instruction. It's the only thing I can >think of that would make the two versions act so differently. > >Does this make any sense to you guys? I think your conclusion is correct. MOVFF takes a 12 bit address, so it can operate on any address in the data memory with no banking. The second bit of code loads 0x40 into W and tries to add it to your 'i' value by using ADDWF. Unfortunately ADDWF takes only an 8 bit address, and since the access bank is not being used here, if the BSR register is not correctly set at this point the result will be invalid. It may be worth trying this with the optimiser disabled to see if the bank selction is being removed by the optimiser or never inserted in the first place. Regards Mike ======================================================================= This e-mail is intended for the person it is addressed to only. The information contained in it may be confidential and/or protected by law. If you are not the intended recipient of this message, you must not make any use of this information, or copy or show it to any person. Please contact us immediately to tell us that you have received this e-mail, and return the original to us. Any use, forwarding, printing or copying of this message is strictly prohibited. No part of this message can be considered a request for goods or services. ======================================================================= -- http://www.piclist.com PIC/SX FAQ & list archive View/change your membership options at http://mailman.mit.edu/mailman/listinfo/piclist