asm编译器中的二进制表达式 [英] Binary expression in asm compiler

查看:116
本文介绍了asm编译器中的二进制表达式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试执行带有逻辑和符号&&的if语句。这是iam试图做的事情:asm字节码中的yy堆栈具有值0和1,并且我想用
的结果获得逻辑和,在我们的情况下,它不会进入if语句。

Iam trying to execute an if statement with logical and symbol '&&'. Here is what iam trying to do: Μy stack in asm byteocode has the values 0 and 1 and i want to get a result with the 'logical and' which in our case it doesn't get into the if statement.

我尝试了Opcodes.IFEQ和Opcodes.IFNE指令,但是没有用。同样带有'||'和'!'逻辑符号

I've tried Opcodes.IFEQ and Opcodes.IFNE instructions but the don't work.Same goes with '||' and '!' logical symbols

有什么想法吗?

感谢您的参与。

推荐答案

&& ||

$的字节码模式b
$ b

考虑一下像&& || 实际上确实如此。您有条件分支。让我们考虑& 。您正在有效评估的是:

Bytecode patterns for && and ||

Think about what a short-circuiting operator like && or || actually does. You've got some conditional branching. Let's consider &&. What you're effectively evaluating is:

if (left)
    if (right) <do something>
endIf

没有单个字节码指令可以描述此行为。您需要一些标签和条件分支指令:

There is no single bytecode instruction that can describe this behavior. You need need some labels and conditional branching instructions:

.start
    <left expression>
    IFEQ .endIf // if left evaluates to zero (false), skip to end
    <right expression>
    IFEQ .endIf // if right evaluates to zero (false), skip to end
.ifTrue
    <body of 'if' block>
.endIf

|| 运算符有点不同;在这种情况下,逻辑看起来像这样:

The behavior of the || operator is a bit different; in this case, the logic looks something like this:

    if (left)
        goto .ifTrue
    if (!right)
        goto .endIf
.ifTrue
    <do something>
.endIf

请注意如何反转右操作数的校验以避免额外的分支当右操作数的值为 true 时。可以使用以下字节码来实现此行为:

Note how the check on the right operand is inverted to avoid an additional branch when the right operand evaluates to true. This behavior could be implemented in bytecode like so:

    <left operand>
    IFNE .ifTrue  // if left evaluates true, skip right, enter 'if' body
    <right operand>
    IFEQ .endIf   // if right evaluates false, skip 'if' body
.ifTrue
    <do something>
.endIf






何时推动您的操作数



请注意,您最初的问题是您已经在堆栈中有了左右操作数。那将是不好的。对于&&<,您只应在右操作数 后评估左操作数 $ true (非零)。 / code>或 false (零)表示 ||| 。如果正确的操作数引起副作用,则过早评估它会违反这些运算符的定义行为。


When to push your operands

Note that your original question suggested you already have the left and right operands on the stack; that would be bad. You should only evaluate the right operand after the left operand has evaluated to true (nonzero) for && or false (zero) for ||. If the right operand causes side effects, evaluating it prematurely would violate the defined behavior of these operators.

这篇关于asm编译器中的二进制表达式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