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 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

Ads









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
IJVM
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
compiling
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
hotel management programme in c language?
hotel management programme in c language?  hotel management programme in c language
compiling .class files
compiling .class files  how do i compile .class files using eclipse
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
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
data and analytics graduate programme
data 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
ModuleNotFoundError: No module named 'django-compiling-loader'
ModuleNotFoundError: No module named 'django-compiling-loader'  Hi...: No module named 'django-compiling-loader' How to remove the ModuleNotFoundError: No module named 'django-compiling-loader' error? Thanks   
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
Placement Programme
Java programme
c programme
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 Program For compiling Java program, first your code must write the code using text editor
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
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
please solve the programme
Problem on JAVA Programme
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 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
Compiling MXML files with FlexBuilder
Compiling MXML files with FlexBuilder  ... i know you are ready for learning the coding and compiling process of flex...:Application>   For compiling press F11

Ads