How to pass the variable value onto the stack (Assembler)?

Hello.
Solve the problem on the assembler TASM. The subprogram that computes the hyperbolic sine. This routine must be linked with the main program using communication standards with the language.
My problem is that I can't load real number in the stack.
I enter the number from the keyboard, the number to be in the FPU stack, put it into a variable Source, and then I have to upload it onto the stack and call a subroutine where I unload it and start calculating
Here is a sample code:
---------------
Source dq ?
Result dq ?
---------------
sub sp,16
mov bp,sp
fstp Source
mov qword ptr [bp], Source //here error "need register in expression"
mov qword ptr [bp+8], Result //here error "need register in expression"
call OutFloat
Add sp,16
---------------
March 19th 20 at 09:18
2 answers
March 19th 20 at 09:20
Solution
The code might look something like this:

void OutFloat(double v);

sub sp,16
mov bp,sp
fstp qword ptr [bp + 8]
call OutFloat
add sp,16


I.e. you can unload the value from the coprocessor directly in the place where you will be outbound parameter to a function call.
The error arises from the fact that there is no mov command to transmit a value from memory into memory.
I did, too. But in my lab is given the task - subroutine takes the value of two arguments (Source, Result). So I think there is a way to send two variables to the stack. - stanton_Smith commented on March 19th 20 at 09:23
in the lab the task - subroutine takes the value of two arguments (Source, Result).

Why do you have arguments not on the stack I don't really understand where?

In any case, you just need to copy the value from memory into memory. This can be done in several ways. For example:
sub sp, 8
fld qword ptr [source]
fstp qword ptr [sp]
call OutFloat
add sp, 8


or this:
mov ax, word ptr [source + 6]
push ax
mov ax, word ptr [source + 4]
push ax
mov ax, word ptr [source + 2]
push ax
mov ax, word ptr [source]
push ax
call OutFloat
add sp, 8


or this:
lea si, source
sub sp, 8
mov di, sp
cld
mov cx, 4
rep movsw
call OutFloat
add sp, 8
- Kavon commented on March 19th 20 at 09:26
@Kavon,Thanks for the examples.Can I ask more questions? 3 way as in the subroutine call the stack value in the FPU?
I tried that, but the program brought 0
FLD qword ptr [di]
And 1 way I didn't understand what was happening. And it's not working, when compiling gives the error: "Illegal indexing mode" in one line
fstp qword ptr [sp]
3 way clear, but here too there are difficulties with the loading of this variable on the stack FPU. The idea is you need to call three times to pop, to put them somewhere and join in one number? - stanton_Smith commented on March 19th 20 at 09:29
3 way as in the subroutine call the stack value in the FPU?


@stanton_Smith,
push bp
mov bp, sp
fld qword ptr [bp + 8]
...
pop bp
ret


And 1 way I didn't understand what was happening. And it's not working, when compiling gives the error: "Illegal indexing mode" in one line

In the first method, I double shift from source to the stack through the coprocessor. Yes, I forgot that 16-bit assembler does not know how to alexiromance relative to sp. Should be like this:
push bp
mov bp, sp
sub sp, 8
fld qword ptr [source]
fstp qword ptr [bp - 8]
call OutFloat
add sp, 8
pop bp
ret


3 way clear, but here too there are difficulties with the loading of this variable on the stack FPU. The idea is you need to call three times to pop, to put them somewhere and join in one number?

No. They lie on the stack in the correct order. This is the finished number. It is possible to load the same code:
push bp
mov bp, sp
fld qword ptr [bp + 8]
...
pop bp
ret
- Kavon commented on March 19th 20 at 09:32
Everything works. Thank you, you helped me a lot) - stanton_Smith commented on March 19th 20 at 09:35
March 19th 20 at 09:22
with the push command

push AX ; pass the value of register AX on the stack
push BX ; pass the value of register BX onto the stack

.... ; your code

pop BX ; retrieve value from stack into register AX
pop AX ; retrieve value from stack into register AX


If you send multiple values to the stack and removed them from there, then you need to do it on the principle of LIFO (last in, first out)
I have to load a real number into AX, and then using push to shove with the stack in the subroutine call by using pop. Well then the question arises how to download prophetic. the number in AX?
And my code to create a pointer and stack bp sp not working? - stanton_Smith commented on March 19th 20 at 09:25

Find more questions by tags AssemblerC++