gnu assember style guide?

Go To Last Post
6 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Although there are lots of C and C++ style guides to choose from, I've not been able to find anything for assembler.  Has anyone come across one?

 

I've looked at the linux kernel source, and unlike the C style, I'm not as comfortable using the style used in the assembler code.  A couple of my issues with it:

1) Use of local labels (.Lfoo:) means no symbol gets emitted to the .o, making disassembly harder to follow.

2) Heavy use of preprocessor macros (#define FOO ...) instead of using asm macros where possible

 

I've noticed the v-usb code uses #define and #undef to name registers used in asm functions.

https://github.com/obdev/v-usb/b...

I'd prefer a cleaner way to do it.  For example, using one .S file per function would permit dropping the #undefs at the end.

 

AVR-libc pseudo-instruction macros start with an X_, such as X_sbiw.  I have macros I've written such as addi (uses subi with the arg negated), and have thought about using the same pattern.

 

I also wonder if there isn't a better disassembler I could use instead of avr-objdump.  There's lots of things I wish it would do, like display global and local symbols differently.  In the code below millis is global and _reload is local.

00000000 <millis>:
   0:   e0 e0           ldi     r30, 0x00       ; 0
   2:   f0 e0           ldi     r31, 0x00       ; 0

00000004 <_reload>:
   4:   60 81           ld      r22, Z
   6:   71 81           ldd     r23, Z+1        ; 0x01
   8:   82 81           ldd     r24, Z+2        ; 0x02
   a:   93 81           ldd     r25, Z+3        ; 0x03
   c:   00 80           ld      r0, Z
   e:   06 16           cp      r0, r22
  10:   01 f4           brne    .+0             ; 0x12 <_reload+0xe>
  12:   08 95           ret

 

I have no special talents.  I am only passionately curious. - Albert Einstein

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

ralphd wrote:
I also wonder if there isn't a better disassembler I could use instead of avr-objdump.
Consider writing your own.  As instruction sets go the AVR is not complicated.

C: i = "told you so";

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I know this is a bit vague but I've seen a thread in the last few months announcing a "better" disasm for AVR but more than that I cannot remember. I seem to remember that it may have had intelligent data area detection etc.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

ralphd wrote:
I also wonder if there isn't a better disassembler I could use instead of avr-objdump.

I've been playing around with this one  https://cutter.re/

But since it's a generalist disassembler that happens to support AVR, it has some trouble with the Harvard architecture typical of AVR, so finding RAM variables is not the easiest thing.

 

Yeah something specific and optimized for AVR would be nice.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I just tried llvm-objdump 11.0.0, and it doesn't recognize "st Z+, r".  It outputs <unknown>.

 

I have no special talents.  I am only passionately curious. - Albert Einstein

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

clawson wrote:

I know this is a bit vague but I've seen a thread in the last few months announcing a "better" disasm for AVR but more than that I cannot remember. I seem to remember that it may have had intelligent data area detection etc.

 

maybe these?

libvmcu-virtual-mcu-library

brief-update-avr-debugger