汇编:建议的跳入和跳出标签的方式类似于C if语句

问题描述

我正在编写一个汇编循环以获取数组中的最大数目。像这样循环:

start_loop:

    # Get the current element in the array and move it to %rax
    # movz --> (1) b(yte-1),w(ord-2),l(long-4),q(uad-8)
    movzwq data_items(,%rdi,2),%rax

    # Check if the current element value is zero,if it is,jump to the end
    cmp $0,%rax
    jz exit

    # Increment the array index as we want to continue the loop at the end
    inc %rdi

    # Compare the current value (rax) to the current max (rbx)
    # WARNING: The `cmp` instruction is always backwards with ATT Syntax!
    # It reads as,"With respect to %rbx,the value of %rax is...(greater|less) than"
    # So to see if a > b,do:
    #   cmp b,a
    #   jg
    # Reference: https://stackoverflow.com/a/26191257/12283168
    cmp %rbx,%rax
    jge update_value

    jmp start_loop


update_value:
    mov %rax,%rbx
    jmp start_loop


exit:
    mov $1,%rax           
    int $0x80

我的问题是这里的比较代码的一部分:

    jge update_value
    jmp start_loop

update_value:
    mov %rax,%rbx
    jmp start_loop # <== can I get rid of this part?

是否有一种方法不必在update_value部分中指定jmp start_loop?例如,我可以使用高级语言:

while (1) {
    if (a > b)
        update_value();
    // continue
}

不必从update_value函数“跳回到while,我可以'继续'。是否可以在汇编中执行类似的操作,或者我是否对此进行了错误考虑?

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)