How do I view Assembly my C code in MPLAB x
Asked Answered
S

5

6

I have code written in C but I need to see the Assembly file so I can optimize the code and figure out how long certain functions will take. Does anyone know of a quick way to pull up the Assembly code?

Salesclerk answered 23/7, 2014 at 15:35 Comment(4)
It's a safe bet that the C compiler authors are much better at assembly-level optimization than you are. For the sake of your code and sanity, please rethink your hand-optimization plans.Smithery
indeed, you will most certainly not be able to produce something better than any modern compiler. You would be advised to stop your quest for "leet h4xx0r sk1llz" and do something useful instead - just saying. You cant optimize something which has already been optimized by a machine, thats a childish dream.Ry
@SevaAlekseyev and specializt, get off your high horses! It is TOTALLY possible to optimize better than a modern C compiler - especially on an 8-bit processor. Also, he asked because he wanted to see how long some functions take, which is also a PERFECTLY REASONABLE reason on a pic processor which has no multithreading so all functions in the main loop must be polled.Weitzman
Aldo, the free mplab-compilers don't optimize at all :)Burrow
D
2

You basically just have to not compile it all the way through, there are flags available so that you can see your code in various states, including assembly.

Take a .c file and compile it with gcc -S test.c

EDIT: I didn't think MPLAB was important to your question until I googled it, but I guess it's safe to assume that you're running this code in the non-OS form?

EDIT: A few MPLAB answers http://www.microchip.com/forums/m537589.aspx

Devolve answered 23/7, 2014 at 15:45 Comment(0)
B
9

I also had the same problem as you. Here is what worked for me.

Debug the main program, when finished, choose

" Window >> Debugging >> Disassembly ".

Then you would see the corresponding assembly code.

Hope it could help you out.

Bizerte answered 31/10, 2014 at 14:27 Comment(0)
R
4

For anyone looking for this in the future, I stumbled on the same problem and a better solution.

In MPLAB X, right click the toolbar and select customize (also under View/Toolbars). Now in the menu of things you can drag to the toolbar find the 'Window' tree and under that 'Disassembly Listing File'. Drag that to somewhere on a toolbar (choose one you have set to always be there).

Now when you build something in debug mode you can click the button to open a (nicely formatted) assembly window. If you keep it open it will auto-refresh after each build.

Rimple answered 5/6, 2015 at 7:13 Comment(0)
D
2

You basically just have to not compile it all the way through, there are flags available so that you can see your code in various states, including assembly.

Take a .c file and compile it with gcc -S test.c

EDIT: I didn't think MPLAB was important to your question until I googled it, but I guess it's safe to assume that you're running this code in the non-OS form?

EDIT: A few MPLAB answers http://www.microchip.com/forums/m537589.aspx

Devolve answered 23/7, 2014 at 15:45 Comment(0)
B
1

Look in the folder dist/default/production/ and you may find a '.lst'-file there, which contains an annotated assembly representation of your program.

At least that works on my machine, MPLAB v3.45 and XC8 compiler v1.38.

Burrow answered 30/12, 2016 at 22:14 Comment(0)
C
1

This works for MPLAB X IDE v5.40:

Go to Project Properties.
Select Simulator as tool.
Set a breakpoint somewhere in your code.
Debug Main Project.
Window -> Debugging -> Disassembly

Cumuliform answered 28/9, 2020 at 20:45 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.