简体   繁体   English

汇编中的高级if语句

[英]High level if statement in Assembly

How to write a logical operator if statement in Assembly? 如何在Assembly中编写逻辑运算符if语句? For example in C we have the AND and OR logical functions, let's say: 例如在C中我们有AND和OR逻辑函数,比方说:

Written in C 用C写的

if((A >= B) && ( C < D)) {
   A = A+1;
   C = C*C;
 }else
C = C - 1;
A = C;

I don't know if it's correct but in assembly i translate it in this way: 我不知道它是否正确但是在汇编时我会用这种方式翻译它:

Translated in Assembly 在大会中翻译

if:   cmp RA,RB
      jl else
      cmp RC,RD
      jge else
      inc RA
      mul RC,RC
      jmp endif
else: dec RC
      mov RA,RC
endif:

I need your help, what if I have if((A >= B) || ( C < D))?, an OR function, which changes will be applied? 我需要你的帮助,如果我有if((A> = B)||(C <D))?, OR函数,将会应用哪些更改? I saw that assembly also has logical operators(AND, OR, XOR), is it possible to us them in this case? 我看到程序集也有逻辑运算符(AND,OR,XOR),在这种情况下我们可以使用它们吗? Could you describe an example of both cases? 你能描述两种情况的例子吗?

what if I have if((A >= B) || ( C < D)) 如果我有if((A >= B) || ( C < D))怎么办?

You can follow the same approach as your original code after applying De Morgan's law : 在应用De Morgan定律后,您可以采用与原始代码相同的方法:

if(!((A < B) && ( C >= D)))

I saw that assembly also has logical operators(AND, OR, XOR), is it possible to us them in this case? 我看到程序集也有逻辑运算符(AND,OR,XOR),在这种情况下我们可以使用它们吗?

In this case, you could. 在这种情况下,你可以。 However, it would no longer be equivalent to your C code, because || 但是,它将不再等同于您的C代码,因为|| and && operators use short-circuit evaluation . &&运营商使用短路评估

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM