If statement 跳跃后返回
我有这个代码,我需要检查RCX寄存器三次。我做了几行代码24-34行。在第一次使用第一个jz时,我转到true:label,但在第二次使用28-30行时,我无法返回并检查它。我的程序在第一次jz之后每次都会完成。我怎样才能回去检查三次呢If statement 跳跃后返回,if-statement,assembly,label,x86-64,nasm,If Statement,Assembly,Label,X86 64,Nasm,我有这个代码,我需要检查RCX寄存器三次。我做了几行代码24-34行。在第一次使用第一个jz时,我转到true:label,但在第二次使用28-30行时,我无法返回并检查它。我的程序在第一次jz之后每次都会完成。我怎样才能回去检查三次呢 default REL extern GetStdHandle extern WriteFile extern ExitProcess section .data true_msg db 'Yes', 0 true_msg_len equ
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(...){
...
}
我需要检查每一个条件。对如何执行这一点存在误解。简单地说:
if (test) {
//block1
}
if (test2) {
//block2
}
if(test3) {
//block3
}
请注意在我的下一个示例中,block1、block2和block3将出现在哪里
每个if都需要在括号中测试测试,然后执行可能为真的测试和可能为非真的测试。
所以应该是这样的:
;first if, start by comparing:
mov rcx, 2
cmp rcx, 2
jnz false1 ;jumps for the false possibility of the first if
;here you type what will happen when the first if is executed (block1)
false1: ;here the first if is finnished, this label is the jump for not executing that first if
;then now you execute the second if:
;first compare:
mov rcx, 0
cmp rcx, 0
jnz false2 ;jumps for not executing the if block
;here is block2
false2:
;now here the last if, just like the last two:
mov rcx, 1
cmp rcx, 0
jnz false3
;here block3
false3:
;here is the rest of your code after those ifs
我更改了跳入false-Probability的逻辑,而不是像您那样跳入true,因为在没有其他块的情况下,它会使代码比您所做的更小。对于如何执行这一点存在误解。简单地说:
if (test) {
//block1
}
if (test2) {
//block2
}
if(test3) {
//block3
}
请注意在我的下一个示例中,block1、block2和block3将出现在哪里
每个if都需要在括号中测试测试,然后执行可能为真的测试和可能为非真的测试。
所以应该是这样的:
;first if, start by comparing:
mov rcx, 2
cmp rcx, 2
jnz false1 ;jumps for the false possibility of the first if
;here you type what will happen when the first if is executed (block1)
false1: ;here the first if is finnished, this label is the jump for not executing that first if
;then now you execute the second if:
;first compare:
mov rcx, 0
cmp rcx, 0
jnz false2 ;jumps for not executing the if block
;here is block2
false2:
;now here the last if, just like the last two:
mov rcx, 1
cmp rcx, 0
jnz false3
;here block3
false3:
;here is the rest of your code after those ifs
我更改了跳转为false可能性的逻辑,而不是像您那样跳转为true的逻辑,因为在没有其他块的情况下,它会使代码比您的方式更小。为什么在每种情况下都跳转为true?应该执行的代码总是相同的吗?如果是这样的话,为什么不把它写成cond1 | | cond2 | | cond3{…}?如果应该执行的代码并不总是相同的,那么显而易见的解决方案是执行类似于jnz@F的操作,后跟应该执行的代码,或者调用包含该代码的函数,后跟@@:。如果你喜欢命名标签而不是匿名标签,那没关系。@Michael:这看起来像NASM源代码。NASM没有内置@样式标签。但是,可以添加对@的支持,包括。为什么在每种情况下都跳到true?应该执行的代码总是相同的吗?如果是这样的话,为什么不把它写成cond1 | | cond2 | | cond3{…}?如果应该执行的代码并不总是相同的,那么显而易见的解决方案是执行类似于jnz@F的操作,后跟应该执行的代码,或者调用包含该代码的函数,后跟@@:。如果你喜欢命名标签而不是匿名标签,那没关系。@Michael:这看起来像NASM源代码。NASM没有内置@样式标签。但是,可以添加对@的支持,包括。是的,当if块不应执行时,您通常希望跳过该块。为了保持与问题中的代码相同的条件,您应该在cmp、jne之后使用相反的条件jnz或更惯用的方式。i、 e.把最重要的东西翻过来;它变成了如果!在_stuff;之后测试转到;。所以if体在2==2时执行。没错,我忘了把jz转换成jnz,我用正确的jumpYes编辑了答案,当if块不应该执行时,你经常想跳过一个块。为了保持与问题中的代码相同的条件,您应该在cmp、jne之后使用相反的条件jnz或更惯用的方式。i、 e.把最重要的东西翻过来;它变成了如果!在_stuff;之后测试转到;。所以if体在2==2时执行。没错,我忘了把jz转换成jnz,我用正确的跳转编辑了答案