无编辑摘要 |
无编辑摘要 |
||
第1行: | 第1行: | ||
指令语句结构 | 指令语句结构 | ||
自增运算++使值增加1 | |||
自减运算--使值减少1 | |||
案例1: | |||
a = 10 | |||
a++ | |||
等价 | |||
set a 10 | |||
op add a a 1 | |||
运行 | |||
a = 11 | |||
前缀:先加后算;后缀先算后加 | |||
前后差异案例前: | |||
a = 10 | |||
b = 2 * ++a | |||
等价 | |||
set a 10 | |||
op add a a 1 | |||
op mul b a 2 | |||
运行 | |||
b = 22 | |||
a = 11 | |||
前后差异案例后: | |||
a = 10 | |||
b = 2 * a++ | |||
等价 | |||
set a 10 | |||
op mul b a 2 | |||
op add a a 1 | |||
运行 | |||
b = 20 | |||
a = 11 | |||
自减运算同理 | |||
无符号右移位>>>高位始终补零正数情况与>>同理 | |||
案例1高性能有缺陷无法正常识别>>>0: | |||
a = -1 | |||
c = a >>> 1 | |||
等价 | |||
set a -1 | |||
op and a a 9223372036854775807 | |||
op shr c a 1 | |||
运行 | |||
c = 9223372036854775807 | |||
案例2低性能无缺陷正常识别>>>0: | |||
a = -1 | |||
b = 0 | |||
c = a >>> b | |||
等价 | |||
set a -1 | |||
set b 0 | |||
jump 4 lessThan b 1 | |||
op and a a 9223372036854775807 | |||
op shr c a b | |||
运行 | |||
c = -1 | |||
逻辑或||任何一个为真输出为真 | |||
案例1: | |||
a = 1 | |||
b = 0 | |||
a || b | |||
等价 | |||
set a 1 | |||
set b 0 | |||
op land c a a | |||
op land c b b | |||
运行 | |||
c = 1 | |||
逻辑非!反转输出 | |||
案例1: | |||
a = 1 | |||
c = !a | |||
等价 | |||
set a 1 | |||
op land a a a | |||
op mul c a -1 | |||
运行 | |||
c = 0 | |||
短路操作()&&()判定到false打断判定并输出false | |||
案例1: | |||
a = 5 | |||
b = (a<4)&&(a++<10) | |||
等价 | |||
set a 5 | |||
op lessThan c a 4 | |||
jump 跳出 equal c 0 | |||
op lessThan c a 10 | |||
op add a a 1 | |||
jump 跳出 equal a 0 | |||
跳出: | |||
end | |||
运行 | |||
a = 5 | |||
c = 0 | |||
三元运算?:基于条件布尔判定赋值对象 | |||
格式:variable x = (expression) ? value if true : value if false | |||
案例1: | |||
a = 10 | |||
b = (--a == 1) ? 20 : 30 | |||
等价 | |||
set a 10 | |||
op sub a a 1 | |||
jump true equal a 1 | |||
set b 30 | |||
jump 跳出 always 0 0 | |||
true: | |||
set b 20 | |||
跳出: | |||
end | |||
运行 | |||
a = 9 | |||
b = 30 | |||
while 循环 | |||
结构: | |||
while( 布尔表达式 ) { | |||
//循环内容 | |||
} | |||
案例1: | |||
a = 3 | |||
while( a>0 ) { | |||
a-- | |||
} | |||
等价 | |||
set a 3 | |||
jump 判定循环 always 0 0 | |||
进入循环: | |||
op sub a a 1 | |||
判定循环: | |||
jump 进入循环 greaterThan a 0 | |||
运行 | |||
a = 2 | |||
a = 1 | |||
a = 0 | |||
do…while 循环 | |||
结构: | |||
do { | |||
//代码语句 | |||
}while(布尔表达式) | |||
案例1: | |||
a = 0 | |||
do { | |||
a-- | |||
}while(a>0); | |||
等价 | |||
set a 0 | |||
进入循环: | |||
op sub a a 1 | |||
jump 进入循环 greaterThan a 0 | |||
运行 | |||
a = -1 |
2024年11月22日 (五) 20:34的最新版本
指令语句结构 自增运算++使值增加1 自减运算--使值减少1 案例1: a = 10 a++ 等价 set a 10 op add a a 1 运行 a = 11 前缀:先加后算;后缀先算后加 前后差异案例前: a = 10 b = 2 * ++a 等价 set a 10 op add a a 1 op mul b a 2 运行 b = 22 a = 11 前后差异案例后: a = 10 b = 2 * a++ 等价 set a 10 op mul b a 2 op add a a 1 运行 b = 20 a = 11 自减运算同理
无符号右移位>>>高位始终补零正数情况与>>同理
案例1高性能有缺陷无法正常识别>>>0:
a = -1
c = a >>> 1
等价
set a -1
op and a a 9223372036854775807
op shr c a 1
运行
c = 9223372036854775807
案例2低性能无缺陷正常识别>>>0:
a = -1
b = 0
c = a >>> b
等价
set a -1
set b 0
jump 4 lessThan b 1
op and a a 9223372036854775807
op shr c a b
运行
c = -1
逻辑或||任何一个为真输出为真
案例1:
a = 1
b = 0
a || b
等价
set a 1
set b 0
op land c a a
op land c b b
运行
c = 1
逻辑非!反转输出
案例1:
a = 1
c = !a
等价
set a 1
op land a a a
op mul c a -1
运行
c = 0
短路操作()&&()判定到false打断判定并输出false
案例1:
a = 5
b = (a<4)&&(a++<10)
等价
set a 5
op lessThan c a 4
jump 跳出 equal c 0
op lessThan c a 10
op add a a 1
jump 跳出 equal a 0
跳出:
end
运行
a = 5
c = 0
三元运算?:基于条件布尔判定赋值对象 格式:variable x = (expression) ? value if true : value if false 案例1: a = 10 b = (--a == 1) ? 20 : 30 等价 set a 10 op sub a a 1 jump true equal a 1 set b 30 jump 跳出 always 0 0 true: set b 20 跳出: end 运行 a = 9 b = 30
while 循环 结构: while( 布尔表达式 ) {
//循环内容
} 案例1: a = 3 while( a>0 ) {
a--
} 等价 set a 3 jump 判定循环 always 0 0 进入循环: op sub a a 1 判定循环: jump 进入循环 greaterThan a 0 运行 a = 2 a = 1 a = 0
do…while 循环 结构: do {
//代码语句
}while(布尔表达式) 案例1: a = 0 do {
a--
}while(a>0); 等价 set a 0 进入循环: op sub a a 1 jump 进入循环 greaterThan a 0 运行 a = -1