# [HELP] looping with floating number

i m trying to do an arithmetic series which is able to read in floating numbers. Yet i entered a problem with the looping.

Initially, i tried with inc instruction to increase my value in register cx by one b4 entering the second loop. Yet the value of cx will multiply itself with 1000, As result the loop can't run properly.

Then, i tried with another way. I declare a variable COUNTER and initiate COUNTER as 0. I move value one into the counter b4 entering the second loop.
mov eax, counter

Yet the same problem still occur.

• : i m trying to do an arithmetic series which is able to read in
: floating numbers. Yet i entered a problem with the looping.
:
: Initially, i tried with inc instruction to increase my value in
: register cx by one b4 entering the second loop. Yet the value of cx
: will multiply itself with 1000, As result the loop can't run
: properly.
:
: Then, i tried with another way. I declare a variable COUNTER and
: initiate COUNTER as 0. I move value one into the counter b4 entering
: the second loop.
: mov eax, counter
:
:
: Yet the same problem still occur.
:
[color=Blue]Can you post the code?[/color]

BELOW IS MY CODE
[/color]
--------------------------------------------------------------------------------

INCLUDE Irvine16.inc

.stack 200h

.386

CR=0Dh
LF=0Ah
TAB=09h

.data

get_n db "The value of n : "
get_d db "The value of d : "
get_a1 db "The value of a1 : "

n dd ?
d dd ?
a_1st dd ?
nd dd ?
a_nth dd ?
nmin1 dd ?

one dd 1
two dd 2

;-------------------- macro to write a string -----------------------
WSTR MACRO string
mov ah,40h
mov bx,1
mov cx,LENGTHOF string
mov dx,OFFSET string
INT 21h
ENDM

;------------------ macro to produce end of line --------------------
ENDL MACRO
mov ah,2
mov dl,CR
int 21h
mov ah,2
mov dl,LF
int 21h
ENDM

;-------------------- macro to leave a space ------------------------
SPACING MACRO
mov ah,2
mov dl,TAB
int 21h
ENDM

.code

main PROC
mov ax,@data ;load the data segment into ds
mov ds,ax

Wstr get_n
mov n,eax
call WriteFloat ; to trace the accuracy of input
ENDL

Wstr get_d
mov d,eax
call WriteFloat ; to trace the accuracy of input
ENDL

Wstr get_a1
mov a_1st,eax
call WriteFloat ; to trace the accuracy of input
ENDL

mov cx,0

mov ax,cx ; i try to debug the value in cx, yet cx
shown in exe is not 0, but value of a_1st
call WriteFloat
SPACING

nthTerms: ;Tn=a|n-1|+d
cmp ecx,n
jge summation

mov eax,a_nth
call WriteFloat
SPACING

fild a_nth
fistp a_nth
mov eax,a_nth
call WriteFloat

inc ecx

jmp nthTerms

summation : ;sum_nth=n/2*[2a+(n-1)d]
fild n
fisub one
fimul d
fistp nmin1

fild a_1st
fimul two
fistp a_1st

fild n
fidiv two
fimul a_1st
fistp n
mov eax,n
call writeFloat

finish:
ENDL
ENDL
mov ax,4c00h
INT 21h

main ENDP
end main

----------------------------------------------------------------------------------

[color=Blue]Problems:

1) In the exe file, why my input will appear at the next line after my input msg since i didn't put ENDL?

2) Why the counter value takes the value of a_1st? Though i had initialize cx as 0. Other than that, value of ecx will not increase by one after every loop.

3) Why my floating number appears in exponential form??
How can i set the precision of the decimal point like in c++?

4) Kindly advise pls why the same program run smooth for integer value?

Again! Thanks for your attention on my post!
[/color]

• :
: BELOW IS MY CODE
: [/color]
: ---------------------------------------------------------------------
: -----------
:
: INCLUDE Irvine16.inc
:
: .stack 200h
:
: .386
:
: CR=0Dh
: LF=0Ah
: TAB=09h
:
: .data
:
: get_n db "The value of n : "
: get_d db "The value of d : "
: get_a1 db "The value of a1 : "
:
: n dd ?
: d dd ?
: a_1st dd ?
: nd dd ?
: a_nth dd ?
: nmin1 dd ?
:
: one dd 1
: two dd 2
:
:
: ;-------------------- macro to write a string -----------------------
: WSTR MACRO string
: mov ah,40h
: mov bx,1
: mov cx,LENGTHOF string
: mov dx,OFFSET string
: INT 21h
: ENDM
:
: ;------------------ macro to produce end of line --------------------
: ENDL MACRO
: mov ah,2
: mov dl,CR
: int 21h
: mov ah,2
: mov dl,LF
: int 21h
: ENDM
:
:
: ;-------------------- macro to leave a space ------------------------
: SPACING MACRO
: mov ah,2
: mov dl,TAB
: int 21h
: ENDM
:
:
: .code
:
: main PROC
: mov ax,@data ;load the data segment into ds
: mov ds,ax
:
: Wstr get_n
: mov n,eax
: call WriteFloat ; to trace the accuracy of input
: ENDL
:
: Wstr get_d
: mov d,eax
: call WriteFloat ; to trace the accuracy of input
: ENDL
:
: Wstr get_a1
: mov a_1st,eax
: call WriteFloat ; to trace the accuracy of input
: ENDL
:
: mov cx,0
:
: mov ax,cx ; i try to debug the value in cx,
: yet cx
: shown in exe is not 0, but value of
: a_1st
: call WriteFloat
: SPACING
:
: nthTerms: ;Tn=a|n-1|+d
: cmp ecx,n
: jge summation
:
: mov eax,a_nth
: call WriteFloat
: SPACING
:
: fild a_nth
: fistp a_nth
: mov eax,a_nth
: call WriteFloat
:
: inc ecx
:
: jmp nthTerms
:
: summation : ;sum_nth=n/2*[2a+(n-1)d]
: fild n
: fisub one
: fimul d
: fistp nmin1
:
: fild a_1st
: fimul two
: fistp a_1st
:
: fild n
: fidiv two
: fimul a_1st
: fistp n
: mov eax,n
: call writeFloat
:
: finish:
: ENDL
: ENDL
: mov ax,4c00h
: INT 21h
:
: main ENDP
: end main
:
: ---------------------------------------------------------------------
: -------------
:
: [color=Blue]Problems:
:
: 1) In the exe file, why my input will appear at the next line after
: my input msg since i didn't put ENDL?
:
: 2) Why the counter value takes the value of a_1st? Though i had
: initialize cx as 0. Other than that, value of ecx will not increase
: by one after every loop.
:
: 3) Why my floating number appears in exponential form??
: How can i set the precision of the decimal point like in c++?
:
: 4) Kindly advise pls why the same program run smooth for integer
: value?
: respectively.
:
:
: Again! Thanks for your attention on my post!
: [/color]
:
:
[color=Blue]You should run your code in debugger. End of line character may be added by ReadFloat function. Also, exponential output may be due to using WriteFloat function. Register ECX may be modified by other functions and not preserved. Again, your good friend is debugger - find a DOS debugger and see what other functions are doing.[/color]