Im trying to make fizzbuzz in assembly x86 64 but i dont know how to make a loop that has conditional statements
I thought i would check for a condition and then jump to that procedure and then ret back. The problem is that if I return the label I will get a segfault for some reason.
The problem in the current code is that the fizzCondition will always execute
mov ax, 6 mov bl, 3 div bl cmp ah, 0 je fizzCondition ;check buzz condition etc.. fizzCondition: mov eax, SYSWRITE mov edi, 1 mov esi, fizz mov edx, 5 syscall exit if I do it like this I will get a segfault:
mov ax, 6 mov bl, 3 div bl cmp ah, 0 je fizzCondition exit fizzCondition: mov eax, SYSWRITE mov edi, 1 mov esi, fizz mov edx, 5 syscall ret
retfrom something youcall. Either just jump back instead ofretor put acallin the conditional, for example by reversing the condition:jne notFizzCondition; call fizzCondition; notFizzCondition: ...divevery iteration. My answer there has a semi-optimized FizzBuzz, storing strings into a buffer for fewer write syscalls. (The major factor in performance, much bigger than avoidingdiv.)