how do you view assembly listing after compile

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

I would AVR Studio to produce an assembler listing when I select Build | Build or when I select Build | Compile. The only way I know of viewing the avr-gcc generated assembler in AVR Studio is by going into a debug session and then selecting View | Disassembler (which is grayed out otherwise). I was wondering if I could modify the AVR studio makefile to generate the assembler without being required to start a debug session?

AVR Studio makefile for a single file main.c project.


###############################################################################
# Makefile for the project UART
###############################################################################

## General Flags
PROJECT = UART
MCU = atmega32
TARGET = UART.elf
CC = avr-gcc.exe

## Options common to compile, link and assembly rules
COMMON = -mmcu=$(MCU)

## Compile options common for all C compilation units.
CFLAGS = $(COMMON)
CFLAGS += -Wall -gdwarf-2   -DF_CPU=18432000UL -O0 -fsigned-char
CFLAGS += -MD -MP -MT $(*F).o -MF dep/$(@F).d 

## Assembly specific flags
ASMFLAGS = $(COMMON)
ASMFLAGS += $(CFLAGS)
ASMFLAGS += -x assembler-with-cpp -Wa,-gdwarf2

## Linker flags
LDFLAGS = $(COMMON)
LDFLAGS += 


## Intel Hex file production flags
HEX_FLASH_FLAGS = -R .eeprom

HEX_EEPROM_FLAGS = -j .eeprom
HEX_EEPROM_FLAGS += --set-section-flags=.eeprom="alloc,load"
HEX_EEPROM_FLAGS += --change-section-lma .eeprom=0 --no-change-warnings


## Objects that must be built in order to link
OBJECTS = main.o 

## Objects explicitly added by the user
LINKONLYOBJECTS = 

## Build
all: $(TARGET) UART.hex UART.eep size

## Compile
main.o: ../main.c
	$(CC) $(INCLUDES) $(CFLAGS) -c  $<

##Link
$(TARGET): $(OBJECTS)
	 $(CC) $(LDFLAGS) $(OBJECTS) $(LINKONLYOBJECTS) $(LIBDIRS) $(LIBS) -o $(TARGET)

%.hex: $(TARGET)
	avr-objcopy -O ihex $(HEX_FLASH_FLAGS)  $< $@

%.eep: $(TARGET)
	-avr-objcopy $(HEX_EEPROM_FLAGS) -O ihex $< $@ || exit 0

%.lss: $(TARGET)
	avr-objdump -h -S $< > $@

size: ${TARGET}
	@echo
	@avr-size -C --mcu=${MCU} ${TARGET}

