Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Consider the stack-machine instructions (push y through pop to x) to compute x = y + (z*y)*z . Translate these instructions into JVM instructions. Presume

Consider the stack-machine instructions ("push y" through "pop to x") to compute x = y + (z*y)*z . Translate these instructions into JVM instructions. Presume that x, y, z are integer variables respectively stored at virtual addresses 0, 1, 2 in the variable area. Use instructions listed in the Selection of Basic JVM Instructions. Stack -machine instruction:

push y // read value of memory cell of y and push it onto the stack push z // read value of memory cell of z and push it onto the stack push y // read value of memory cell of y and push it onto the stack mul // pop top two values of the stack, multiply them, push the result onto the stack push z // read value of memory cell of z and push it onto the stack mul // pop top two values of the stack, multiply them, push the result onto the stack add // pop top two values of the stack, add them, push the result onto the stack pop to x // pop top value of the stack and store it in the memory cell of x

Selection of Basic JVM Instructions.

  • push value onto operand stack
    • iconst_k (0 k 5) : push int constant k onto stack
    • iload_k (0 k 3) : push value at address k in variable area onto stack
    • bipush k : push byte int constant k onto stack
    • iload k : push value at address k in variable area onto stack For long, float, double types, replace prefix "i" by "l", "f", "d", respectively (except for bipush).
  • pop from operand stack
    • istore_k (0 k 3) : pop stack and store into address k in variable area
    • istore k : pop stack and store into address k in variable area For long, float, double types, replace prefix "i" by "l", "f", "d", respectively.
  • arithmetic
    • iadd, isub, imul, idiv : pop top two values from stack, apply operator to stack[top-1] and stack[top], push result onto stack For long, float, double types, replace prefix "i" by "l", "f", "d", respectively.
  • conditional jump
    • if_icmpeq k : pop top two int values from stack; if stack[top1] = stack[top] then go to instruction at address k
    • if_icmpne k : pop top two int values from stack; if stack[top1] stack[top] then go to instruction at address k
    • if_icmplt k : pop top two int values from stack; if stack[top1] < stack[top] then go to instruction at address k
    • if_icmple k : pop top two int values from stack; if stack[top1] stack[top] then go to instruction at address k
    • if_icmpgt k : pop top two int values from stack; if stack[top1] > stack[top] then go to instruction at address k
    • if_icmpge k : pop top two int values from stack; if stack[top1] stack[top] then go to instruction at address k
  • unconditional jump
    • goto k : go to instruction at address k
  • function invocation
    • invokevirtual #k : invoke instance-level function numbered k
    • invokestatic #k : invoke static function numbered k
  • function return
    • return : exit from void-type function
    • ireturn : pop top int value from stack, push it onto caller's stack, and exit from function call For long, float, double types, replace prefix "i" by "l", "f", "d", respectively.
  • Instructions operating on references have the prefix "a", for example: aconst_null, aload, aload_k (0 k 3), astore, astore_k (0 k 3), areturn.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

More Books

Students also viewed these Databases questions

Question

Know how to use reservations systems to inventory demand.

Answered: 1 week ago

Question

What are the Five Phases of SDLC? Explain each briefly.

Answered: 1 week ago

Question

How can Change Control Procedures manage Project Creep?

Answered: 1 week ago