【发布时间】:2020-08-04 15:48:54
【问题描述】:
我有这个代码,我需要检查RCX 注册三遍。我做了几行代码(24-34行)。第一次(第一次jz),我移动到true:标签,但是第二次(28-30行)我不能回去检查它。我的程序每次都在第一个jz 之后完成。怎么回去查三遍?
default REL
extern GetStdHandle
extern WriteFile
extern ExitProcess
section .data
true_msg db 'Yes', 0
true_msg_len equ $-true_msg
section .text
global _main
_main:
and rsp, -10h
sub rsp, 020h
mov rcx, -0Bh
call GetStdHandle
;jmp true
mov rcx, 2
cmp rcx, 2
jz true
mov rcx, 0
cmp rcx, 0
jz true
mov rcx, 1
cmp rcx, 0
jz true
;----------------
add rsp, 28h ; Restore Stack Pointer
;----------------
mov rcx, 0 ; RCX - first argument.
call ExitProcess
;----------------
xor rax, rax
ret
true:
mov rcx, rax
mov rdx, true_msg
mov r8, true_msg_len
xor r9, r9
push r9
sub rsp, 20h
call WriteFile
我想得到类似的东西:
if(...){
...
}
if(...){
...
}
if(...){
...
}
我需要检查每个条件。
【问题讨论】:
-
为什么在每种情况下都跳到
true?是否总是应该执行相同的代码?如果是这样,为什么不写成if (cond1 || cond2 || cond3) { ... }呢? -
如果它 not 总是应该执行相同的代码,那么明显的解决方案是执行类似
jnz @F之类的操作,然后执行应该执行的代码 (或call指向包含该代码的函数)后跟@@:。如果您更喜欢命名标签而不是匿名标签,那很好。 -
@Michael:这看起来像 NASM 源。 NASM 没有内置
@@样式标签。(但是,my macro collection 可以添加对@@的支持,包括multi-step references。)
标签: if-statement assembly label x86-64 nasm