SlideShare ist ein Scribd-Unternehmen logo
1 von 3
; Ham giai phuong trinh bac 2
; a*x^2 + b*x + c = 0
; duoc goi trong C:
; int quadratic( double a, double b, double c,
; double * root1, double *root2 )
; Cac tham so:
; a, b, c – cac tham so cua phuong trinh bac 2 mot an so
; root1 – Con tro toi vi tri luu tru thu nhat
; root2 - Con tro toi vi tri luu tru thu nhat
; Gia tri tra ve:
; 1 neu phuong trin co nghiem, 0 neu phuong trinh vo nghiem

%define a qword [ebp+8]
%define b qword [ebp+16]
%define c qword [ebp+24]
%define root1 dword [ebp+32]
%define root2 dword [ebp+36]
%define disc qword [ebp-8]

%define one_over_2a qword [ebp-16]

segment .data
MinusFour dw -4

segment .text
global _quadratic
_quadratic:
push ebp
mov ebp, esp
sub esp, 16 ; allocate 2 doubles (disc & one_over_2a)
push ebx ; must save original ebx

fild word [MinusFour]                    ; Khoi tao gia tri -4 cho ngan xep
fld a                                    ; Ngan xep: a, -4
fld c                                    ; Ngan xep: c, a, -4
fmulp st1              ; Ngan xep: a*c, -4
fmulp st1              ; Ngan xep: -4*a*c
fld b                  ; Ngan xep: b, -4*a*c
fld b                  ; Ngan xep: b, b, -4*a*c
fmulp st1              ; Ngan xep: b*b, -4*a*c
faddp st1              ; Ngan xep: b*b - 4*a*c
ftst                   ; Kiem tra voi 0
fstsw ax
sahf
jb no_real_solutions   ; Neu < 0, Phuong trinh vo nghiem
fsqrt                  ; Ngan xep: sqrt(b*b - 4*a*c)
fstp disc              ; Lay ra cho bien disc
fld1                   ; Ngan xep: 1.0
fld a                  ; Ngan xep: a, 1.0
fscale                 ; Ngan xep: a * 2^(1.0) = 2*a, 1
fdivp st1              ; Ngan xep: 1/(2*a)
fst one_over_2a        ; Ngan xep: 1/(2*a)
fld b                  ; Ngan xep: b, 1/(2*a)
fld disc               ; Ngan xep: disc, b, 1/(2*a)
fsubrp st1             ; Ngan xep: disc - b, 1/(2*a)
fmulp st1              ; Ngan xep: (-b + disc)/(2*a)
mov ebx, root1
fstp qword [ebx]       ; Lay ra cho bien *root1
fld b                  ; Ngan xep: b
fld disc               ; Ngan xep: disc, b
fchs                   ; Ngan xep: -disc, b

fsubrp st1             ; Ngan xep: -disc - b
fmul one_over_2a       ; Ngan xep: (-b - disc)/(2*a)
mov ebx, root2
fstp qword [ebx]       ; Lay ra cho *root2
mov eax, 1             ; eax=1
jmp short quit         ;Tra ve gia tri 1 (xac dinh phuong trinh co nghiem)
no_real_solutions:   ;Nguoc lai,
mov eax, 0           ; tra ve gia tri 0 (phuong trinh vo nghiem)

quit:
pop ebx
mov esp, ebp
pop ebp
ret

Weitere ähnliche Inhalte

Was ist angesagt?

Po presentation to ddc
Po presentation to ddcPo presentation to ddc
Po presentation to ddcParbati Subba
 
กระบวนการวิจัย-การแจกแจงความถี่-การวัดเข้าสู่ส่วนกลาง
กระบวนการวิจัย-การแจกแจงความถี่-การวัดเข้าสู่ส่วนกลางกระบวนการวิจัย-การแจกแจงความถี่-การวัดเข้าสู่ส่วนกลาง
กระบวนการวิจัย-การแจกแจงความถี่-การวัดเข้าสู่ส่วนกลางCoverslide Bio
 
Trinity Kings Family Leadership: When your son Honors you by writing a letter...
Trinity Kings Family Leadership: When your son Honors you by writing a letter...Trinity Kings Family Leadership: When your son Honors you by writing a letter...
Trinity Kings Family Leadership: When your son Honors you by writing a letter...Terrell Patillo
 
Professional Certificate in Facilities Management
Professional Certificate in Facilities Management Professional Certificate in Facilities Management
Professional Certificate in Facilities Management Jedh Quenano
 
สรุปวิจัย อ.ทิพยา แผ่นที่ 7
สรุปวิจัย อ.ทิพยา แผ่นที่ 7สรุปวิจัย อ.ทิพยา แผ่นที่ 7
สรุปวิจัย อ.ทิพยา แผ่นที่ 7Coverslide Bio
 
