Question

In: Computer Science

Give the JAVA code for the following IJVM: ILOAD j ILOAD k IADD BIPUSH 3 I...

Give the JAVA code for the following IJVM:

ILOAD j

ILOAD k

IADD

BIPUSH 3

I CMPEQ L1

ILOAD j

BIPUSH 1

ISUB

ISTORE j

GOTO L2

L1: BIPUSH 0

ISTORE k

L2:

Solutions

Expert Solution

  • The given code simply storing two values in two variables
  • Two variables are added and stored
  • Then the sum is compared with the value 3, if the sum equals to 3 then the assigning k with 0, k=0
  • If not subtracting 1 from j, j=j-1

Given code:

ILOAD j

ILOAD k

IADD

BIPUSH 3

I CMPEQ L1

ILOAD j

BIPUSH 1

ISUB

ISTORE j

GOTO L2

L1: BIPUSH 0

ISTORE k

L2:

Note: The given code has some corrections to make it work properly, so here is the updated code (Result is same but verify the code once for any correction. It is for student best understanding)

Updated Code:

ILOAD j //push j onto the stack

ILOAD k //push k onto the stack

IADD //pop j and k then add both

ISTORE i //i=j+k, store in i

ILOAD i //push i onto the stack

BIPUSH 3 //push 3 onto the stack

I CMPEQ L1 //compare 3 with i, if equal goto L1

ILOAD j //if i not equal with 3, push j onto the stack

BIPUSH 1 //push 1 onto the stack

ISUB //subtract 1 from j

ISTORE j //store j=j-1 in j, then push j onto the stack

GOTO L2 //go to L2

L1: BIPUSH 0 //if -==3, then push 0 onto the stack

ISTORE k //store 0 in k, then push onto the stack

L2: //end of the else loop

==================

Java code:

i = j + k;

if( i == 3)

k = 0;

else

j = j-1;

==================

Code cheats:

ILOAD variable: push local variable onto the stack

IADD: pop top two elements from stack then add, push the sum onto the stack

ISTORE variable: pop top element from stack and store it in variable

BIPUSH num: push a byte number onto the stack

I CMPEQ: compares top two elements from the stack

I CMPEQ L1: compares top two elements from the stack, if equal goto L1 else proceed with next step

ISUB: pop top two elements from stack then subtract them, push the subtract onto the stack

GOTO L2: tells to go to particular step, here it is L2

============================================


Related Solutions

import java.util.*; class A { int i, j, k; public A(int i, int j, int k)...
import java.util.*; class A { int i, j, k; public A(int i, int j, int k) { this.i=i; this.j=j; this.k=k; } public String toString() { return "A("+i+","+j+","+k+")"; } } class Main { public static void main(String[] args) { ArrayList<A> aL=new ArrayList<A>(); Random rand= new Random(1000); //1000 is a seed value for (int p=0; p<10; p++) { int i = rand.nextInt(100); int j = rand.nextInt(200); int k = rand.nextInt(300); aL.add(new A(i, j, k)); } System.out.println("----- Original arraylist------"); for (A a: aL)...
Consider the group G = {1, −1, i, −i, j, −j, k, −k} under multiplication. Here...
Consider the group G = {1, −1, i, −i, j, −j, k, −k} under multiplication. Here i2= j2= k2= ijk = −1. determine which of the following sets is a subgroup of G. If a set is not a subgroup, give one reason why it is not. (a) {1, −1} (b) {i, −i, j, −j} (c) {1, −1, i, −i} (d) {1, i, −i, j}
3. Let S3 act on the set A={(i,j) : 1≤i,j≤3} by σ((i, j)) = (σ(i), σ(j))....
3. Let S3 act on the set A={(i,j) : 1≤i,j≤3} by σ((i, j)) = (σ(i), σ(j)). (a) Describe the orbits of this action. (b) Show this is a faithful action, i.e. that the permutation represen- tation φ:S3 →SA =S9 (c) For each σ ∈ S3, find the cycle decomposition of φ(σ) in S9.
Assume i = 4, j = 9, k = 5 and m = -3. What does...
Assume i = 4, j = 9, k = 5 and m = -3. What does each of the following statements print? a) printf("%d", i == 4); b) printf("%d", j!= 3); c) printf("%d", i >= 5 && j < 2); d) printf("%d", !m || k > m); e) printf("%d", !k && m); f) printf("%d", k - m < j || 5 - j >= k); g) printf("%d", j + m <= i && !0); h) printf("%d", !(j + m)); i)...
There exists a group G of order 8 having the following presentation: G=〈i,j,k | ij=k, jk=I,...
There exists a group G of order 8 having the following presentation: G=〈i,j,k | ij=k, jk=I, ki=j, i^2 =j^2 =k^2〉. Denotei2 bym. Showthat every element of G can be written in the form e, i, j, k, m, mi, mj, mk, and hence that these are precisely the distinct elements of G. Furthermore, write out the multiplication table for G (really, this should be going on while you do the first part of the problem).
Cards are: Black A, K, Q, J Red    A, K, Q, J A K Q J...
Cards are: Black A, K, Q, J Red    A, K, Q, J A K Q J A K Q J 1.) The probability of picking a numeric card if you pick two cards randomly 2.) The probability of Picking K and Q if you pick two cards randomly. It does not matter which color. However, K needs to be in your left and Q needs to be in your right hand. 3.) The probability of Picking K and Q if...
Cards are: Black A, K, Q, J Red    A, K, Q, J A K Q J...
Cards are: Black A, K, Q, J Red    A, K, Q, J A K Q J A K Q J 1.) The probability of picking a numeric card if you pick two cards randomly 2.) The probability of Picking K and Q if you pick two cards randomly. It does not matter which color. However, K needs to be in your left and Q needs to be in your right hand. 3.) The probability of Picking K and Q if...
Compile the following C code to MIPS assembly. a. Assume that i and j are stored...
Compile the following C code to MIPS assembly. a. Assume that i and j are stored in register $s1 and $s2, respectively. i = i – 2 + j; b. Assume base address of Array B and the variable i are stored in registers $s3 and $s1, respectively. B[1] = (B[0] x 4) - I; Explain each step in detail! my professor has the following answer: 1) addi $t0, $s1, -2 add $s1, $$t0, $s2 2) lw $t0, 0 ($s3)...
JAVA JAVA JAVA Hey i need to find a java code for my homework, this is...
JAVA JAVA JAVA Hey i need to find a java code for my homework, this is my first java homework so for you i don't think it will be hard for you. (basic stuff) the problem: Write a complete Java program The transport Company in which you are the engineer responsible of operations for the optimization of the autonomous transport of liquid bulk goods, got a design contract for an automated intelligent transport management system that are autonomous trucks which...
Create a new Java program named AllAboutMe (For JAVA we use blue J) Write code to...
Create a new Java program named AllAboutMe (For JAVA we use blue J) Write code to have the program print your name, favorite color, and three hobbies to a new text file called “AllAboutMe” using PrintStream. Submit code.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT