PIC32Mx understanding disassembly
Hi. I've been using PICs for years but this is the first time I've used a 32bit device. I'm using a PIC32MX270F256B and have running an LCD 320*240 but I'm trying to fix SPI slow thru-put but the disassembly looks like garbage.
details:
MPLAB X IDE v5.4
xc32 v2.5 (optimization level 2)
eg. here's a wrapper function for an spi function defined in macros.
void lcd_send(bool dc, uint8_t value)
{
LCD_CS = 0;
if(dc)
LCD_DC = 1;
else
LCD_DC = 0;
LCD_FUNC_1B(value);
LCD_CS = 1;
}
I look at the disassembly and I expect to see a few instructions relating to LCD_CS = 0 (it would have been 1 line when I was using pic24, a BCLR instruction, but anyway...). However I see 300 lines of assembly, most of it repetitions
142: void lcd_send(bool dc, uint8_t value)
143: {
9D000000 27BDFFE8 ADDIU SP, SP, -24
9D000004 AFBF0014 SW RA, 20(SP)
9D000008 AFB00010 SW S0, 16(SP)
144: LCD_CS = 0;
9D00000C 3C10BF88 LUI S0, -16504
9D000010 96026130 LHU V0, 24880(S0)
9D000014 7C022104 INS V0, ZERO, 4, 1
9D000018 A6026130 SH V0, 24880(S0)
9D000344 3C10BF88 LUI S0, -16504
9D000348 96026130 LHU V0, 24880(S0)
9D000354 7C022104 INS V0, ZERO, 4, 1
9D000358 A6026130 SH V0, 24880(S0)
9D000384 96026130 LHU V0, 24880(S0)
9D000388 7C022104 INS V0, ZERO, 4, 1
9D00038C A6026130 SH V0, 24880(S0)
9D0003D4 3C10BF88 LUI S0, -16504
9D0003D8 96026130 LHU V0, 24880(S0)
9D0003E0 7C022104 INS V0, ZERO, 4, 1
9D0003E4 A6026130 SH V0, 24880(S0)
9D00042C 3C10BF88 LUI S0, -16504
9D000430 96026130 LHU V0, 24880(S0)
9D000438 7C022104 INS V0, ZERO, 4, 1
9D00043C A6026130 SH V0, 24880(S0)
9D000498 3C10BF88 LUI S0, -16504
9D00049C 96026130 LHU V0, 24880(S0)
9D0004A8 7C022104 INS V0, ZERO, 4, 1
9D0004AC A6026130 SH V0, 24880(S0)
9D0004FC 96026130 LHU V0, 24880(S0)
now I know these lines can't be executing bc my 'scope shows a delay of ~1us from CS going low to the start of SPI clocking (inside LCD_FUNC_1B) and I'm running at 48MHz so i'm losing ~50 instructions.
Should I give up on understanding the assembly code now I'm working with 32bit PICs? Or is there a setting which would make it more accessible? Any general advice on minimising overheads on PIC32s would be appreciated. I'm used to working with PIC24s where basic things like setting a bit really only takes 1 line of assembly (BSET). My PIC32 is way faster for float maths, but seems less good for the most basic stuff.
If I turn off optimizations (level = 0) I get something much more realistic, but it does run slower on the 'scope.
142: void lcd_send(bool dc, uint8_t value)
143: {
9D000000 27BDFFE8 ADDIU SP, SP, -24
9D000004 AFBF0014 SW RA, 20(SP)
9D000008 AFBE0010 SW FP, 16(SP)
9D00000C 03A0F021 ADDU FP, SP, ZERO
9D000010 00801821 ADDU V1, A0, ZERO
9D000014 00A01021 ADDU V0, A1, ZERO
9D000018 A3C30018 SB V1, 24(FP)
9D00001C A3C2001C SB V0, 28(FP)
144: LCD_CS = 0;
9D000020 3C03BF88 LUI V1, -16504
9D000024 94626130 LHU V0, 24880(V1)
9D000028 7C022104 INS V0, ZERO, 4, 1
9D00002C A4626130 SH V0, 24880(V1)
145:
146: if(dc)
9D000030 93C20018 LBU V0, 24(FP)
9D000034 10400008 BEQ V0, ZERO, 0x9D000058
9D000038 00000000 NOP
147: LCD_DC = 1;