How to view disassembled C/C++ code in Visual Studio Code
There are four steps to do this. That’s assuming that you have successfully compiled your C or C++ program and have the source file handy.
- Install Disassembly Explorer extension into Visual Studio Code.
- Set a configuration setting.
- Run a single line command in terminal.
- Select a command in the Visual Studio Code command palette.
Install Disassembly Explorer.
In Visual Studio Code just switch to the extension tab and search for Dissassembly Explorer and click the install button.
Next is configuration
View the installed extensions and click the cogwheel for Disassembly Explorer then click Extension Settings at the bottom of the popup menu. A Settings tab will open, click Edit in settings.json.
You should see a few settings but only this one matters: “compilerexplorer.compilationDirectory”: “${workspaceFolder}/.vscode” . That path is where the compile etc. .json files are located.
Now open a terminal
I’ve assumed that you are running on Linux or Mac. If you are on Windows, you can also use Visual Studio Community Edition which includes disassembly features and why I’m not mentioning it here.
In the folder with your source files issue this command in the terminal.
clang -g -o asteroids.S -S asteroids.c
If OTOH you are running gcc then just substitute gcc for clang.
Finally, back in Visual Studio Code select your source file as the open tab then press F1 and in the menu that appears type in enough of Disassembly Explorer: Show until you can select it and a second tab should open with the disassembly. Click on a function in the source tab and it will jump to the correct place in the disassembled code.