LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 01-15-2008, 07:15 AM   #1
Peter_APIIT
Member
 
Registered: Dec 2006
Posts: 606

Rep: Reputation: 31
Print Stack Pointer


Hello all expert C programmer and hacker, i truly a noob in this field.

I have a program that print stack pointer but i don't really know its underlying concept.

I hope you all can explain it to me. When i try to compiled this program , unresolve external symbol means i didn't finish up the function definition

Below is my program :


Quote:
// A little program to print stack pointer


#include<stdio.h>

int main()
{
printf("0x%x\n", get_sp());
return 0;
}

unsigned long get_sp()
{
__asm__("movl %esp,%eax");
}
Quote:
--------------------Configuration: StackPointer. - Win32 Debug--------------------
Linking...
StackPointer..obj : error LNK2001: unresolved external symbol ___asm__
Debug/StackPointer..exe : fatal error LNK1120: 1 unresolved externals
Error executing link.exe.

StackPointer..exe - 2 error(s), 0 warning(s

I used MS VC 6.0 ++ on MS platforms.

A billion thanks for your help.
 
Old 01-15-2008, 07:33 AM   #2
orgcandman
Member
 
Registered: May 2002
Location: new hampshire
Distribution: Fedora, RHEL
Posts: 600

Rep: Reputation: 110Reputation: 110
different compiler platforms define different asm directives.

I suggesting having macros:

BEGIN_ASM_BLOCK
END_ASM_BLOCK

which are platform specific, and having your code call the macro fuctions.

The asm on gcc is just "asm" not "__asm__"

-Aaron
 
Old 01-15-2008, 07:42 AM   #3
Uncle_Theodore
Member
 
Registered: Dec 2007
Location: Charleston WV, USA
Distribution: Slackware 12.2, Arch Linux Amd64
Posts: 896

Rep: Reputation: 71
Learning some hacking, aren't we?
To make it work in Windows, start reading here
http://msdn2.microsoft.com/en-us/library/45yd4tzz.aspx
 
  


Reply



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 Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Difference b/t Kernel stack and User stack hazzyb Linux - Software 2 09-29-2008 07:40 PM
returning data to main() via a pointer to a pointer. slzckboy Programming 3 05-30-2005 01:20 PM
hot to set value of pointer to pointer to a structure in C alix123 Programming 2 11-17-2004 06:40 AM
red hat 9 stack pointer drumwell Red Hat 4 11-15-2004 02:11 PM
red hat 9 stack pointer drumwell Linux - Security 1 02-24-2004 12:13 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 02:38 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration