Q3

You might also like

Download as txt, pdf, or txt
Download as txt, pdf, or txt
You are on page 1of 2

global main

extern printf

SECTION .data
prompt db "Enter your age: ",0xa,0x0
printnum db "Your age is not divisible by 3 and 12",0x0
printfizz db " Your age is divisible by 3",0x0
printbuzz db " Your age is divisible by 12",0x0
endprint db 0xa,0x0
age dd age
flag db 0

SECTION .text

main:
push prompt
call printf
pop ebx
mov eax, 3
mov ebx, 1
mov ecx, age
mov edx, 40
int 0x80
push age
call fizz
call buzz
call print
call end

print:
mov eax, [flag]
cmp eax, 0
jne END_PRINTNUM
mov eax, [age]
push eax
push printnum
call printf
pop ebx
pop ebx
END_PRINTNUM:
ret

fizz:
mov edx, 0
mov eax, [age]
mov ebx, 3
div ebx
cmp edx, 0
jnz END_FIZZ
inc byte [flag]
push printfizz
call printf
pop ebx
END_FIZZ:
ret
buzz:
mov edx, 0
mov eax, [age]
mov ebx, 12
div ebx
cmp edx, 0
jnz END_BUZZ
inc byte [flag]
push printbuzz
call printf
pop ebx
END_BUZZ:
ret
end:
push endprint
call printf
mov eax, 1
int 0x80
ret

You might also like