Latest Tutorials| Questions and Answers|Ask Questions?|Site Map



Home Answers Viewqa Java-Beginners compiling programme IJVM
Login         

View Questions and Answers by Category

Advertisements


 
Have Programming Question? Ask it here!
 
 
 


charles kaifiti
compiling programme IJVM
0 Answer(s)      3 years and 7 months ago
Posted in : Java Beginners


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


Advertisement
View Answers

Related Tutorials/Questions & Answers:
compiling programme IJVM
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
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
IJVM
IJVM  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
programme
programme  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 compiling
program 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 .class files
compiling .class files  how do i compile .class files using eclipse
Compiling Error - Java Beginners
Compiling 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 line
Compiling 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
hotel management programme in c language?
hotel management programme in c language?  hotel management programme in c language
Compiling a Servlet - JSP-Servlet
Compiling 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
programme - Java Beginners
programme  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 Error - Java Beginners
Compiling 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
process of compiling and running java program
process of compiling and running java program  Explain the process of compiling and running java program. Also Explain type casting
error while compiling - Java Beginners
error 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
JAVA programme - Java Interview Questions
JAVA 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 Beginners
Error 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 - Applet
error 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 a uploaed java file - JSP-Servlet
compiling a uploaed java file  How a uploaded java source file is automatically compiled(i.e converted to .class file) in server using jsp/servlet
Compiling and Interpreting Applications in Java
Welcome to Java tutorial series. In this lesson, you will learn about following topics: Compiling Java Program Interpreting Java Program Compiling Java Program For compiling Java program, first your code must write
Compiling and Running Java program from command line
Compiling and Running Java program from command line - Video tutorial... of compiling and running java program from command line. We have also video... the process of compiling and running the Java program from command prompt
How to add a file in GZIP file format in Java programme.
How to add a file in GZIP file format in Java programme.  Hi please help me. How to add a file GZIP File format in Java program. If example or suggest link for reference then it will be good. thanks,   Hi
making consistency of data member in the whole programme without using static keyword
making consistency of data member in the whole programme without using static keyword  In the below programme i use one boolean variable named check... . But the value of check variable is not maintained in the programme . we can
Advertisements
 

 

 

DMCA.com