KOG Profile Company
KOG Profile CompanyKOG Profile Company
KOG Profile Companyarmenaldrin
 
Kenza-solution
Kenza-solutionKenza-solution
Kenza-solutionPauline07
 
presenación de Almudena Sanchez Fúnez 4º de ESO cultura clásica IES Felipe Trigo
presenación de Almudena Sanchez Fúnez 4º de ESO cultura clásica IES Felipe Trigopresenación de Almudena Sanchez Fúnez 4º de ESO cultura clásica IES Felipe Trigo
presenación de Almudena Sanchez Fúnez 4º de ESO cultura clásica IES Felipe Trigoandres ignacio B
 
Colour book 1st edition final-low res
Colour book 1st edition final-low resColour book 1st edition final-low res
Colour book 1st edition final-low resDIPECHO Nepal
 

Was ist angesagt? (19)

Penghargaan Kemenkeu RI
Penghargaan Kemenkeu RIPenghargaan Kemenkeu RI
Penghargaan Kemenkeu RI
 
Skm
SkmSkm
Skm
 
Po presentation to ddc
Po presentation to ddcPo presentation to ddc
Po presentation to ddc
 
REPRODUCCION DE LAS CELULAS
REPRODUCCION DE LAS CELULASREPRODUCCION DE LAS CELULAS
REPRODUCCION DE LAS CELULAS
 
กระบวนการวิจัย-การแจกแจงความถี่-การวัดเข้าสู่ส่วนกลาง
กระบวนการวิจัย-การแจกแจงความถี่-การวัดเข้าสู่ส่วนกลางกระบวนการวิจัย-การแจกแจงความถี่-การวัดเข้าสู่ส่วนกลาง
กระบวนการวิจัย-การแจกแจงความถี่-การวัดเข้าสู่ส่วนกลาง
 
Trinity Kings Family Leadership: When your son Honors you by writing a letter...
Trinity Kings Family Leadership: When your son Honors you by writing a letter...Trinity Kings Family Leadership: When your son Honors you by writing a letter...
Trinity Kings Family Leadership: When your son Honors you by writing a letter...
 
IMG_0003
IMG_0003IMG_0003
IMG_0003
 
Professional Certificate in Facilities Management
Professional Certificate in Facilities Management Professional Certificate in Facilities Management
Professional Certificate in Facilities Management
 
3670
36703670
3670
 
Img 0002
Img 0002Img 0002
Img 0002
 
สรุปวิจัย อ.ทิพยา แผ่นที่ 7
สรุปวิจัย อ.ทิพยา แผ่นที่ 7สรุปวิจัย อ.ทิพยา แผ่นที่ 7
สรุปวิจัย อ.ทิพยา แผ่นที่ 7
 
KOG Profile Company
KOG Profile CompanyKOG Profile Company
KOG Profile Company
 
Img 0008
Img 0008Img 0008
Img 0008
 
Linda (4)
Linda (4)Linda (4)
Linda (4)
 
Kenza-solution
Kenza-solutionKenza-solution
Kenza-solution
 
Img 20160118 0015
Img 20160118 0015Img 20160118 0015
Img 20160118 0015
 
presenación de Almudena Sanchez Fúnez 4º de ESO cultura clásica IES Felipe Trigo
presenación de Almudena Sanchez Fúnez 4º de ESO cultura clásica IES Felipe Trigopresenación de Almudena Sanchez Fúnez 4º de ESO cultura clásica IES Felipe Trigo
presenación de Almudena Sanchez Fúnez 4º de ESO cultura clásica IES Felipe Trigo
 
Tugas nmr 2
Tugas nmr 2Tugas nmr 2
Tugas nmr 2
 
Colour book 1st edition final-low res
Colour book 1st edition final-low resColour book 1st edition final-low res
Colour book 1st edition final-low res
 

Mehr von Nguyen Chien

Evolutionary inaccuracy of pairwise structural alignments (slide)
Evolutionary inaccuracy of pairwise structural alignments (slide)Evolutionary inaccuracy of pairwise structural alignments (slide)
Evolutionary inaccuracy of pairwise structural alignments (slide)Nguyen Chien
 
Giao Trinh Vi Xu Ly (20 12 2008)
Giao Trinh Vi Xu Ly (20 12 2008)Giao Trinh Vi Xu Ly (20 12 2008)
Giao Trinh Vi Xu Ly (20 12 2008)Nguyen Chien
 
Vxl Dahl 2009 05 08
Vxl Dahl 2009 05 08Vxl Dahl 2009 05 08
Vxl Dahl 2009 05 08Nguyen Chien
 
Quy Che Quyet Dinh 14
Quy Che Quyet Dinh 14Quy Che Quyet Dinh 14
Quy Che Quyet Dinh 14Nguyen Chien
 
