c++ - Running In-Line Assembly in Linux Environment (Using GCC/G++) -


so have basic program written in c (.c file) in-line assembly coding part. want convert .c file assembly output know don't know how compile code linux environment.

when using gcc or g++ .cpp files, errors not recognizing asm instructions.

now code works intended in visual studio besides me changing brackets asm code parenthesis. still errors. bunch of undefined references variables.

the changes made working code changing brackets parentheses, putting assembly instruction in quotation marks (found online, wrong).

in short, want code below able compiled in linux environment using command gcc. don't know syntax code works, not linux/.

#include <stdio.h> int main()  {  float num1, num2, sum, product; float sum, product; float f1, f2, f3, fsum, fmul;  printf("enter 2 floating point numbers: \n"); scanf("%f %f", &num1, &num2);   __asm__  (     "fld num1;"     "fadd num2;"     "fst fsum;" );  printf("the sum of %f , %f " "is" " %f\n", num1, num2, fsum); printf("the hex equivalent of numbers , sum %x + %x = %x\n", num1, num2, fsum);  return 0; } 

in-line assembly in gcc translated literally generated assembly source; since variables don't exist in assembly, there's no way have written can work.

the way make work use extended assembly, annotates assembly modifiers gcc use translate assembly when source compiled.

__asm__ (   "fld %1\n\t"   "fadd %2\n\t"   "fst %0"   : "=f" (fsum)   : "f" (num1), "f" (num2)   : ); 

Comments

Popular posts from this blog

html - Styling progress bar with inline style -

java - Oracle Sql developer error: could not install some modules -

How to use autoclose brackets in Jupyter notebook? -