Question

In: Computer Science

Get the file “HW4Short.java”. Compile it and look at its bytecode. [TO DO:] Write a step-by-step...

Get the file “HW4Short.java”. Compile it and look at its bytecode. [TO DO:] Write a step-by-step description of the bytecode, imitating the style of my explanation in problem 1.

Explantionin promblem1:

0 iconst_0 push constant 0 onto the stack

1 istore_1 pop stack and store in location 1 (sum = 0)

2 iconst_0 push constant 0 onto the stack

3 istore_2 pop stack and store in location 2 (i = 0)

4 iload_2 push contents of location 2 onto stack (i)

5 bipush 10 push constant 10 onto stack

7 if_icmpge 20 pop two elements and compare with ">=" (if (i >= 10)) if test is true, go to line 20

10 iload_1 [test was false:] push sum onto stack

11 iload_2 push i onto stack

12 iadd pop two elements, add, push result onto stack 1

13 istore_1 pop stack and store in sum (sum = sum + i)

14 iinc 2 by 1 increment location 2 by 1 (i=i+1)

17 goto 4 go back to line 4 and repeat the loop

20 return

I am most interested in seeing how the bytecode demonstrates “short circuit evaluation” of the boolean “&&” operator, so be careful when explaining those parts. Place the bytecode, along with your step-by-step explanation, in a text document named q2.txt, including your name at the top. Use the following format:

0 bipush 10 push the constant 10 onto the stack

2 istore_1 pop the 10 and save it in i

3 bipush 20 push 20 onto the stack

5 istore_2 ... etc. ...

6 iconst_m1

7 istore_3 ...

etc. ...

// Needed for problem 2, lab 4
public class HW4Short {
public int f() {
int i = 10, j = 20, k = 0;
if (i > 10 && j == 20)
k = 100;
return k;
}
}

Solutions

Expert Solution

Solution:

Bytecode:It contain set of instruction to run your java code in JVM machine.When you compiled your java code ,compiler will generate the bytecode in the form .classfile.Using this bytecode file we can run our application in any machine.It will acts as platform indepent code.

Step-by-step bytecode of HW4Short class

//bytecode use stack push,pop operation to store the constant value

//push the constant value 10 to stack and store that it in the constant i

0 bipush 10 push the constant 10 onto the stack

2 istore_1 pop the 10 and save it in i

3 bipush 20 push the constant 20 onto the stack

5 istore_2 pop the 20 and save it in j

6 iconst_0 push the constant 0 onto the stack

7istore_3 pop the 0 and svae it in k

8 iload_1 loadthe content of location 1(i=1) on to the stack

9 bipush 10 push the constant 10 onto stack

11 if_icmple 12 compare the stack top element (i is greater than 10 if not jump to the label 12--here label 12 means end of the loop)

14 iload_2 load the content of the loaction 2(j=20) on to stack

15 bipush 20 push the constant 20 onto the stack

17 if_icmpne 6 compare the the top of the stack j and 20 value (if two value are not equal jump to the label 6 k=0,if true below instrucrion will exceute)

20 bipush 100 push the constant 100 onto the stack

22 istore_3 pop the 100 and save it in k

23 iload_3 load the content of the loaction 3 (K value)on to the stack

24 ireturn return k value

Note :

Short circuit ->is used to excute the loop operation very quickly to improve the performance .From given HW$Short It using && if first part of expression failed it will exit from the loop.It is imilar to the logical AND operation.If both expresssion true it will proceed the action in the loop.


Related Solutions

