Products > Embedded Computing

[solved] AVR-GCC generates ASM stuffed with bloatware use of reserved registers

<< < (7/7)

Nominal Animal:
If you use GDB for debugging, note that it supports custom commands via plug-ins written in Python.

I investigated this myself a decade ago, and wrote an example to save or display C pointer-based binary trees in Graphviz DOT format.  It adds a tree command, which takes some optional parameters in name=value format (specifying the left and right child pointer member names for example) and the name of the variable pointing to the root node of the binary tree.

Browsing through the GDB Python API is very informative, and can make debugging much nicer, even on AVRs with JTAG via avarice and GDB.

gjl:

--- Quote from: RoGeorge on July 20, 2024, 07:23:36 am ---The reason for using -O0 was to be sure that each C line has a 1:1 direct translation into some assembly code.
--- End quote ---
Even with -O0 GCC won't translate line by line.  It doesn't matter whether you

--- Code: ---PORTB |= _BV(PB4);
--- End code ---
or

--- Code: ---PORTB
|=
 _BV
(
PB4
)
;
--- End code ---
And notice that PORTB, _BV and PB4 are macros that resolve to more complicated expressions.

Anyway; according to the C standard, that statement performs:

* Perform a load from uint8_t volaltile location.
* Promote that 8-bit value to a 16-bit integer as required by bit-or.
* Perform a 16-bit bit-or of the promoted 16-bit result with 16-bit mask (also promoted).
* Extract the lower 8 bits.
* Store that result to a uint8_t volaltile location.
Hence you are requesting 5 operations involovnd load, store and a 16-bit operation to be optimized to one single instruction with optimizations completely turned off!

So you get what you requested by turning optimizations off entirely

Navigation

[0] Message Index

[*] Previous page

There was an error while thanking
Thanking...
Go to full version
Powered by SMFPacks Advanced Attachments Uploader Mod