I think I am using the loop incorrectly somehow in the assembler.
Task text:
Calculate 5 values of the function Yn = 7x^3 /(2x^2 + 1.6) (x varies
from 1 with step 4).
Here is the execution of my program picture 1:
Here is my program code:
;2 вариант Вычислить 5 значений функции Yn = 7x 3 /(2x 2 + 1,6) (x изменяется от 1 с шагом 4).
.686
.Model flat, stdcall
option casemap: none
include D:\masm32\include\windows.inc
include D:\masm32\include\kernel32.inc
include D:\masm32\include\fpu.inc
include D:\masm32\include\msvcrt.inc
include D:\masm32\include\user32.inc
includelib D:\masm32\lib\user32.lib
includelib D:\masm32\lib\kernel32.lib
includelib D:\masm32\lib\msvcrt.lib
includelib D:\masm32\lib\fpu.lib
; Yn = 7x^3 /(2x^2 + 1,6)
.data
CrLf equ 0A0Dh
_y1 dt 0.0
_y2 dt 0.0
_y3 dt 0.0
_y4 dt 0.0
_y5 dt 0.0
x DWORD 1.0
seven DWORD 7.0
two DWORD 2.0
num DWORD 1.6
_zero DWORD 0.0
step DWORD 4.0
info db "Гринёв Илья ВТИПО-21-2 (2 вариант)",10,10,
"Yn = 7x^3 /(2x^2 + 1,6) (x изменяется от 1 с шагом 4).",10,10,
"y1 = "
_res1 db 14 DUP(0),10,13
db "y2 = "
_res2 db 14 DUP(0),10,13
db "y3 = "
_res3 db 14 DUP(0),10,13
db "y4 = "
_res4 db 14 DUP(0),10,13
db "y5 = "
_res5 db 15 DUP(0),10,13
ttl db "Обработка чисел на сопроцессоре в цикле",0
.code
_start:
finit
mov ecx, 6
m1:
fld x
;(7*x^3)
fmul x
fmul x ; x^3
fmul seven
fld x
;(2x^2 + 1,6)
fmul x ; x^2
fmul two ; 2*x^2
fadd num
FDIVP st(1),st
fld x
fadd step
fstp x
loop m1
fstp _y5
fstp _y4
fstp _y3
fstp _y2
fstp _y1
invoke FpuFLtoA,offset _y1,10,offset _res1,SRC1_REAL or SRC2_DIMM
mov word ptr _res1 + 14, CrLf
invoke FpuFLtoA,offset _y2,10,offset _res2,SRC1_REAL or SRC2_DIMM
mov word ptr _res2 + 14, CrLf
invoke FpuFLtoA,offset _y3,10,offset _res3,SRC1_REAL or SRC2_DIMM
mov word ptr _res3 + 14, CrLf
invoke FpuFLtoA,offset _y4,10,offset _res4,SRC1_REAL or SRC2_DIMM
mov word ptr _res4 + 14, CrLf
invoke FpuFLtoA,offset _y5,10,offset _res5,SRC1_REAL or SRC2_DIMM
invoke MessageBox, 0, offset info, offset ttl, MB_ICONINFORMATION
invoke ExitProcess, 0
end _start
I tried changing the loop counter to 5 instead of 6
mov ecx, 5
and the output is normal starts x with 1, but outputs only y1. (picture 2)
FpuFLtoA
writes a null terminated string with a leading space or minus sign. If this string is 14 or 15 characters long the terminator is overwritten by mov word ptr _res1 + 14, CrLf
.
However 1.9444444316
is only 13 characters long so the zero byte is preserved and causes MessageBox
to stop processing the string.