[英]difference between .IF and IF in assembly
what is the difference of .IF and IF directive in assembly? .IF 和 IF 指令在汇编中有什么区别? in document for .IF :在 .IF 文件中:
.IF condition1
statements
[[.ELSEIF condition2
statements]]
[[.ELSE
statements]]
.ENDIF
and for IF :对于 IF :
IF expression1
ifstatements
[[ELSEIF expression2
elseifstatements]]
[[ELSE
elsestatements]]
ENDIF
IF-ELSEIF-ELSE-ENDIF (without the dot) are compile-time directives. IF-ELSEIF-ELSE-ENDIF(不带点)是编译时指令。 The assembler will test the conditions, and based on the results, will only include one of the sequences of statements in the resulting program.汇编器将测试条件,并根据结果,将只包括结果程序中的语句序列之一。 They serve the same purpose as the C preprocessor directives #if
, #elif
, #else
, and #endif
.它们与 C 预处理器指令#if
、 #elif
、 #else
和#endif
用途相同。
.IF-.ELSEIF-.ELSE-.ENDIF (with the dot) are execution-time directives. .IF-.ELSEIF-.ELSE-.ENDIF(带点)是执行时指令。 The assembler will generate comparison and jumping instructions.汇编器会生成比较和跳转指令。 They serve the same purpose as C statements in the form if (...) { ... } else if (...) { ... } else { ... }
.它们的作用与形式为if (...) { ... } else if (...) { ... } else { ... }
C 语句相同。
Note: I'm not fluent in masm, so there might be errors in the notation of these examples.注意:我不精通 masm,因此这些示例的符号可能存在错误。
something EQU 1
somewhere:
mov ax, 42
IF something == 1
xor bx, 10
ELSE
mov bx, 20
ENDIF
add ax, bx
During the preprocessing phase of compilation, the compiler will test the conditions in IF
and ELSEIF
statements (without the dot), and select one of the blocks of code that will end up in the program.在编译的预处理阶段,编译器将测试IF
和ELSEIF
语句(不带点)中的条件,并选择将在程序中结束的代码块之一。 The above code is turned into the following:上面的代码变成了如下:
somewhere:
mov ax, 42
xor bx, 10
add ax, bx
Another example:另一个例子:
something EQU 1
somewhere:
mov ax, 42
mov dx, something
.IF dx == 1
xor bx, 10
.ELSE
mov bx, 20
.ENDIF
add ax, bx
During the preprocessing phase of compilation, the compiler will turn .IF
-statements (with the dot) into assembly instructions.在编译的预处理阶段,编译器会将.IF
语句(带点)转换为汇编指令。 The above code is probably turned into the following:上面的代码大概变成了下面这样:
something EQU 1
somewhere:
mov ax, 42
mov dx, 1
cmp dx, 1
jnz else_clause
xor bx, 10
jmp past_endif
else_clause:
mov bx, 20
past_endif:
add ax, bx
The conditions are actually checked at execution time.这些条件实际上是在执行时检查的。
Wrong "IF-ELSEIF-ELSE-ENDIF (without the dot) are compile-time directives. The assembler will test the conditions, and based on the results, will only include one of the sequences of statements in the resulting program. They serve the same purpose as the C preprocessor directives #if, #elif, #else, and #endif.错误的“IF-ELSEIF-ELSE-ENDIF(不带点)是编译时指令。汇编程序将测试条件,并根据结果,将只包括结果程序中的语句序列之一。它们服务于与 C 预处理器指令 #if、#elif、#else 和 #endif 的用途相同。
.IF-.ELSEIF-.ELSE-.ENDIF (with the dot) are execution-time directives. .IF-.ELSEIF-.ELSE-.ENDIF(带点)是执行时指令。 The assembler will generate comparison and jumping instructions.汇编器会生成比较和跳转指令。 They serve the same purpose as C statements in the form if (...) { ... } else if (...) { ... } else { ... }."它们与形式为 if (...) { ... } else if (...) { ... } else { ... } 的 C 语句的用途相同。”
True .if marks the beginning of a section of code which is only considered part of the source program being assembled if the argument (which must be an absolute expression) is non-zero. True .if 标记一段代码的开始,如果参数(必须是绝对表达式)非零,则该代码段仅被视为正在汇编的源程序的一部分。
reference: http://web.mit.edu/gnu/doc/html/as_toc.html#SEC65参考: http : //web.mit.edu/gnu/doc/html/as_toc.html#SEC65
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.