FizzBuzz en ensamblaje - falla de segmentación
Estoy tratando de escribir FizzBuzz en Assembly y veo fallas de segmentación todo el tiempo. Hasta ahora he determinado que no son mis rutinas de impresión (porque he eliminado su contenido y el problema persiste) y el error se esconde en algún lugar de la función principal.
Estaba obteniendo esta salida cuando ejecuto el programa:
fizzSegmentation fault
Llevándome a creer que no es el problema usar la división y buscar el resto. Pero podría estar equivocado, no he hecho la Asamblea en dos años ...
SECTION .data
global _start
fizz: db "fizz", 4
buzz: db "buzz", 4
SECTION .bss
counter: resb 1
SECTION .text
_start:
mov ax,0
mov [counter],ax
main_loop:
cmp ax,100 ;from 0 to 100
je exit ;
mov bl,3 ;divisor
mov ah,0 ;here will be a remainder
div bl ;divide
cmp ah,0 ;compare the remainder with 0
je print_fizz ;print fizz if they equal
mov bl,5 ;new divisor
mov ah,0 ;do I have to do it every time?
div bl ;divide
cmp ah,0 ;compare the remainder with 0
je print_buzz ;print buzz if they equal
jmp print_ax ;print contents of ax if not
inc ax ;increment ax
jmp main_loop ;jump to label
print_ax:
ret
print_fizz:
ret
print_buzz:
ret
exit:
mov rax,1
mov rbx,0
int 80h
ret
Estoy compilando usando:
yasm -f elf64 -o fizzbuzz.o fizzbuzz.asm
ld -d -o fizzbuzz fizzbuzz.o