`cmp/test` 和 `js/jns/jz/jnz` 的示例

huangapple go评论107阅读模式
英文:

Examples of `cmp/test` and `js/jns/jz/jnz`

问题

Sure, here's the Chinese translation of your text:

有人可以展示一下cmp/testjs/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.

huangapple
  • 本文由 发表于 2023年6月12日 21:47:44
  • 转载请务必保留本文链接:https://go.coder-hub.com/76457312.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定