R
R
Ruslan2019-03-30 15:20:13
C++ / C#
Ruslan, 2019-03-30 15:20:13

How to pass the value of a variable to the stack (Assembler)?

Hello.
I solve the problem in TASM assembler. Subroutine that calculates the hyperbolic sine. This subroutine must be linked to the main program using the C language communication standards.
My problem is that I can't push a real number onto the stack.
I enter a number from the keyboard, this number is on the FPU stack, I put it in the Source variable, and then I have to load it onto the stack and call a subroutine where I unload it and start the calculations
Here is an example code:
-------- -------
Source dq ?
Result dq ?
---------------
sub sp,16
mov bp,sp
fstp Source
mov qword ptr [bp], Source // "need register in expression" error here
mov qword ptr [bp+8], Result //there is an error "need register in expression"
call OutFloat
Add sp,16
---------------

Answer the question

In order to leave comments, you need to log in

2 answer(s)
J
jcmvbkbc, 2019-03-30
@magaaamed

The code might look something like this:

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

Those. you can unload the value from the coprocessor directly to the place where the outgoing parameter for the function call will be.
The error occurs because there are no mov commands that transfer the value from memory to memory.

M
Muriam, 2019-03-30
@Muriam

using the push command

push AX      ; передать значение регистра AX в стек
push ВX      ; передать значение регистра BX в стек

....               ; ваш код

pop BX       ; извлечь значение из стека в регистр AX
pop AX       ; извлечь значение из стека в регистр AX

If you send multiple values ​​to the stack and take them out from there, then you need to do it according to the LIFO principle (last in, first out)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question