![]() |
|
#1
|
||||
|
||||
Mixing C and assembly in x86 - Makefile nuanceshello,
I have been trying to write a C program and call an assembly routine from within the C program. Im following the C calling convention. I have written the following assembly routine and named the file 'mul64_32.asm' and this file is as shown below, I have a routine which is called 'llmultiply' which I call from the C source file. In this assembly routine, I assume that the stack looks like as shown in the second ASCII art figure here. Code:
In this program Im trying to implement a 64*64 multiplication using 32bit registers present in an x86 platform. Now this is exactly what Im trying to do but everything in C in this thread wherein I had segfault issues which were pointed put by dave. That code is still buggy but since my labs require me to hand in the assembly one first, im stuck with this! Now I call this from the following C file which is called 'main.c'. CPP / C++ / C Code:
Makefile Code:
Code:
Code:
Hope to hear from you guys, __________________
Hope to hear from you guys! -------------------------------------------------- Best Regards, Aijaz Baig. |
||||
|
#2
|
|||
|
|||
Re: Mixing C and assembly in x86 - Makefile nuancesQuote:
Code:
What happens when you execute that from a command line? If it does create mul64_32.o, then look at the Makefile: Makefile Code:
You have to tell the make program that the target depends on mul64_32.o also. Maybe try changing the Makefile to Code:
Then try Code:
Just a guess. Regards, Dave |
|
#3
|
||||
|
||||
Re: Mixing C and assembly in x86 - Makefile nuancesWell...the technique you told above did work for me. I did change the Makefile as you suggested and then I tried building the binary and the floppy image by executing the 'make' command after I manually assembled the assembly code.
But as with the latter part of this thread, the result was all zeros. As our school workstation do not have gdb installed on their windows workstations (they have it on limux and solaris, i dunno why not on windows.. Now my make file is: Code:
Addionally 'main.c' is exactly the same as above. Shown below is what I have added to the asm file so I could call the C printf function from within it. And as you've guessed it doesn't work. Code:
I dunno what that 'k' is for there but we have been advised to use eclipse which I sometimes do and sometimes don't and when I issue the 'clean project' command from eclipse, it automatically inserts the 'k' in there. Anyways..point is...even if theres a 'k' or not...I haven't got the "_printf" part right. This is what the compiler complains about: Code:
__________________
Hope to hear from you guys! -------------------------------------------------- Best Regards, Aijaz Baig. |
|
#4
|
|||
|
|||
Re: Mixing C and assembly in x86 - Makefile nuancesQuote:
Code:
Quote:
Quote:
I observe that C compilers typically clean up the stack after calling a function by adding to a number (equal to the lengths of all of the arguments that were pushed) to the stack pointer, not by using multiple pop instructions. Note that if you need to restore the old value of ebx (I don't know whether it is necessary), you have to pop the stuff in reverse order. maybe: Code:
If you know that the called function doesn't screw with ebx (or if you don't need to restore its value, then instead of add, pop you could just add ebp,8 Disclaimer: I have no way of testing. Furthermore, this pretty much exhausts my knowledge of and enthusiasm for the subject. Maybe some other assembly language wonk can contribute some suggestions. Regards, Dave |
Recent GIDBlog
Install Adobe Flash - Without Administrator Rights by LocalTech
| Thread Tools | Search this Thread |
| Rate This Thread | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| C mixed with assembly x86 | ChristieGiorgos | Assembly Language | 1 | 23-Mar-2008 06:47 |
| Standard Assembly Languages | Peter_APIIT | Assembly Language | 10 | 23-Mar-2008 06:31 |
| Hangman in Assembly | zeliie | Assembly Language | 1 | 24-Nov-2007 11:32 |
| Assemblers & assembly language | BlueFireCO. | Assembly Language | 2 | 26-Mar-2007 09:56 |
Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The