fork download
  1. section .data
  2. prompt db "Enter age: ", 0
  3. eligible db "Eligible", 0
  4. not_eligible db "Not Eligible", 0
  5.  
  6. section .bss
  7. age resb 2 ; Reserve 2 bytes for the age input
  8.  
  9. section .text
  10. global _start
  11.  
  12. _start:
  13. ; Print the prompt "Enter age: "
  14. mov eax, 4 ; syscall number for sys_write
  15. mov ebx, 1 ; file descriptor (stdout)
  16. mov ecx, prompt ; address of prompt message
  17. mov edx, 11 ; length of prompt
  18. int 0x80 ; interrupt to invoke the syscall
  19.  
  20. ; Read the user's input
  21. mov eax, 3 ; syscall number for sys_read
  22. mov ebx, 0 ; file descriptor (stdin)
  23. mov ecx, age ; buffer to store input
  24. mov edx, 2 ; read 2 bytes (including newline)
  25. int 0x80 ; interrupt to invoke the syscall
  26.  
  27. ; Convert ASCII to integer
  28. movzx eax, byte [age] ; move age input to eax
  29. sub eax, '0' ; convert ASCII character to integer
  30.  
  31. ; Compare age with 18
  32. cmp eax, 18
  33. jl not_eligible_case ; jump if age is less than 18
  34.  
  35. eligible_case:
  36. ; Print "Eligible"
  37. mov eax, 4
  38. mov ebx, 1
  39. mov ecx, eligible
  40. mov edx, 8
  41. int 0x80
  42. jmp exit_program ; jump to exit
  43.  
  44. not_eligible_case:
  45. ; Print "Not Eligible"
  46. mov eax, 4
  47. mov ebx, 1
  48. mov ecx, not_eligible
  49. mov edx, 13
  50. int 0x80
  51.  
  52. exit_program:
  53. ; Exit the program
  54. mov eax, 1 ; syscall number for sys_exit
  55. xor ebx, ebx ; exit status 0
  56. int 0x80
  57.  
Success #stdin #stdout 0s 5284KB
stdin
Standard input is empty
stdout
Enter age: Not Eligible