N
N
Nikolay2014-11-13 17:59:39
C++ / C#
Nikolay, 2014-11-13 17:59:39

Assembler code inserts in C ++, how to implement it correctly?

How to correctly insert assembler inserts into the body in C ++, are there any rules when writing in the OO style?
And actually, what is the analog of push/pop in C++?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
S
Stanislav Silin, 2014-11-13
@byme

If you are working in Visual Studio, then everything is simple:

int main()
{
  short a=0;
  __asm
  {
  mov ax, a
  inc ax
  mov a, ax
  }
  cout<<a;  //1
}

The stl library has a ready-made stack class.
PS You can also write assembly code in a separate *.asm, and then link it to the project.

T
tsarevfs, 2014-11-13
@tsarevfs

1 rule of assembler inserts - "it would be better if you didn't do assembler inserts".
Are you sure you need it? For example, working with SSE is quite possible with the help of C++ libraries.
Some analogue of push pop can be considered the _allcoa function that allocates memory on the stack. Working with objects through assembler is of course possible. Read about call conventions, name mangling, alignment. If you want to work with objects using inheritance and virtual functions, then you need to understand the structure of the virtual function table.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question