## Clean target
.PHONY: clean
clean:
	-rm -rf $(OBJECTS) UART.elf dep/* UART.hex UART.eep

## Other dependencies
-include $(shell mkdir dep 2>/dev/null) $(wildcard dep/*)
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Start a debug session, right click on the code you're debugging and right click and select Goto Dissasembly.

There are pointy haired bald people.
Time flies when you have a bad prescaler selected.

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

The disassembly is from avr studio (avrdisassembler.dll I presume), so the makefile will have no effect (on the avr studio disassembler at least).

I too would like the disassembler available without starting the simulator.

(I assume you are not talking about the lss listing, but the 'raw' disassembled version that avr studio produces, so let's call it the disassembly listing and not the assembly listing as they not the same thing)

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

Surely you just add the required flags for producing .lss file. Or you can keep the generated .s files.

IMHO I find gcc generated assembler totally unreadable. But I presume that you just want to check small snippets of code. I would assume (but have never done it) that you can set the required flags so that the ELF debug lines come from the .s file rather than the .c file.

You would then have to debug while the code window is full of gcc generated treacle.

David.

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

Open either the .lss file or the .lst file. Both have assembly info in them, but with different "other" info.

Regards,
Steve A.

The Board helps those that help themselves.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0
Start a debug session, right click on the code you're debugging and right click and select Goto Dissasembly.

I am looking for a way to do it without go into debugging to view the assembler.

(I assume you are not talking about the lss listing, but the 'raw' disassembled version that avr studio produces)

That is correct. I would like to the .asm file to pop up in the project directory the same way .o and .elf do after compiling.

I was wondering if this would be possible by adding a avr-objdump under the ##Build line as part of the build process. The avr-objdump documentation says "Display information from object files including disassembly."

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

Project-Configuration Options-tick "Generate List File"

(probably also tick Generate .map file too)

Now when you build the ./default output directory contains proj.map and proj.lss

Note however that the .lss is generated by avr-objdump and the one in the binutils that ships with the very latest WinAVR seems incapable of producing an interleaved C/Asm view so you might want to lift the avr-objdump from an older WinAVR installation for the time being.

Note that I'm never that great a fan of this though. The disassembly you see this way has been through the .c->compiler->.o, .o's->linker->.elf, .elf->obj-dump disassembler->.lss process so the interleaving view (when it works does not always accurately reflect things).

This is one of the many reasons I prefer to build at the command line using an Mfile generated "Makefile" rather than the auto-generated Makefile from within Studio. In this case the Mfile template has a rule to build .s files:

# Compile: create assembler files from C source files.
%.s : %.c
	$(CC) -S -fverbose-asm $(ALL_CFLAGS) $< -o $@

and you may spot I've added a -fverbose-asm to that so you get far more comments added into the output .s file to document what the compiler was "thinking" when it converted the C to assembler.

Now you just go into the project directory, pick the file_of_interest.c and use:

C:\>make file_of_interest.s

and you end up wiht a copy of the (usually hidden/temporary) file that the C compiler would have passed to avr-as but complete with comments.

In fact I actually use a combination of all three - .s files, .lss files and Studio simulator interleaved C/Asm view as each has a "little something" to offer.

Cliff

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

PS If you go with the Mfile template then another nice feature is

C:\>make file_of_interest.i

the file this outputs is file_of_interest.c after it's passed through the C Pre Processor but before it's offered to the core C compiler. So all the macros are expanded, the #if 0'd stuff is gone and you get a much more "raw" view of what DDRD=0xF5 really means!

Cliff

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

8 gcc messages in the wrong forum. If you used a real commercial compiler like imagecraft, you get a great interspered c-assmbler file with absolute addresses.

Imagecraft compiler user

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

Quote:
8 gcc messages in the wrong forum
Is that a record?

Mine was about the avr studio disassembler, so that one don't count.

Quote:
great interspered c-assmbler
Bob, your keyboard plug is coming out.

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

Just for Bob - like Magic....

BTW, interesting to see Wikipedia's view on what is "commerical":

http://en.wikipedia.org/wiki/Com...

it seems to hinge around whether something is of "economic value":

http://en.wikipedia.org/wiki/Val...

That seems to be suggesting that "value" may be more than just monetary - kind of "beauty in the eye of the beholder perhaps?"

(but as we all know from Lee, GCC is of "infinite value" of course! ;) )

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

If I now talk about avr studio disassembler, will we have to move this thread again? I will throw in some gcc talk just in case.

I like the avr studio disassembler listing for several reasons, one being I can see the word addresses instead of byte addresses. Not a big deal, but nice sometimes. Also the objdump seems to 'hide' nop's sometimes, which I also want to see.

Is there any gcc output like the avr studio disassembler which will also show word addresses? and not 'hide' nop's?

If not, its not a big deal to start the simulator and view the disassembled output.

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

Needless to say there is a command line switch to objdump (-z) to say "don't do 0x00 byte hiding" which you can add to the rule that generates the .lss (or at least you can in your OWN Makefile rather than Studio's one)

As for word addressing - doubt that - the core of binutils is very 8bit-centric

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

Then I will stick to plan A (just start simulator to see disassembly when I want to see word addresses, etc.).

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

bobgardner wrote:
If you used a real commercial compiler like imagecraft,

Y'know, if I sold you WinAVR for 5 bucks, it'd be a commercial compiler wouldn't it?

But for you Bob, I'll give it to you for free, cause you're such a nice guy. ;)

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

With the commercial compiler, I can get the guy that sells it on the phone and say 'you need to add this and that' and its in the next version. Are you the go-to guy for putting an interspersed c-assembler listing with absolute addresses in the winavr package?

Imagecraft compiler user

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

Already have 'interspersed c-assembler'-

assuming we are talking about the same thing, this is a sample (I use an older version of gcc from winavr20060421)-

void init_mystuff(void){

    DDRC = ((1<<PC5) | (1<<PC3) | (1<<PC4)); 
 6f4:	88 e3       	ldi	r24, 0x38	; 56
 6f6:	87 b9       	out	0x07, r24	; 7
    DDRD = (1<<PD7);
 6f8:	80 e8       	ldi	r24, 0x80	; 128
 6fa:	8a b9       	out	0x0a, r24	; 10
    DDRB = ((1<<PB0) | (1<<PB2));
 6fc:	95 e0       	ldi	r25, 0x05	; 5
 6fe:	94 b9       	out	0x04, r25	; 4

    PORTB |= (1<<PB0);
 700:	28 9a       	sbi	0x05, 0	; 5
    PORTD |= (1<<PD7);
 702:	5f 9a       	sbi	0x0b, 7	; 11

    PORTB |= ((1<<PB1) | (1<<PB3));
 704:	85 b1       	in	r24, 0x05	; 5
 706:	8a 60       	ori	r24, 0x0A	; 10
 708:	85 b9       	out	0x05, r24	; 5
    PORTD |= (1<<PD6);
 70a:	5e 9a       	sbi	0x0b, 6	; 11

    PCICR = ((1<<PCIE0) | (1<<PCIE2));
 70c:	90 93 68 00 	sts	0x0068, r25
    PCMSK0 = ((1<<PCINT1) | (1<<PCINT3));
 710:	8a e0       	ldi	r24, 0x0A	; 10
 712:	80 93 6b 00 	sts	0x006B, r24
    PCMSK2 = (1<<PCINT22);
 716:	80 e4       	ldi	r24, 0x40	; 64
 718:	80 93 6d 00 	sts	0x006D, r24
 
 //etc
 //...
 
 }

looks interspersed to me. But its byte addressed and not word addressed. Which is why I want to see the avr studio disassembly sometimes.

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

Dear Bob!

Plugging "commercial compilers" is just fine with me. Being "envious" (in lack of a better word - bear with me) on the forum specific for avr-gcc here is OK too.

Insinuating that a feature is lacking when this is factually wrong, or at least not entirely true, is IMO not fair.

Also: Is the word 'real' qualifying 'commercial' or 'compiler'?

--

Corollary: From time to time people talk here about having GNU/Linux as the OS platform for their personal computers. Why do we never hear you arguing "If you used a real commercial operating system like MS Windows, you get a great "? (Careful now, this is a trap!)

As of January 15, 2018, Site fix-up work has begun! Now do your part and report any bugs or deficiencies here

No guarantees, but if we don't report problems they won't get much of  a chance to be fixed! Details/discussions at link given just above.

 

"Some questions have no answers."[C Baird] "There comes a point where the spoon-feeding has to stop and the independent thinking has to start." [C Lawson] "There are always ways to disagree, without being disagreeable."[E Weddington] "Words represent concepts. Use the wrong words, communicate the wrong concept." [J Morin] "Persistence only goes so far if you set yourself up for failure." [Kartman]

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

Quote:

"If you used a real commercial operating system like MS Windows, you get a great "?

"If you used a real commercial operating system like MS Windows, you get a great AVR tool called AVRStudio."

Quote:

(Careful now, this is a trap!)

You bet--you forced me to use "great" adjoining "AVRStudio".

Lee

You can put lipstick on a pig, but it is still a pig.

I've never met a pig I didn't like, as long as you have some salt and pepper.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0
Note that I'm never that great a fan of this though. The disassembly you see this way has been through the .c->compiler->.o, .o's->linker->.elf, .elf->obj-dump disassembler->.lss process so the interleaving view (when it works does not always accurately reflect things).

I had to do a reread when I read this after reading what you said :)

An even more useful option is -S. This option disassembles the binary file and intersperses the source code in the output! This method is much better, in my opinion, than using the -S with the compiler because this listing includes routines from the libraries and the vector table contents. Also, all the "fix-ups" have been satisfied. In other words, the listing generated by this option reflects the actual code that the processor will run.
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I'm covered... when I made my snide comment, I was reading the message in the avr forum...

Imagecraft compiler user

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

Quote:

I'm covered... when I made my snide comment, I was reading the message in the avr forum...

What are you saying here? In the AVR forum it's OK not to stick to facts? Or is it OK when something is posted in the wrong forum? :shock:

As of January 15, 2018, Site fix-up work has begun! Now do your part and report any bugs or deficiencies here

No guarantees, but if we don't report problems they won't get much of  a chance to be fixed! Details/discussions at link given just above.

 

"Some questions have no answers."[C Baird] "There comes a point where the spoon-feeding has to stop and the independent thinking has to start." [C Lawson] "There are always ways to disagree, without being disagreeable."[E Weddington] "Words represent concepts. Use the wrong words, communicate the wrong concept." [J Morin] "Persistence only goes so far if you set yourself up for failure." [Kartman]

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

I think I may have found the problem with objdump -S. It will work if the source file has a Unix end-of-line convention. Furthermore, it seems that AVR Studio honors each opened file's EOL convention, so running dos2unix once on the source files should be sufficient as a workaround.

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

Wow - nice piece of detective work!

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

objdump in binutils 2.18 caches the content of source-files. The read() function is used to read in a complete source-file into memory for later indexing. It seems that read() from mingw internally converts line-endings from "DOS-style" (\r\n) to "Unix-style" (\n) if the files is opened in "text-mode" and since later in objdump the file-size is checked against the number of bytes read the test fails and objdump does not "parse" the file. This patch should fix the problem:

diff -Nbaur binutils-2.18.50/binutils/objdump.c binutils-2.18.50-mod/binutils/objdump.c
--- binutils-2.18.50/binutils/objdump.c Thu Feb  7 16:04:47 2008
+++ binutils-2.18.50-mod/binutils/objdump.c     Thu Feb  7 16:02:11 2008
@@ -964,7 +964,12 @@
 #endif
   const char *map;
   struct stat st;
+  
+#if (defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN32__
+  int fd = open (fn, O_RDONLY | O_BINARY);
+#else
   int fd = open (fn, O_RDONLY);
+#endif
 
   if (fd < 0)
     return NULL;

Only tested with another build-target (for ARM) but should be universal for all targets. It also should be easy to create a "binary-patch" for objdump.exe in WinARM 12/2007. Since only one byte needs to be modified.

Martin Thomas

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

Quote:
It also should be easy to create a "binary-patch" for objdump.exe in WinARM 12/2007. Since only one byte needs to be modified.

Could you please wrote which byte should be changed?

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

Clawson (or anyone else for that matter) do you have a location for an avr-objdump version that does c/asm interleaving? Without me having to install an old version of WinAVR just to extract it that is.

Edward

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

Edward,

I posted a link to it in answer to a request from Dean previously. I actually thought it was in this thread but it was certainly in GCC Forum and a search should find it. (the URL will be on www.ourcottage.plus.com)

EDIT: found the thread:

https://www.avrfreaks.net/index.p...