Bisection method in Assembly using irvine 32 / 64
TITLE MASM Template(main.asm)
; Description:
;
; Revision date :
INCLUDE Irvine32.inc
.data
myMessage1 BYTE "Enter the first number: ", 0dh, 0ah, 0
myMessage2 BYTE "Enter the second number: ", 0dh, 0ah, 0
Showmid BYTE "The mid of input is: ", 0dh, 0ah, 0
inputNum1 DWORD ?
inputNum2 DWORD ?
two Sdword 2
mid SDword ?
ab real4 ?
abs real4 ?
val real4 0.001
f0 real4 ?
f1 real4 ?
f2 real4 ?
msgIntro byte "The bisection method in mathematics is a root-finding method that repeatedly bisects", 0dh, 0ah
byte "an interval and then selects a subinterval in which a root must lie for further processing.", 0dh, 0ah
byte " It is a very simple and robust method, but it is also relatively slow", 0dh, 0ah
byte "---------------------------------------------------------------------------------.", 0dh, 0ah, 0
first byte "---------------------------------------------------------------------------------.", 0dh, 0ah
byte"the f(x0) is found to be : ", 0dh, 0ah, 0
Second byte "---------------------------------------------------------------------------------.", 0dh, 0ah
byte"the f(x1) is found to be : ", 0dh, 0ah, 0
alter byte "---------------------------------------------------------------------------------.", 0dh, 0ah
byte" the f(x2) mid point is found to be ", 0dh, 0ah, 0
tree byte "---------------------------------------------------------------------------------.", 0dh, 0ah
byte" Now the value of x0 is greater then 0 ", 0dh, 0ah, 0
third byte "---------------------------------------------------------------------------------.", 0dh, 0ah
byte"after 2nd alteration the root is", 0dh, 0ah, 0
forth byte "---------------------------------------------------------------------------------.", 0dh, 0ah
byte"after 3nd alteration the root is", 0dh, 0ah, 0
.code
main PROC
call Clrscr
mov edx, offset msgIntro
call WriteString
mov edx, offset myMessage1
call WriteString
call ReadInt; Reads the integer value from console and moves it to eax.
mov inputNum1, eax; Input value is taken in eax.
mov edx, offset myMessage2
call WriteString
call ReadInt; Reads the integer value from console and move
mov inputNum2, eax; Input value is taken in ebx.
mov eax, inputNum1
add eax, inputnum2
cdq
idiv two
mov mid, eax
mov edx, offset showmid
call WriteString
call WriteInt
call crlf
.if (eax<0)
neg ebx
mov abs,ebx
.endif
mov eax,0
mov eax,inputnum1
call function
mov edx, offset first
call WriteString
call WriteInt
call crlf
mov f0, eax
mov eax, 0
mov eax, inputnum2
call function
mov edx, offset Second
call WriteString
call WriteInt
call crlf
mov f1, eax
mov eax,0
mov eax, inputNum1
add eax, inputnum2
cdq
idiv two
mov edx, offset alter
call WriteString
call WriteInt
call crlf
mov mid, eax
mov eax,mid
call function
mov edx, offset third
call WriteString
call WriteInt
call crlf
mov f2,eax
.if (eax<0)
neg eax
mov abs,eax
.endif
mov eax, mid
call function
mov edx, offset forth
call WriteString
call WriteInt
call crlf
mov f2, ebx
.if (ebx<0)
neg ebx
mov ab, ebx
.endif
mov ebx, 0
mov ebx, f0
imul ebx, f1
.if (ebx<0)
mov eax, mid
mov inputnum2, eax
.else
mov eax, mid
mov inputnum1, eax
.endif
function proc
mov ebx, 0
mov ecx, 0
mov ebx, eax
imul ebx
mov ecx, eax
imul ebx
add eax, ebx
add eax, ecx
add eax, 7
ret
function endp
exit
main ENDP
END main
; Description:
;
; Revision date :
INCLUDE Irvine32.inc
.data
myMessage1 BYTE "Enter the first number: ", 0dh, 0ah, 0
myMessage2 BYTE "Enter the second number: ", 0dh, 0ah, 0
Showmid BYTE "The mid of input is: ", 0dh, 0ah, 0
inputNum1 DWORD ?
inputNum2 DWORD ?
two Sdword 2
mid SDword ?
ab real4 ?
abs real4 ?
val real4 0.001
f0 real4 ?
f1 real4 ?
f2 real4 ?
msgIntro byte "The bisection method in mathematics is a root-finding method that repeatedly bisects", 0dh, 0ah
byte "an interval and then selects a subinterval in which a root must lie for further processing.", 0dh, 0ah
byte " It is a very simple and robust method, but it is also relatively slow", 0dh, 0ah
byte "---------------------------------------------------------------------------------.", 0dh, 0ah, 0
first byte "---------------------------------------------------------------------------------.", 0dh, 0ah
byte"the f(x0) is found to be : ", 0dh, 0ah, 0
Second byte "---------------------------------------------------------------------------------.", 0dh, 0ah
byte"the f(x1) is found to be : ", 0dh, 0ah, 0
alter byte "---------------------------------------------------------------------------------.", 0dh, 0ah
byte" the f(x2) mid point is found to be ", 0dh, 0ah, 0
tree byte "---------------------------------------------------------------------------------.", 0dh, 0ah
byte" Now the value of x0 is greater then 0 ", 0dh, 0ah, 0
third byte "---------------------------------------------------------------------------------.", 0dh, 0ah
byte"after 2nd alteration the root is", 0dh, 0ah, 0
forth byte "---------------------------------------------------------------------------------.", 0dh, 0ah
byte"after 3nd alteration the root is", 0dh, 0ah, 0
.code
main PROC
call Clrscr
mov edx, offset msgIntro
call WriteString
mov edx, offset myMessage1
call WriteString
call ReadInt; Reads the integer value from console and moves it to eax.
mov inputNum1, eax; Input value is taken in eax.
mov edx, offset myMessage2
call WriteString
call ReadInt; Reads the integer value from console and move
mov inputNum2, eax; Input value is taken in ebx.
mov eax, inputNum1
add eax, inputnum2
cdq
idiv two
mov mid, eax
mov edx, offset showmid
call WriteString
call WriteInt
call crlf
.if (eax<0)
neg ebx
mov abs,ebx
.endif
mov eax,0
mov eax,inputnum1
call function
mov edx, offset first
call WriteString
call WriteInt
call crlf
mov f0, eax
mov eax, 0
mov eax, inputnum2
call function
mov edx, offset Second
call WriteString
call WriteInt
call crlf
mov f1, eax
mov eax,0
mov eax, inputNum1
add eax, inputnum2
cdq
idiv two
mov edx, offset alter
call WriteString
call WriteInt
call crlf
mov mid, eax
mov eax,mid
call function
mov edx, offset third
call WriteString
call WriteInt
call crlf
mov f2,eax
.if (eax<0)
neg eax
mov abs,eax
.endif
mov eax, mid
call function
mov edx, offset forth
call WriteString
call WriteInt
call crlf
mov f2, ebx
.if (ebx<0)
neg ebx
mov ab, ebx
.endif
mov ebx, 0
mov ebx, f0
imul ebx, f1
.if (ebx<0)
mov eax, mid
mov inputnum2, eax
.else
mov eax, mid
mov inputnum1, eax
.endif
function proc
mov ebx, 0
mov ecx, 0
mov ebx, eax
imul ebx
mov ecx, eax
imul ebx
add eax, ebx
add eax, ecx
add eax, 7
ret
function endp
exit
main ENDP
END main
Comments
Post a Comment