fork download
  1. section .data
  2. positive_msg db "Positive!", 10, 0 ; Message for positive number, newline, null-terminated
  3. negative_msg db "Not positive!", 10, 0 ; Message for negative number, newline, null-terminated
  4.  
  5. section .text
  6. global _start
  7.  
  8. _start:
  9. ; Example: Check if the number -5 is positive
  10. mov rax, -5 ; Load the number to check into rax
  11.  
  12. cmp rax, 0 ; Compare rax with 0
  13. jg positive_case ; Jump to positive_case if rax is greater than 0 (positive)
  14.  
  15. ; Negative or zero case
  16. ; Print "Not positive!"
  17. mov rax, 1 ; System call number for write
  18. mov rdi, 1 ; File descriptor 1 (stdout)
  19. mov rsi, negative_msg ; Address of the negative message
  20. mov rdx, 14 ; Length of the negative message (including newline and null)
  21. syscall
  22. jmp exit
  23.  
  24. positive_case:
  25. ; Print "Positive!"
  26. mov rax, 1 ; System call number for write
  27. mov rdi, 1 ; File descriptor 1 (stdout)
  28. mov rsi, positive_msg ; Address of the positive message
  29. mov rdx, 10 ; Length of the positive message (including newline and null)
  30. syscall
  31.  
  32. ; Exit the program
  33. mov rax, 60 ; System call number for exit
  34. xor rdi, rdi ; Exit code 0
  35. syscall
  36.  
Success #stdin #stdout 0s 5276KB
stdin
Standard input is empty
stdout
Not positive!