Is there any possibility to use RET function to go back from the conditional statement to the main function (_start) where it was called from and go on with the next instructions? Right now, it's just causing a segmentation fault beacuse it is not setted in the stack.
If not, what is the best approach to perform if jumps in asm? Am i supposed to write jmp _cont at the end of the if statement instead of ret and then go on with the instructions in _cont?
section .data
a dq 222
b dq 333
section .text
global _start
_start:
mov rax, [a]
mov rbx, [a]
cmp rax, rbx
je ifstatement1
//desired return point
mov rax, [b]
call _printInt
mov eax, 60
xor edi, edi
syscall
ifstatement1:
mov rax, [a]
call _printInt
ret
retonly works if you usedcall. Sincejeis a jump, there is no address to return to. Yes, you should usejmpto go to wherever you want to continue execution. If you want to conditionally call a function, you should reverse the condition to skip over acall._startis special; isn't a function — the operating system doesn't call it, instead it sets the pc there and runs that code. The usual_startdoes callmainas a real function, so that one can do what you're showing here.retinifstatement1going back to thedesired return point. It would not work inmaineither.call _printInt, from a function likemainthey could do a conditional tailcall to_printInt, likeje _printInt/ set up RAX a different way /jmp _printInt.ifstatement1:only has one "caller", so you could just usejmp desired_return_pointto a label you placed there, instead ofret. Otherwise you'd need to make a conditional call (e.g. by branching past acallinstruction), or inline the (tiny in this case) amount of code at each call-site so there isn't a function, just a block that you jump over or that you jump to and it jumps back to a hard-coded location.