The professional, friendly Java community. 21,500 members and growing!

The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.

//
// echo.jas
//
// Author
// Dan Stone
//
// Description
// Sample assembly program that reads a key press and echoes the result to
// standard output.
//
.main
L1: IN // request character input from memory
DUP // duplicate top of stack (inputed char) for comparing
BIPUSH 0x0 // push 0x0 for comparison
IF_ICMPEQ L2 // if no characters are available for input, loop
OUT // else, print character
GOTO L1 // loop back to beginning of program
L2: POP // No key has been pushed, so clear the stack,
GOTO L1 // and start over
.end-main

They want me to write microinstructions for code for

X + Y - Z

They said:

[1] (35 points) Write an IJVM assembly program that accepts three integer values (say, X, Y, and Z)
from the console and then print the result of the following computation on the console screen:
X + Y – Z
Hints: You can refer to “add.jas” and “echo.jas” sample code. You may do the computation just
ONCE.

Re: I might be asking too much but does anyone know assembly code for JVM?

Working directly with Java byte-code is a little... odd. Few people know how Java byte-code works. I'm moving this Other Programming Languages for this reason.

When working with assembly, you have to remember to code very verbosely. I don't have any experience with working with Java byte-code, but when working with other assembly languages one of the most important parts is learning the instructions set. Read through the documentation (pay attention to the main points of that instruction, as well as any "fringe" behaviors of that instruction), and see if you can put together something which would accomplish what you want. It looks like the two samples provided can add and print out numbers.

a few hints:
x+y-z = a-z
where a =x+y
If you can find an instruction which subtracts two numbers, this would be fairly simple. Otherwise, look for a negation operator, or in the most extreme case, you'll need to write a two's compliment routine which computes the negation for you.