英文:
Examples of `cmp/test` and `js/jns/jz/jnz`
问题
Sure, here's the Chinese translation of your text:
有人可以展示一下cmp
/test
与js
/jns
/jz
/jnz
等的C语言表示吗?
谢谢。
英文:
Can someone show a C-like representation of the uses of cmp
/test
alongside js
/jns
/jz
/jnz
/etc.?
Thanks.
答案1
得分: 1
以下是一些示例代码以及它们可能转化为的内容(clang输出):
test_with_self:
test edi, edi
jne .LBB0_2
ret
.LBB0_2:
push rax
call abort@PLT
test_with_mask:
test esi, edi
jne .LBB1_2
ret
.LBB1_2:
push rax
call abort@PLT
test_js:
test edi, edi
js .LBB2_2
ret
.LBB2_2:
push rax
call abort@PLT
test_jns:
test edi, edi
jns .LBB3_2
ret
.LBB3_2:
push rax
call abort@PLT
cmp_jz:
cmp edi, 42
je .LBB4_2
ret
.LBB4_2:
push rax
call abort@PLT
cmp_jnz:
cmp edi, 42
jne .LBB5_2
ret
.LBB5_2:
push rax
call abort@PLT
请注意,je
等于 jz
,而 jne
等于 jnz
。
英文:
Here are some examples:
#include <stdlib.h>
void test_with_self(int A){
if (A) abort();
}
void test_with_mask(int A, int Mask){
if (A&Mask) abort();
}
void test_js(int A){
if (A<0) abort();
}
void test_jns(int A){
if (A>=0) abort();
}
void cmp_jz(int A){
if (A==42) abort();
}
void cmp_jnz(int A){
if (A!=42) abort();
}
and what they could be rendered as (clang output):
test_with_self: # @test_with_self
test edi, edi
jne .LBB0_2
ret
.LBB0_2:
push rax
call abort@PLT
test_with_mask: # @test_with_mask
test esi, edi
jne .LBB1_2
ret
.LBB1_2:
push rax
call abort@PLT
test_js: # @test_js
test edi, edi
js .LBB2_2
ret
.LBB2_2:
push rax
call abort@PLT
test_jns: # @test_jns
test edi, edi
jns .LBB3_2
ret
.LBB3_2:
push rax
call abort@PLT
cmp_jz: # @cmp_jz
cmp edi, 42
je .LBB4_2
ret
.LBB4_2:
push rax
call abort@PLT
cmp_jnz: # @cmp_jnz
cmp edi, 42
jne .LBB5_2
ret
.LBB5_2:
push rax
call abort@PLT
Note that je
== jz
and jne
== jnz
.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论