For us, the registers are familiar, and most of the x86 and arm directives we are familiar with. So based on what the stack is. In fact, based on the stack for some resource-scarce equipment (set-top box, embedded) more use. The JVM is based on the stack because the Java design idea is to run both on the server and in the embedded device (Java ME), because the stack based versatility is better so the JVM uses it. based on the nature of the stack
Based on stack essence, the Operation Stack is used to store the operands, which replaces the way the operands are placed in the instruction (based on registers).
The following quotes: a stack based virtual machine VS a register based virtual machine
For example, execute "a = B + C", and the bytecode instruction on the stack based virtual machine looks like this:
I1:load C
I2:load B
I3:add
I4:store A
Because the operands are all implicit, the instructions can be done very briefly, typically one or two bytes. But it is obvious that the number of instruction bars will increase significantly. And there is only one instruction to perform this operation on a register virtual machine:
I1:add A, B, c
Where a,b,c are virtual registers. The changes on the operand stack are shown in the following illustration:
First read the data from the symbol table on the stack of the operand,
The operand is then popped out of the stack to perform an addition operation, which is performed by the physical machine, as shown in the following figure:
comparison between the two codes
The following quote: Android Dalvik virtual Machine First
We can see from the screenshot below the comparison of Java bytecode and Dalvid bytecode corresponding to the same section of Java code.
Description
0x04 iconst_1 pushes int 1 to the top of the stack (Operation Stack)
0x05 iconst_2 pushes int 2 to the top of the stack
0x1a Iload_0 pushes the first int-type local variable (from a local variable table) to the top of the stack
0x1b Iload_1 pushes the second int local variable to the top of the stack