kvmtour.blogg.se

Buf resb 6
Buf resb 6









buf resb 6

With assembler macros, you could easily produce a fully-unrolled loop with LCM(fizz,buzz) outputs per loop (i.e. Storing the 16bit counter into memory is silly in the first place, but storing it to an address where you've only reserved one byte is asking for trouble.īesides the small stuff, FizzBuzz(3,5) is small enough to unroll and avoid some divs entirely. ( nasm itself does.) Setting up 64bit registers and then using the int 0x80 32bit compatibility ABI is even more silly.

buf resb 6

Mov rax, 1 is a waste of instruction bytes compared to mov eax, 1, and this is tagged yasm, which doesn't optimize that for you at assemble time. Put the the conditional branch at the bottom of the loop whenever possible. Using a 16bit counter is at least a waste of bytes (operand-size prefixes), and can cause slowdowns. (al/ah, bl/bh, cl/ch, dl/dh (no REX), and sil, dil. There's so many small ways this could be better, e.g. In case anyone's interested in a code-review of the attempted implementation, and a version with a lot of asm tricks: how to make a simple problem complicated.

buf resb 6

This answer ended up a lot longer than I was planning, kind of a tutorial on writing efficient asm. I am compiling using: yasm -f elf64 -o fizzbuzz.o fizzbuzz.asm But I could be wrong, I haven't done Assembly in two years. Leading me to believe that it's not the problem with using division and looking up the remainders. I was getting this output when I run the program: fizzSegmentation fault So far I have determined that it is not my printing routines (because I have removed their contents and the problem persists) and the error hides somewhere in the main function. I am trying to write FizzBuzz in Assembly and I am seeing segmentation fault all the time.











Buf resb 6