常量入栈指令

常量入栈指令

aconst_null 将null对象引用压入栈
iconst_m1 将int类型常量-1压入栈
iconst_0 将int类型常量0压入栈
iconst_1 将int类型常量1压入栈
iconst_2 将int类型常量2压入栈
iconst_3 将int类型常量3压入栈
iconst_4 将int类型常量4压入栈
iconst_5 将int类型常量5压入栈
lconst_0 将long类型常量0压入栈
lconst_1 将long类型常量1压入栈
fconst_0 将float类型常量0压入栈
fconst_1 将float类型常量1压入栈
dconst_0 将double类型常量0压入栈
dconst_1 将double类型常量1压入栈
bipush 将一个8位带符号整数压入栈
sipush 将16位带符号整数压入栈
ldc 把常量池中的项压入栈
ldc_w 把常量池中的项压入栈(使用宽索引)
   ldc2_w 把常量池中long类型或者double类型的项压入栈(使用宽索引)

二 常量入栈常用指令集

xconst_n
范围
xconst_null
xconst_m1
xconst_0
xconst_1
xconst_2
xconst_3
xconst_4
xconst_5
iconst_n
[-1, 5]
iconst_m1
iconst_0
iconst_1
iconst_2
iconst_3
iconst_4
iconst_5
lconst_n
0, 1
lconst_0
lconst_1
fconst_n
0, 1, 2
fconst_0
fconst_1
fconst_2
dconst_n
0, 1
dconst_0
dconst_1
aconst_n
null、String literal、Class literal
aconst_null
bipush
一个字节,即 [-128, 127]
sipush
两个字节,即 [-32768, 32767]
ldc
四个字节,[-2^31, 2^31 - 1]
ldc_w
宽索引
ldc2_w
宽索引,long 或 double

三 常量入栈指令剖析

1 const 和 push 系列

2 ldc 系列

类型
常数指令
范围
int(boolean,byte,char,short)
iconst
[-1, 5]
bipush
[-128, 127]
sipush
[-32768, 32767]
ldc
any int value
long
lconst
0, 1
ldc
any long value
float
fconst
0, 1, 2
ldc
any float value
double
dconst
0, 1
ldc
any double value
reference
aconst
null
ldc
String literal, Class literal

四 实战

1 代码

// 2.常量入栈指令
public void pushConstLdc() {
    int i = -1;
    int a = 5;
    int b = 6;
    int c = 127;
    int d = 128;
    int e = 32767;
    int f = 32768;
}

public void constLdc() {
    long a1 = 1;
    long a2 = 2;
    float b1 = 2;
    float b2 = 3;
    double c1 = 1;
    double c2 = 2;
    Date d = null;
}

2 图解

 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值