Discrete And Continuous Simulation
Discrete And Continuous SimulationDiscrete And Continuous Simulation
Discrete And Continuous SimulationNguyen Chien
 

Mehr von Nguyen Chien (9)

Evolutionary inaccuracy of pairwise structural alignments (slide)
Evolutionary inaccuracy of pairwise structural alignments (slide)Evolutionary inaccuracy of pairwise structural alignments (slide)
Evolutionary inaccuracy of pairwise structural alignments (slide)
 
P0126557 report
P0126557 reportP0126557 report
P0126557 report
 
P0126557 slides
P0126557 slidesP0126557 slides
P0126557 slides
 
Giao Trinh Vi Xu Ly (20 12 2008)
Giao Trinh Vi Xu Ly (20 12 2008)Giao Trinh Vi Xu Ly (20 12 2008)
Giao Trinh Vi Xu Ly (20 12 2008)
 
Vxl Dahl 2009 05 08
Vxl Dahl 2009 05 08Vxl Dahl 2009 05 08
Vxl Dahl 2009 05 08
 
Mips Assembly
Mips AssemblyMips Assembly
Mips Assembly
 
Risc
RiscRisc
Risc
 
Quy Che Quyet Dinh 14
Quy Che Quyet Dinh 14Quy Che Quyet Dinh 14
Quy Che Quyet Dinh 14
 
Discrete And Continuous Simulation
Discrete And Continuous SimulationDiscrete And Continuous Simulation
Discrete And Continuous Simulation
 

Ham Giai Phuong Trinh Bac 2

  • 1. ; Ham giai phuong trinh bac 2 ; a*x^2 + b*x + c = 0 ; duoc goi trong C: ; int quadratic( double a, double b, double c, ; double * root1, double *root2 ) ; Cac tham so: ; a, b, c – cac tham so cua phuong trinh bac 2 mot an so ; root1 – Con tro toi vi tri luu tru thu nhat ; root2 - Con tro toi vi tri luu tru thu nhat ; Gia tri tra ve: ; 1 neu phuong trin co nghiem, 0 neu phuong trinh vo nghiem %define a qword [ebp+8] %define b qword [ebp+16] %define c qword [ebp+24] %define root1 dword [ebp+32] %define root2 dword [ebp+36] %define disc qword [ebp-8] %define one_over_2a qword [ebp-16] segment .data MinusFour dw -4 segment .text global _quadratic _quadratic: push ebp mov ebp, esp sub esp, 16 ; allocate 2 doubles (disc & one_over_2a) push ebx ; must save original ebx fild word [MinusFour] ; Khoi tao gia tri -4 cho ngan xep fld a ; Ngan xep: a, -4 fld c ; Ngan xep: c, a, -4
  • 2. fmulp st1 ; Ngan xep: a*c, -4 fmulp st1 ; Ngan xep: -4*a*c fld b ; Ngan xep: b, -4*a*c fld b ; Ngan xep: b, b, -4*a*c fmulp st1 ; Ngan xep: b*b, -4*a*c faddp st1 ; Ngan xep: b*b - 4*a*c ftst ; Kiem tra voi 0 fstsw ax sahf jb no_real_solutions ; Neu < 0, Phuong trinh vo nghiem fsqrt ; Ngan xep: sqrt(b*b - 4*a*c) fstp disc ; Lay ra cho bien disc fld1 ; Ngan xep: 1.0 fld a ; Ngan xep: a, 1.0 fscale ; Ngan xep: a * 2^(1.0) = 2*a, 1 fdivp st1 ; Ngan xep: 1/(2*a) fst one_over_2a ; Ngan xep: 1/(2*a) fld b ; Ngan xep: b, 1/(2*a) fld disc ; Ngan xep: disc, b, 1/(2*a) fsubrp st1 ; Ngan xep: disc - b, 1/(2*a) fmulp st1 ; Ngan xep: (-b + disc)/(2*a) mov ebx, root1 fstp qword [ebx] ; Lay ra cho bien *root1 fld b ; Ngan xep: b fld disc ; Ngan xep: disc, b fchs ; Ngan xep: -disc, b fsubrp st1 ; Ngan xep: -disc - b fmul one_over_2a ; Ngan xep: (-b - disc)/(2*a) mov ebx, root2 fstp qword [ebx] ; Lay ra cho *root2 mov eax, 1 ; eax=1 jmp short quit ;Tra ve gia tri 1 (xac dinh phuong trinh co nghiem)
  • 3. no_real_solutions: ;Nguoc lai, mov eax, 0 ; tra ve gia tri 0 (phuong trinh vo nghiem) quit: pop ebx mov esp, ebp pop ebp ret