Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- section .data
- numerator dd 10.0
- denominator dd 0.0
- formatString db "Result: %f", 0
- nanMessage db "Result is NaN", 0
- infMessage db "Result is Infinite", 0
- newline db 10, 0
- section .bss
- resultBuffer resb 32
- section .text
- global Start
- extern printf
- extern ExitProcess
- Start:
- ; Load the numerator into the FPU stack
- fld dword [numerator]
- ; Load the denominator into the FPU stack
- fld dword [denominator]
- ; Perform the division
- fdivp
- ; Check if the result is NaN
- fcomp
- fnstsw ax
- test ah, 0b01000000
- jnz print_nan
- ; Check if the result is infinite
- fcomp
- fnstsw ax
- test ah, 0b00100000
- jnz print_inf
- ; Store the result from the FPU stack into the resultBuffer
- sub esp, 8
- fstp qword [resultBuffer]
- ; Call printf to print the result
- push dword formatString
- push dword resultBuffer
- call printf
- ; Print a newline
- push dword newline
- call printf
- ; Exit the program
- push 0
- call ExitProcess
- print_nan:
- ; Print the NaN message
- push dword nanMessage
- call printf
- jmp exit_program
- print_inf:
- ; Print the infinite message
- push dword infMessage
- call printf
- jmp exit_program
- exit_program:
- ; Exit the program
- push 0
- call ExitProcess
Advertisement
Add Comment
Please, Sign In to add comment