I started to change the code of the first library to reduce the stack usage and have a few questions about that...
In a first step I took a function with several arguments
Code: Select all
unsigned char RFID::MFRC522ToCard(unsigned char command, unsigned char *sendData, unsigned char sendLen, unsigned char *backData, unsigned int *backLen)
For the original function I found this in the *.rst file:
Code: Select all
1489 ;------------------------------------------------------------
1490 ;Allocation info for local variables in function '__cxx__RFID__method__MFRC522ToCard0505p0505p05p09'
1491 ;------------------------------------------------------------
1492 ;command Allocated to stack - _bp -3
1493 ;sendData Allocated to stack - _bp -6
1494 ;sendLen Allocated to stack - _bp -7
1495 ;backData Allocated to stack - _bp -10
1496 ;backLen Allocated to stack - _bp -13
1497 ;v__this Allocated to registers r5 r6 r7
1498 ;this Allocated to stack - _bp +3
1499 ;status Allocated to stack - _bp +11
1500 ;irqEn Allocated to stack - _bp +6
1501 ;waitIRq Allocated to stack - _bp +7
1502 ;lastBits Allocated to registers r6
1503 ;n Allocated to stack - _bp +10
1504 ;i Allocated to stack - _bp +8
1505 ;sloc0 Allocated to stack - _bp +1
1506 ;------------------------------------------------------------
1507 ; C:\Users\andre\AppData\Local\Temp\build6796448123814796796.tmp\ZUNO_RFID_ucxx.c:642: unsigned char __cxx__RFID__method__MFRC522ToCard0505p0505p05p09(void * v__this, unsigned char command, unsigned char * sendData, unsigned char sendLen, unsigned char * backData, unsigned int * backLen)
For the modified function I found this:
Code: Select all
2247 ;------------------------------------------------------------
2248 ;Allocation info for local variables in function '__cxx__RFID__method__MFRC522ToCard_ah01prtoCard'
2249 ;------------------------------------------------------------
2250 ;toCard_p Allocated to stack - _bp -5
2251 ;v__this Allocated to registers r5 r6 r7
2252 ;this Allocated to stack - _bp +14
2253 ;status Allocated to stack - _bp +9
2254 ;irqEn Allocated to stack - _bp +8
2255 ;waitIRq Allocated to stack - _bp +11
2256 ;lastBits Allocated to stack - _bp +1
2257 ;n Allocated to stack - _bp +10
2258 ;i Allocated to stack - _bp +12
2259 ;sloc0 Allocated to stack - _bp +4
2260 ;sloc1 Allocated to stack - _bp +5
2261 ;sloc2 Allocated to stack - _bp +1
2262 ;------------------------------------------------------------
2263 ; C:\Users\andre\AppData\Local\Temp\build6796448123814796796.tmp\ZUNO_RFID_ucxx.c:858: unsigned char __cxx__RFID__method__MFRC522ToCard_ah01prtoCard(void * v__this, struct toCard * toCard_p)
2264 ; -----------------------------------------
I expected that "removing" the parameters would lead to a higher reduction...
I noticed that in the modified function there additional values put on the stack...
"lastbits" was previously in a register and is now put on stack. lastbits is used to calculate a value that is then assigned to one of the parameter / the corresponding value in the global struct.
Next, there are now to more local values "sloc1" and "sloc2"... Which I can't correlate to any part of the code as I am not so good in reading assembler code...
Can you tell why lastbits is now on the stack and no longer in a register? The part where lastbits is used is here:
Code: Select all
lastBits = readMFRC522(ControlReg) & 0x07;
if (lastBits) {
*toCard_p->backLen = (n-1)*8 + lastBits;
} else {
*toCard_p->backLen = n*8;
}
Next question, is there a way to tell why the compiler created two more local variables and where they are used without fully understanding the assembler code?
So far I did not even check the modified function, I just want to make sure that I understood the approach correctly and can use the numbers from the *.rst to check If some changes really reduce the use of the stack and that in this case I would have a reduction from 26 to 21 bytes.
Best regards,
Andreas.