Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Mar 30th, 2006, 7:21 AM   #1
edemkay
Newbie
 
Join Date: Mar 2006
Posts: 3
Rep Power: 0 edemkay is on a distinguished road
C / Assembly HELP

I am new to the assembly world i tried to combined the C and assembly code below.
. How do i run (compile both) and how do i access an array if sent as parameter to the assemly part.
Thanks
#include <stdio.h>

extern int add_num(int num1, int num2);

int main()
{
printf("Sum: %d\n" ,add_num(22, 33));
return 0;
}

/*Assembly part*/
global add_num
add_num:
push ebp ; save ebp register
mov ebp, esp ; get current stack pointer
push ebx ; save ebx register
mov ebx, [ebp + 8] ; get second parameter
mov eax, [ebp + 12] ; get first parameter
add eax, ebx ; add numbers,store sum in eax, return value
pop ebx ; restore ebx
pop ebp ; restore ebp
ret ; return to caller

/*Make file*/

main :addNum
gcc -o main caller.c addNum.o
addNum :addNum.asm
nasm -felf -o addNum.o addNum.asm
edemkay is offline   Reply With Quote
Old Mar 30th, 2006, 8:46 AM   #2
DaWei
Resident Grouch
 
DaWei's Avatar
 
Join Date: Jun 2005
Posts: 6,453
Rep Power: 10 DaWei is on a distinguished road
Please read the forum's rules/FAQ and the "How to Post a Question" thread at the top of the C forum.
__________________
Abstraction doesn't make it impossible to write bad code; it makes it possible to write superior code.
Contributor's Corner: Grumpy on C++ Exceptions DaWei on Pointers
DaWei is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 4:55 AM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC