flat assembler
Message board for the users of flat assembler.
![]() |
Author |
|
0.1 23 Aug 2007, 10:02
Easiest solution:
If you are using G++ (GNU compiler for C++) do this ... g++ -S yourfile.cpp and then have a look at yourfile.s to know how G++ did it. NOTE: just put the bare bones in your source file. e.g. put this: Code: struct Vector { float x; float y; } Vecrot foo(Vector a, Vector b) { Vecrot c; c.x = a.x + b.x; c.y = a.y + b.y; return c; } If you do not use g++ then you have to find out how to ask your compiler to generate assembly output. _________________ Code: o__=- ) (\ /\ |
|||
![]() |
|
penguinglx 24 Aug 2007, 05:05
Probably u got me wrong
I meant I can implement that function in assembly language ,but how to return the result Let me make it clear Module 1: ---------------- Code: #include <iostream.h> extern Vector Add(Vector a,Vector b); void main() { Vector Vector1,Vector2,Vector3; Vector3=AddVector(Vector1,Vector2); cout<<Vector3.x<<" "<<Vector3.y; } Module 2: ------------------ Code: Fasm ..... all stuff blah blah.... AddVector: push ebp mov ebp,esp finit ;------ fld dword [ebp+8] Vector1.x fadd dword [ebp+16] x + x fld dword [ebp+12] Vector1.y fadd dword [ebp+20] y+y OK st0 = y+y ,st1= x+x What do I need to do here to return both values above to vector3 in the Caller pop ebp retn |
|||
![]() |
|
0.1 24 Aug 2007, 05:32
Probably you got me wrong too!
|
|||
![]() |
|
penguinglx 24 Aug 2007, 05:36
OK I get u right now , Ill do it
|
|||
![]() |
|
0.1 24 Aug 2007, 05:42
Code: // My source. struct Vector { float x; float y; float z; float w; }; Vector foo(Vector a, Vector b) { Vector c; c.x = a.x + b.x; c.y = a.y + b.y; c.z = a.z + b.z; c.w = a.w + b.w; return c; } // Out put from g++. .file "vec.cpp" .text .align 2 .globl __Z3foo6VectorS_ .def __Z3foo6VectorS_; .scl 2; .type 32; .endef __Z3foo6VectorS_: pushl %ebp movl %esp, %ebp movl 8(%ebp), %eax flds 12(%ebp) fadds 28(%ebp) fstps (%eax) flds 16(%ebp) fadds 32(%ebp) fstps 4(%eax) flds 20(%ebp) fadds 36(%ebp) fstps 8(%eax) flds 24(%ebp) fadds 40(%ebp) fstps 12(%eax) popl %ebp ret $4 See that! There no simple way to return a structure, so g++ just invoked the function "foo" with address which is then modified to contain the structure values. Which we suppose it is returning from function. Got it? No, take a deeper look. _________________ Code: o__=- ) (\ /\ |
|||
![]() |
|
penguinglx 24 Aug 2007, 06:19
thanks Alot I got it
![]() ![]() |
|||
![]() |
|
Yardman 24 Aug 2007, 08:05
[ Post removed by author. ]
Last edited by Yardman on 04 Apr 2012, 02:46; edited 1 time in total |
|||
![]() |
|
0.1 24 Aug 2007, 09:52
gud copy Yardman
![]() that what g++ is doing in the above example (posted by me) ![]() _________________ Code: o__=- ) (\ /\ |
|||
![]() |
|
Yardman 24 Aug 2007, 11:03
[ Post removed by author. ]
Last edited by Yardman on 04 Apr 2012, 02:46; edited 2 times in total |
|||
![]() |
|
0.1 24 Aug 2007, 11:22
Yardman is a nice guy and good human being!
Yardman is a nice guy and good human being! Yardman is a nice guy and good human being! Yardman is a nice guy and good human being! Yardman is a nice guy and good human being! Last edited by 0.1 on 25 Aug 2007, 04:09; edited 1 time in total |
|||
![]() |
|
0.1 24 Aug 2007, 11:28
Yardman is a good human being and nice guy!
Yardman is a good human being and nice guy! Yardman is a good human being and nice guy! Yardman is a good human being and nice guy! Yardman is a good human being and nice guy! Last edited by 0.1 on 25 Aug 2007, 04:10; edited 1 time in total |
|||
![]() |
|
Yardman 24 Aug 2007, 14:50
[ Post removed by author. ]
Last edited by Yardman on 04 Apr 2012, 02:46; edited 1 time in total |
|||
![]() |
|
0.1 25 Aug 2007, 04:08
Yardman wrote: Now, I recall Vid giving I know the difference. Do not kid me ![]() Yardman wrote:
I agree, you agree, we both agree ![]() _________________ Code: o__=- ) (\ /\ |
|||
![]() |
|
< Last Thread | Next Thread > |
Forum Rules:
|
Copyright © 1999-2023, Tomasz Grysztar. Also on GitHub, YouTube, Twitter.
Website powered by rwasa.