I have to do a program to school in Assembler but we did just a few basic things. Is it possible to write code in Java and convert it to Assembler?
Asked
Active
Viewed 1.2k times
-10
-
1see [Why is "Is it possible to:" a poorly worded question?](https://softwareengineering.meta.stackexchange.com/a/7274/31260) – gnat May 16 '17 at 08:27
-
5I'm pretty certain the goal of your class is to teach *you* to write assembly code, not the computer. – Kilian Foth May 16 '17 at 08:28
-
Related: https://softwareengineering.stackexchange.com/questions/285888/how-do-java-aot-compilers-work and http://openjdk.java.net/jeps/295 – Polygnome May 16 '17 at 08:32
-
1Possible duplicate of [How do Java AOT compilers work?](https://softwareengineering.stackexchange.com/questions/285888/how-do-java-aot-compilers-work) – Polygnome May 16 '17 at 08:34
-
Yes, it is possible. Converting a program from one language to another is always possible as long as the target language is computationally powerful enough to express the semantics of the program. In particular, it is always possible if the target language is Turing-complete. Converting a program from one language to another is called "compilation" and it can be done by a program, such a program is called a "compiler". So, you just need to find (or write) a compiler from Java to assembler. – Jörg W Mittag May 16 '17 at 09:03
-
Java contains a lot of classes in the JDK that have nothing to do with your program. Are you going to submit the assembly code for them too? And if you are not, how do you make your calls to methods in the JDK do something, since there is no direct counterpart in assembly? – SOFe May 16 '17 at 10:12
1 Answers
3
Yes you can. While normally Java is compiled to bytecode executed by JVM, there are compilers that output native code. For example, gcc
has Java front-end, the gcj
, so you can use that along with -s
option (which emits assembly output instead of machine code).
Having said that, don't expect to fool anyone. Your teacher will instantly recognise that your code has not been written by you.

Gerardo Zinno
- 101
- 5

el.pescado - нет войне
- 1,215
- 10
- 14
-
Thank you very much! I know it probably wouldn't look exactly the same but my teacher really don't care. He didn't teach us anything except add and sub and he doesn't even know a lot of stuff when you ask him. He just want to see that our program works. – jankova0013 May 16 '17 at 12:19
-
6I mean, unless your teacher totally don't care, it will be instantly recognizable as machine-generated code. – el.pescado - нет войне May 16 '17 at 12:58