Michael Rigby-Jones wrote: > >> -----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 > x40 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,... I think it is. To use the BSR, the machine inst for ADDWF "2400" would have been "2500". The difference is the "a" bit. a = "0" => access bank. And the "MOVWF _SSPBUF" also uses the access bank, so it weird... Maybe the asm listing isn't the final PIC code ? Notice that the target adress of both MOVWF and MOVFF is h'000', SSPBUF is at h'FC9' (in one of the PIC18 I looked at). I'd try to write a few lines in asm in MPALB and run it through MPSIM and see what happens. Jan-Erik. -- http://www.piclist.com PIC/SX FAQ & list archive View/change your membership options at http://mailman.mit.edu/mailman/listinfo/piclist