compiling programme IJVM
I TRY AND COMPILE THE PROGRAMME BELOW BUT HAS ERROR APPEAR ALL THE TIME,,CAN ANYONE CORRECT THE CODE AND WRITE UP THE NEXT METHOD FOR POWER IN THE PROGRAME AS WELL...URGENT
// Program to read two single digit numbers and display
// a.sum
// b.difference (a-b or b-a, whichever gives a positive value)
// c.products (axb)
// d.power (ab)
.constant
OBJEREF 0x40 // for calling method
ten 10 // for multiplication and division when dealing with multiple digits
.end-constant
.main
.var
a
b
.end-var
start:
BIPUSH 69 'E'
OUT
BIPUSH 110 'n'
OUT
BIPUSH 116 't'
OUT
BIPUSH 101 'e'
OUT
BIPUSH 114 'r'
OUT
BIPUSH 32
OUT
BIPUSH 116 't'
OUT
BIPUSH 119 'w'
OUT
BIPUSH 111 'o'
OUT
BIPUSH 32
OUT
BIPUSH 110 'n'
OUT
BIPUSH 117 'u'
OUT
BIPUSH 109 'm'
OUT
BIPUSH 98 'b'
OUT
BIPUSH 101 'e'
OUT
BIPUSH 114 'r'
OUT
BIPUSH 115 's'
OUT
BIPUSH 58 ':'
BIPUSH 10
OUT
inp1: IN // read character input from memory/buffer
DUP // duplicate top stack (inputed char) for comparing
BIPUSH 0 // push o for comparison with null
IF_ICMPEQ null // read next char if no input(null)
DUP // else, duplicate top stack
OUT // print character that being read
BIPUSH 48 // convert char ASCII to real value
ISUB
ISTORE a // store in a
GOTO inp2 // read second number
null: POP // if null,loop to read again
GOTO inpl
inp2: IN // read second number
DUP // duplicate top stack (inputed char) for comparing
BIPUSH 0
IF_ICMPEQ null2 // push 0 for comparison with null
DUP // else, duplicate top stack
OUT // print character that being read
BIPUSH 48 // convert char ASCII to real value
ISUB
ISTORE b // store in b
GOTO add // go to add a and b
null: POP // if null, loop to read again
GOTO inp2
//addition
add: LDC_W OBJREF
ILOAD a // add a and b
ILOAD b
INVOKEVIRTUAL ADDITION
BIPUSH 48 // convert sum to ASCII equivalent for printing
IADD
OUT // print the sum of the two numbers
BIPUSH 83 'S'
OUT
BIPUSH 117 'U'
OUT
BIPUSH 109 'M'
OUT
BIPUSH 61 '='
OUT
BIPUSH 0
OUT
OUT
BIPUSH 10
OUT
GOTO sub
//subtraction
sub: LDC_W OBJREF
ILOAD A
ILOAD B
INVOKEVIRTUAL SUBTRACTION
BIPUSH 48
IADD
BIPUSH 68 'D'
OUT
BIPUSH 105 'i'
OUT
BIPUSH 102 'f'
OUT
BIPUSH 102 'f'
OUT
BIPUSH 101 'e'
OUT
BIPUSH 114 'r'
OUT
BIPUSH 101 'e'
OUT
BIPUSH 110 'n'
OUT
BIPUSH 99 'c'
OUT
BIPUSH 101 'e'
OUT
BIPUSH 61 '='
OUT
BIPUSH 0
OUT
OUT
BIPUSH 10
OUT
GOTO mult
//multiplication
mult:LDC_W OBJREF
ILOAD A
ILOAD B
INVOKEVIRTUAL MULTIPLICATION
BIPUSH 48
IADD
BIPUSH 80 'P' //* Prints product
OUT
BIPUSH 114 'r'
OUT
BIPUSH 111 'o'
OUT
BIPUSH 100 'd'
OUT
BIPUSH 117 'u'
OUT
BIPUSH 99 'c'
OUT
BIPUSH 116 't'
OUT
BIPUSH 61 '='
OUT
BIPUSH 0
OUT
OUT
BIPUSH 10
OUT
GOTO start
stop:
OUT
HALT
.end-main
//addition
.method ADDITION(a,b)
.var // local variable of method
sum
.end-var
ILOAD a
ILOAD b
IADD
ISTORE sum
ILOAD sum // return value by putting on stack before returning
IRETURN
.end-method
//difference
.method SUBTRACTION(a,b)
.var // local variable of method
difference
.end-var
ILOAD a
ILOAD b
ISUB
ISTORE difference
ILOAD difference
IRETURN
.end-method
//multiply
.method MULTIPLICATION(a,b)
.var
product
counter
total
.end-var
L1: Iload a
Iload b
BIPUSH 0
BIPUSH 0
ISUB
ISTORE counter
BIPUSH 0
BIPUSH 0
ISUB
DUP
ISTORE total
GOTO L2
L2:
ILOAD counter
ILOAD a
IF_ICMPEQ L3
ILOAD total
ILOAD b
IADD
ISTORE total
BIPUSH 1
BIPUSH 0
ISUB
ILOAD counter
IADD
ISTORE counter
GOTO L2
L3:
ILOAD total
IRETURN
.end-method
View Answers
Related Tutorials/Questions & Answers:
compiling programme IJVMcompiling programme IJVM I TRY AND COMPILE THE
PROGRAMME BELOW BUT HAS ERROR APPEAR ALL THE TIME,,CAN ANYONE CORRECT THE CODE AND WRITE UP THE NEXT METHOD FOR POWER IN THE PROGRAME AS WELL...URGENT
// Program to read two single
IJVM in
IJVM. For example, if two numbers 2 and 3
are on the stack, the power function... value and b being the value on top). Write an
IJVM code segment... are
allowed to use existing
IJVM instructions only. Include appropriate comments
Advertisements
IJVM in
IJVM. For example, if two numbers 2 and 3
are on the stack, the power function... value and b being the value on top). Write an
IJVM code segment... are
allowed to use existing
IJVM instructions only. Include appropriate comments
IJVMIJVM using
IJVM..can anybody help me in this question
User should be prompted to enter two non-negative numbers (say, a and b where a >0 and
b > 0) line by line and then press the enter key.
Your program should
programmeprogramme Using an ATM, customer can access their bank accounts in order to credit/debit cash and check their account balances.You have to write c
programme to implement a simple ATM for 15 customers. Initially you have to store
java programme java
programme 1.....
programme for reading 10 values for 10 variables using scanner class
2....declares all types of primitive data inside main method
java programme java
programme i have to write a java programe that calculates the average of 10 students in Test 1 ,Test 2 and Test 3....Values of the marks in all the test for a student should be hardcore.Ialso have to tell the maixmum
program not compilingprogram not compiling Hello can you help me with this program,I am trying to add a loop at the end of the program but it is not
compiling,thank you.
import java.util.*;
import java.text.*;
class HardwareItems
{
String code
menu driven programme menu driven
programme calculate the area of circle, square, rectangle in menu driven
programme in java
Compiling Error - Java BeginnersCompiling Error cant able to compile java servlet file in the command prompt? WHY?
but i can compile normal java file
give me answer to fix my problem
Compiling package in command lineCompiling package in command line Hi friends,
i am totally new to java programming, i am basic learner in java.
My query is, How to compile java... how to compile it.
Thanks & Regards,
Sham
Compiling Java
programme - Java Beginnersprogramme java
programme to implement stack operation?use stack to check whether a given string is polidrome or not Hi Friend,
Please visit the following link to get the stack implementation:
http
Compiling a Servlet - JSP-ServletCompiling a Servlet Respected sir,
I just want to know how to compile a servlet coding? I need it in a sequential way so that I can understand it at the very first time as I am new to this technology
Compiling Error - Java BeginnersCompiling Error cant able to compile java servlet file in the command prompt? WHY?
but i can compile normal java file
give me answer to fix my problem. Hi Friend,
Do you have servlet-api.jar in the lib folder
data and analytics graduate programmedata and analytics graduate programme Hi,
I am beginner in Data Science and machine learning field. I am searching for
the tutorials to learn:
data and analytics graduate
programme
Try to provide me good examples
JAVA programme - Java Interview QuestionsJAVA programme Perpare a class "package_example" following the basic functionality of "string" type in JAVA.Use of dynamic character arrays for such class is encouraged.Following is expected from the
programme:
a.Use of 3
error while compiling - Java Beginnerserror while compiling i am facing problem with
compiling and running a simple java program, can any one help me, the error i am getting is javac is not recognised as internal or external command Check if you JAVA_HOME
Error While Compiling - Java BeginnersError While Compiling Hi All
I Am a beginner and i face the following problem while
compiling
can anyone help me.
C:\javatutorial\example> javac HelloWorld.java
'javac' is not recognized as an internal or external
error in compiling j2me apllication - Appleterror in
compiling j2me apllication hi,
in my j2me application for video,m getting only the audio.i ll send the code.
package src.video_streaming;
import javax.microedition.media.Manager;
import
Compiling and Interpreting Applications in Java
following topics:
Compiling Java Program
Interpreting Java Program...
and then use the command prompt to run the example code.
Compiling Java ProgramADS_TO_REPLACE_1
For
compiling Java program, first your code must write the code using
Compiling and Running Java program from command lineCompiling and Running Java program from command line - Video tutorial... of
compiling and running java
program from command line. We have also video... to explain you the process of
compiling and running the Java program from command
i have got error while compiling simple tag handler i have got error while
compiling simple tag handler javac.servlet.jsp not found! tell me what are the jar files required to run simple tag handler class
The package you have used javac.servlet.jsp does not exist
Compiling Objective C Compiling Objective C
... program on windows and Max OS x machine.
Compiling Objective C
program is necessary as it generates the executable program that can run.
Compiling Objective C
Compiling and testing the application
Compiling and testing the application
In this application we will compile and deploy...
compile:
[javac]
Compiling 18 source files to C:\tomcat\apache
Compiling a Pattern with Multiple Flags
Compiling a Pattern with Multiple Flags
In this section you will learn how to compile a pattern... for
compiling pattern with multiple flags i.e. explained ahead.
Program Result:ADS
Compiling MXML files with FlexBuilder Compiling MXML files with FlexBuilder
... getting flex builder i know you are ready for learning the coding
and
compiling...;
For
compiling press F11 or click on Run ->
Run
DEVELOPING & DEPLOYING A PACKAGED EJB' is very important in Enterprise Java.
Compiling and Deploying such packaged servlets... the correct procedure, in
compiling and deploying. These have already been... in facility for package.
Marty Hall has provided a very nice note on
compiling