section .data
prompt db "Enter age: ", 0
eligible db "Eligible", 0
not_eligible db "Not Eligible", 0
section .bss
age resb 2 ; Reserve 2 bytes for the age input
section .text
global _start
_start:
; Print the prompt "Enter age: "
mov eax, 4 ; syscall number for sys_write
mov ebx, 1 ; file descriptor (stdout)
mov ecx, prompt ; address of prompt message
mov edx, 11 ; length of prompt
int 0x80 ; interrupt to invoke the syscall
; Read the user's input
mov eax, 3 ; syscall number for sys_read
mov ebx, 0 ; file descriptor (stdin)
mov ecx, age ; buffer to store input
mov edx, 2 ; read 2 bytes (including newline)
int 0x80 ; interrupt to invoke the syscall
; Convert ASCII to integer
movzx eax, byte [age] ; move age input to eax
sub eax, '0' ; convert ASCII character to integer
; Compare age with 18
cmp eax, 18
jl not_eligible_case ; jump if age is less than 18
eligible_case:
; Print "Eligible"
mov eax, 4
mov ebx, 1
mov ecx, eligible
mov edx, 8
int 0x80
jmp exit_program ; jump to exit
not_eligible_case:
; Print "Not Eligible"
mov eax, 4
mov ebx, 1
mov ecx, not_eligible
mov edx, 13
int 0x80
exit_program:
; Exit the program
mov eax, 1 ; syscall number for sys_exit
xor ebx, ebx ; exit status 0
int 0x80
c2VjdGlvbiAuZGF0YQogICAgcHJvbXB0IGRiICJFbnRlciBhZ2U6ICIsIDAKICAgIGVsaWdpYmxlIGRiICJFbGlnaWJsZSIsIDAKICAgIG5vdF9lbGlnaWJsZSBkYiAiTm90IEVsaWdpYmxlIiwgMAoKc2VjdGlvbiAuYnNzCiAgICBhZ2UgcmVzYiAyICAgICAgIDsgUmVzZXJ2ZSAyIGJ5dGVzIGZvciB0aGUgYWdlIGlucHV0CgpzZWN0aW9uIC50ZXh0CiAgICBnbG9iYWwgX3N0YXJ0Cgpfc3RhcnQ6CiAgICA7IFByaW50IHRoZSBwcm9tcHQgIkVudGVyIGFnZTogIgogICAgbW92IGVheCwgNCAgICAgICA7IHN5c2NhbGwgbnVtYmVyIGZvciBzeXNfd3JpdGUKICAgIG1vdiBlYngsIDEgICAgICAgO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