"You will need to compile each Java source file (provided below) separately, in its own file...
"You will need to compile each Java source file (provided below) separately, in its own file since they are public classes, to create a .class file for each, ideally keeping them all in the same directory." My class is asking me to do this and i am not understanding how to do it. I use JGRASP for all of my coding and i can't find a tutorial on how to do it. I just need a step by step tutorial...
Step by step in python please Write a program this will read a file (prompt for...
Step by step in python please Write a program this will read a file (prompt for name) containing a series of numbers (one number per line), where each number represents the radii of different circles. Have your program output a file (prompt for name) containing a table listing: the number of the circle (the order in the file) the radius of the circle the circumference the area of the circle the diameter of the circle Use different functions to calculate...
Can I get a Step by Step on how to do this problem Test the claim...
Can I get a Step by Step on how to do this problem Test the claim that the proportion of people who own cats is larger than 80% at the 0.005 significance level. The null and alternative hypothesis would be: H0:p≤0.8H0:p≤0.8 H1:p>0.8H1:p>0.8 H0:μ=0.8H0:μ=0.8 H1:μ≠0.8H1:μ≠0.8 H0:p≥0.8H0:p≥0.8 H1:p<0.8H1:p<0.8 H0:p=0.8H0:p=0.8 H1:p≠0.8H1:p≠0.8 H0:μ≥0.8H0:μ≥0.8 H1:μ<0.8H1:μ<0.8 H0:μ≤0.8H0:μ≤0.8 H1:μ>0.8H1:μ>0.8 The test is: right-tailed left-tailed two-tailed Based on a sample of 700 people, 82% owned cats The test statistic is:  (to 2 decimals) The p-value is:  (to 2 decimals) Based...
please do these 2 problem step by step and how how you get z core SAT...
please do these 2 problem step by step and how how you get z core SAT scores are normally distributed with a mean of 1,500 and a standard deviation of 300. An administrator at a college is interested in estimating the average SAT score of first-year students. If the administrator would like to limit the margin of error of the 86% confidence interval to 15 points, how many students should the administrator sample? Make sure to give a whole number...
Do the assignment in R/RStudio. Copy or compile your results into Word, write any explanations and...
Do the assignment in R/RStudio. Copy or compile your results into Word, write any explanations and turn in the hard copy. You conduct a survey of New Yorkers. The survey uses a stratified sample of 100 employed college graduates and 100 employed high school graduates. Your survey concludes that 70% of college graduates are happy with their job compared to only 60% of high school graduates. a. What is the standard error and margin of error of the estimate for...
Objectives To learn to code, compile, and run a program using file input and an output...
Objectives To learn to code, compile, and run a program using file input and an output file. Assignment Plan and code a program utilizing one file for input and one file for output to solve the following problem: Write a program to determine the highest number, the lowest number, their total, and the average of each line of numbers in a file. A file contains 7 numbers per line. How many lines a file contains is unknown. Note Label all...
Can you show how to do this step by step using Matlab please. Write a function...
Can you show how to do this step by step using Matlab please. Write a function with header [S] = myAddString(S1, S2), where S is the concatenation of the stings S1 and S2. Test Cases: S = myAddString(myAddString('Programming', ' '), myAddString(' is ', 'fun! ')) S = Programming is fun!
Need R codes to compile and plots , no hand written. Step-1: Type the data in...
Need R codes to compile and plots , no hand written. Step-1: Type the data in R Step-2: Perform Least-Squares regression Step-3: Make a normal Probability Plot using rstudent residuals Step-4: Plotting residuals versus predicted response yhat Step-5: Plotting Residuals versus each regressor. Step-6: Partial regression plots of residuals vs. regressors Step-7: Partial regression plots of residuals vs. regressors data:  (p.555 y, x1 and x5). y <- c(271.8, 264,238.8,230.7,251.6,257.9,263.9,266.5,229.1,239.3,258, 257.6,267.3,267,259.6,240.4,227.2,196,278.7,272.3,267.4,254.5,224.7, 181.5,227.5,253.6,263,265.8,263.8) x1 <- c(783.35, 748.45,684.45,827.8,860.45,875.15,909.45,905.55,756,769.35,793.5,801.65,819.65,808.55,774.95,711.85,694.85,638.1,774.55,757.9,753.35,704.7, 666.8,568.55,653.1,704.05,709.6,726.9,697.15) x5 <- c(13.2, 14.11,15.68,10.53,11,11.31,11.96,12.58,10.66,10.85,11.41,11.91,12.85,13.58,14.21,15.56,15.83,16.41,13.1,13.63,14.51,15.38, 16.1,16.73,10.58,11.28,11.91,12.65,14.06)
can i get a summery of heat cycle and a step by step on what it...
can i get a summery of heat cycle and a step by step on what it is or do please
Can you please provide a step by step instruction to get to the answer to the...
Can you please provide a step by step instruction to get to the answer to the following question WACC. Kose, Inc., has a target debt-equity ratio of .38. Its WACC is 10.1 percent and the tax rate is 25 percent. a) If the company’s cost of equity is 12 percent, what is its pretax cost of debt? b) If instead you know that the aftertax cost of debt is 6.4 percent, what is the cost of equity?
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT