Settings

Theme

Show HN: Online C/C++ to assembly visualizer [Weekend Project]

assembly.ynh.io

149 points by ynh 13 years ago · 46 comments

Reader

munin 13 years ago

LLVM has a similar page: http://llvm.org/demo

you can compile C/C++ to LLVM IR and also 32 or 64 bit intel assembler. you can also see the effects of different optimizations, etc

berkut 13 years ago

Side by side would be a better layout like: http://gcc.godbolt.org/

option_greek 13 years ago

Nice project. Will be more useful if there is an explanation of code generated. For example, making the various assembly instructions clickable and displaying information about them. Also a tiny bit of explanation about code and data sections might be of help too :)

  • ynhOP 13 years ago

    Ok added to the todo list

    • wutwot 13 years ago

      You don't filter out CPP macro's. I would skip that and only allow C code. Or run this thing in a proper jail because at the moment:

      - doing an include #include "/dev/random" will block the thread. - including "/etc/passwd" is also possible although I don't see a direct way to turn this into password disclosure.

      Seriously; even if it's a weekend project, letting people run all kinds of potentially bad code on your machine is never a good idea. Even though you don't run the binaries yourself there's so many ways to mess around with a compiler. You just don't know what's going to happen.

      • __alexs 13 years ago

        chroot would probably be sufficient. Barring some sort of code execution vuln in the compiler you can only load stuff off of the filesystem.

        Having the actual CPP available is nice because some bits of libc are only macros.

      • ynhOP 13 years ago

        I have now added some basic macro detection

        • yonilevy 13 years ago

          #define x "/etc/passwd" #include x

          • ynhOP 13 years ago

            I have now fixed it. But I think there must be an other way to make it safe. Maybe a sandbox

            • dzorz 13 years ago

              This is part of your /etc/shadow file:

                  root:censored
              
              We can still read /etc/ssh/ssh_host_rsa_key, etc.

              Edit: removed hash, sorry

              • daeken 13 years ago

                Saying "you can read /etc/shadow by doing X, Y, and Z" is okay -- it's a permanent record there was a flaw. Saying "here's your root password hash" is not ok; even once the flaw is fixed, that hash is still floating around out there. I'd take advantage of the edit period and remove that from your comment; it's just not cool. The OP should definitely change the root password on the box regardless.

              • wulczer 13 years ago

                Well one easy way to increase security would for this to stop running as root.

                Please, don't ever run your application code as root. Less so when it's facing the Internet.

              • ynhOP 13 years ago

                No problem I think I could fix it.

                Can you show us how you read the content of the file. Just want to learn more

            • espes 13 years ago

              If it's a server used for other things, definitely a sandbox. gcc's not exactly security hardend. Best one (novel solution, though the code's old and shit) I've come across: https://pts-mini-gpl.googlecode.com/svn/trunk/uevalrun/doc/u...

            • ynhOP 13 years ago

              I have now used a the wrapper by gcc-explorer https://github.com/mattgodbolt/gcc-explorer/blob/master/c-pr...

  • Ubiquite 13 years ago

    I could have made the same comment. Good project, could be useful to me. A peace of asm documentation would be tasty.

winter_blue 13 years ago

This could be a great educational tool! It could be used to teach Introductory Computer Organization at the college level.

I have a suggestion:

- Would you be able to separate the web interface, so that it could used to display Java -> JVM assembly, or any other language. Basically, so that it would be re-usable.

- Putting this up on GitHub would be great.

Finally, great work for just a weekend!

unix-dude 13 years ago

Definitely interesting! Lots of us unix people would just run objdump -d for a quick ASM extraction, but this is probably much friendlier to the user just starting to learn C/ASM.

Overall, Good Job!

jrajav 13 years ago

Silently fails if you make a syntax error. I accidentally pasted this without newlines and at first I thought it wasn't responding:

  #include <stdio.h>int main() { printf("Hello World"); }
mappu 13 years ago

Can i recommend adding -masm=intel to your gcc flags? I know AT&T syntax is the default for gcc and gas, but not why. Intel syntax seems clearer to read and is used by most assembly tutorials.

vvnraman 13 years ago

This really removes any hurdle I might have of inspecting the assembly code due to sheer laziness of opening up my Visual Studio and start debugging. Awesome work. If you add some type of interactivity to the generated assembly, it can be made more visual.

b3b0p 13 years ago

I love it!

My only suggestion right now is to have it so you can have the assembly on the left or right side. Maybe it's just me, but my focus seems to be on the left side more than the right.

Since this is a focused on assembly it seems, wouldn't you want the focus on the assembly, not the C? It could be different for different people though.

Aardwolf 13 years ago

In the hello world example, no matter what text you put there, the assembly is the same. Where does the string content go?

tisme 13 years ago

Very neat! Suggestion: add a 'flags' field where you can specify stuff like -std=c99 and any other flags you might need for your code to compile, and a horizontal rule or something like that after every line of input code.

If you do the 'flags' thing make sure you filter it to avoid escapes to the underlying shell.

gtklocker 13 years ago

Error: Command failed: /tmp/test969394043.c:1:0: fatal error: can’t open /root/assembler/ccMEBJ3B.s for writing: Permission denied compilation terminated. The bug is not reproducible, so it is likely a hardware or OS problem.

Really.

daurnimator 13 years ago

Error: Command failed: /bin/sh: 1: c-preload/compiler-wrapper: Permission denied

ajhai 13 years ago

Interesting project. As an improvement to the UI, you can consider adding syntax highlighting to the editor. Take a look at ACE editor (http://ace.ajax.org/).

alpb 13 years ago

Try this on iPad. Generated assembly looks very bad in terms of layout.

  • Zenst 13 years ago

    Apple safari browser? Is it also the case with opera or Chrome on the iPad?

    • jurre 13 years ago

      I would guess it will be the same, Chrome on iPad is basically just an iOS webkit wrapper

  • icefox 13 years ago

    And you can't load any of the examples

erichocean 13 years ago

It'd be nice to make, e.g. the for loop clickable, so that it "stuck" and you could scroll down and see where it ended.

As it is now, as soon as you move your mouse, it unhighlights.

akavi 13 years ago

Does anyone have a link to a good beginner's guide explaining the output?

bostko 13 years ago

Can't you add a function for memorizing the code written?

Thank you!

  • ynhOP 13 years ago

    Yes I could add some thing like a permanent link creator.

jheriko 13 years ago

don't work really - some guidance on use might be acceptable. does it need to be a whole program? my snippets give confusing errors about variable identifiers not being types o_0

  • ynhOP 13 years ago

    It must be a valid c/c++ program. Just wrap your code in a function

pgbovine 13 years ago

excellent -- my unsolicited advice is for you to ping some professors and TAs who teach low-level programming to get them interested in using this in their teaching.

Keyboard Shortcuts

j
Next item
k
Previous item
o / Enter
Open selected item
?
Show this help
Esc
Close modal / clear selection