如何解决汇编:建议的跳入和跳出标签的方式类似于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 举报,一经查实,本站将立刻删除。