Guest User

Untitled

a guest
Jul 13th, 2023
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
ASM (NASM) 1.43 KB | Source Code | 0 0
  1. section .data
  2.     numerator       dd 10.0
  3.     denominator     dd 0.0
  4.     formatString    db "Result: %f", 0
  5.     nanMessage      db "Result is NaN", 0
  6.     infMessage      db "Result is Infinite", 0
  7.     newline         db 10, 0
  8.  
  9. section .bss
  10.     resultBuffer    resb 32
  11.  
  12. section .text
  13.     global Start
  14.    
  15.     extern printf
  16.     extern ExitProcess
  17.  
  18. Start:
  19.     ; Load the numerator into the FPU stack
  20.     fld dword [numerator]
  21.    
  22.     ; Load the denominator into the FPU stack
  23.     fld dword [denominator]
  24.    
  25.     ; Perform the division
  26.     fdivp
  27.    
  28.     ; Check if the result is NaN
  29.     fcomp
  30.     fnstsw ax
  31.     test ah, 0b01000000
  32.     jnz print_nan
  33.    
  34.     ; Check if the result is infinite
  35.     fcomp
  36.     fnstsw ax
  37.     test ah, 0b00100000
  38.     jnz print_inf
  39.    
  40.     ; Store the result from the FPU stack into the resultBuffer
  41.     sub esp, 8
  42.     fstp qword [resultBuffer]
  43.    
  44.     ; Call printf to print the result
  45.     push dword formatString
  46.     push dword resultBuffer
  47.     call printf
  48.    
  49.     ; Print a newline
  50.     push dword newline
  51.     call printf
  52.    
  53.     ; Exit the program
  54.     push 0
  55.     call ExitProcess
  56.  
  57. print_nan:
  58.     ; Print the NaN message
  59.     push dword nanMessage
  60.     call printf
  61.     jmp exit_program
  62.  
  63. print_inf:
  64.     ; Print the infinite message
  65.     push dword infMessage
  66.     call printf
  67.     jmp exit_program
  68.  
  69. exit_program:
  70.     ; Exit the program
  71.     push 0
  72.     call ExitProcess
  73.  
Tags: asm
Advertisement
Add Comment
Please, Sign In to add comment