Advertisement
Guest User

Untitled

a guest
Apr 21st, 2017
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.10 KB | None | 0 0
  1. section .data
  2. msg1 db "Complex Root",10
  3. msglen1 equ $-msg1
  4. msg2 db "Root1: "
  5. msglen2 equ $-msg2
  6. msg3 db "Root2: "
  7. msglen3 equ $-msg3
  8. new: db "",0x0A
  9. new_len: equ $-new
  10. a dd 1.00
  11. b dd 8.00
  12. c dd 15.00
  13. four dd 4.00
  14. two dd 2.00
  15.  
  16. hdec dq 100
  17. point db "."
  18.  
  19. section .bss
  20.  
  21. root1 resd 1
  22. root2 resd 1
  23. resbuff rest 1
  24. temp resb 2
  25. disc resd 1
  26.  
  27. %macro write 2 ;macro for display
  28. mov rax,1
  29. mov rdi,1
  30. mov rsi,%1
  31. mov rdx,%2
  32. syscall
  33. %endmacro
  34.  
  35. %macro read 2 ;macro for input
  36. mov rax,0
  37. mov rdi,0
  38. mov rsi,%1
  39. mov rdx,%2
  40. syscall
  41. %endmacro
  42.  
  43. %macro exit 0 ;macro for exit
  44. mov rax,60
  45. xor rdi,rdi
  46. syscall
  47. %endmacro
  48.  
  49. section .text
  50. global _start
  51. _start:
  52.  
  53. finit ; initialise 80387 co-processor
  54. fld dword[b] ; stack: b
  55.  
  56.  
  57.  
  58. fmul dword[b] ; stack: b*b
  59.  
  60. fld dword[a] ; stack: a, b*b
  61.  
  62. fmul dword[c] ; stack: a*c, b*b
  63.  
  64. fmul dword[four] ; stack: 4*a*c,b*b
  65.  
  66. fsub ; stack: b*b - 4*a*c
  67.  
  68. ftst ; compares ST0 and 0
  69.  
  70.  
  71. fstsw ax ;Stores the coprocessor status word ;into either a word in memory or the AX register
  72. sahf ;Stores the AH register into the FLAGS register.
  73.  
  74. jb no_real_solutions ; if disc < 0, no real solutions
  75.  
  76. fsqrt ; stack: sqrt(b*b - 4*a*c)
  77.  
  78. fst dword[disc] ; store disc= sqrt(b*b - 4*a*c)
  79.  
  80. fsub dword[b] ; stack: disc-b
  81.  
  82. fdiv dword[a] ; stack: disc-b/2*a or (-b+disc)/2a
  83. fdiv dword[two]
  84.  
  85. write msg2,msglen2
  86. call disp_proc
  87. fldz ;stack:0
  88. fsub dword[disc] ;stack:-disc
  89. fsub dword[b] ; stack: -disc - b
  90. fdiv dword[a] ; stack: (-b - disc)/(2*a)
  91. fdiv dword[two]
  92.  
  93.  
  94. write msg3,msglen3
  95. call disp_proc
  96. jmp exi
  97.  
  98. no_real_solutions:
  99.  
  100. write msg1,msglen1
  101. exi :
  102.  
  103. mov rax,60
  104. mov rdi,1
  105. syscall
  106.  
  107.  
  108. disp_proc:
  109. FIMUL dword[hdec]
  110. FBSTP tword[resbuff]
  111. mov rsi,resbuff+9
  112. mov rcx,09
  113. next1:
  114.  
  115. push rcx
  116. push rsi
  117.  
  118. mov bl,[rsi]
  119. call disp
  120.  
  121. pop rsi
  122. pop rcx
  123.  
  124. dec rsi
  125. loop next1
  126. push rsi
  127. write point,1
  128. pop rsi
  129. mov bl,[rsi]
  130. call disp
  131. ret
  132.  
  133.  
  134. disp:
  135. mov edi,temp ;mov dnum address into edi
  136. mov ecx,02 ;initialize ecx with 2
  137. dispup1:
  138. rol bl,4 ;rotate bl by 4 bits
  139. mov dl,bl ;move bl into dl
  140. and dl,0fh ;and of dl with 0fh
  141. add dl,30h ;add 30h into dl
  142. cmp dl,39h ;compare dl with 39h
  143. jbe dispskip1 ;jump if below and equal to dispskip1
  144. add dl,07h ;add 7h into dl
  145. dispskip1:
  146. mov [edi],dl ;mov dl into dnum
  147. inc edi ;increament edi by a byte
  148. loop dispup1 ;loop dispup1 while ecx not zero
  149. write temp,2 ;Display dnum by calling macro
  150. ret ;return from procedure
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement