You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

57 lines
867 B

5 years ago
  1. ; fizzbuzz.asm
  2. ; Prints numbers 1 to 100, however if the number is a multiple of 3 it will print Fizz,
  3. ; and if the number is a multiple of 5 it will print Buzz. If the number is a multiple
  4. ; of both, it will print FizzBuzz
  5. ; Compile with "nasm -f elf64 fizzbuzz.asm && ld fizzbuzz.o -o fizzbuzz"
  6. %include 'macros.asm'
  7. .text:
  8. global _start
  9. _start:
  10. mov rcx,0 ; counter
  11. mov rsi,0 ; fizz check
  12. mov rdi,0 ; buzz check
  13. loop:
  14. inc rcx
  15. check_fizz:
  16. mov rdx,0
  17. mov rax,rcx
  18. mov rbx, 3
  19. div rbx
  20. mov rsi,rdx
  21. cmp rsi,0
  22. jne check_buzz
  23. printStr f
  24. check_buzz:
  25. mov rdx,0
  26. mov rax,rcx
  27. mov rbx, 5
  28. div rbx
  29. mov rdi,rdx
  30. cmp rdi,0
  31. jne check_int
  32. printStr b
  33. check_int:
  34. cmp rsi,0
  35. je cont
  36. cmp rdi,0
  37. je cont
  38. printInt rcx
  39. cont:
  40. printStr n
  41. cmp rcx,99
  42. jle loop
  43. exit 0
  44. .data:
  45. ; initialize doubleword msg variable
  46. f db 'Fizz',0x0
  47. b db 'Buzz',0x0
  48. n db 0xA,0x0