跳跃后返回
Go back after jump
我有这个代码,我需要检查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(...){
...
}
我需要检查所有条件。
关于如何执行这个有一个误解。简单来说:
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
我更改了跳转到假可能性而不是真可能性的逻辑(就像你所做的那样),因为在没有“else”块的情况下,它使代码比你做的更小。
我有这个代码,我需要检查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(...){
...
}
我需要检查所有条件。
关于如何执行这个有一个误解。简单来说:
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
我更改了跳转到假可能性而不是真可能性的逻辑(就像你所做的那样),因为在没有“else”块的情况下,它使代码比你做的更小。