LinuxQuestions.org
Review your favorite Linux distribution.
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 04-20-2004, 10:13 PM   #1
eantoranz
Senior Member
 
Registered: Apr 2003
Location: Costa Rica
Distribution: Kubuntu, Debian, Knoppix
Posts: 2,092
Blog Entries: 1

Rep: Reputation: 90
Question as86 help needed!


Guys... I'm trying to take on rather insignificant portion of C code with assembler in it to a piece of linux executable. This is the code:

#define ASM_START #asm
#define ASM_END #endasm


int main() {
printf("Hello!");
ASM_START
xor ax, ax
ASM_END
}

suppose It's called hello.c

What are the steps I have to follow in order to get from this code to hello (the executable) using as86?
 
Old 04-20-2004, 11:52 PM   #2
itsme86
Senior Member
 
Registered: Jan 2004
Location: Oregon, USA
Distribution: Slackware
Posts: 1,246

Rep: Reputation: 59
That's a C program, not an assembly program. You'd use gcc to compile it, but I don't think #asm and #endasm are the correct markers. It's something like _asm { assembly code }

Here, I found this using google:

Code:
int main(int argc, char *argv[])
{
  char a = 'a';

  __asm__
  {
    "movl a,EAX\n\t"
    "and 0x01000001,EAX\n\t"
    "mov EAX,a\n\t"
  };

  printf("%x\n",a);

  return 1;
}
So then you'd just compile the file with gcc like normal (gcc hello.c -o hello).

If you want to keep the program the same and change only the #defines, then change them to this:

#define ASM_START __asm__ {
#define ASM_END };

edit: Actually, I'm getting compile errors with that. Maybe someone with more knowledge than me can help out

Last edited by itsme86; 04-21-2004 at 12:09 AM.
 
Old 04-21-2004, 05:32 PM   #3
jinksys
Member
 
Registered: Aug 2003
Location: 63123
Distribution: OpenSuSE/Ubuntu
Posts: 419

Rep: Reputation: 35
First, if you are going to use a C shell with inline assembly, you cant compile that with as86. C code has to be compiled with GCC, (unless you use a different compiler, but unlikely) and for inline code GCC uses its GAS assembler. Second, for such a simple program I dont see why you couldnt just write the whole thing in assembly in the first place. Second, may I ask you why you are using as86 anyway, and not a better assembler like NASM or GAS?
 
Old 04-21-2004, 07:09 PM   #4
eantoranz
Senior Member
 
Registered: Apr 2003
Location: Costa Rica
Distribution: Kubuntu, Debian, Knoppix
Posts: 2,092
Blog Entries: 1

Original Poster
Rep: Reputation: 90
you are soooo right

well, man..... I am trying to get myself started in assembly with C.... so I'm looking at my posibilities.

I just started as86... and at the same time looked at nasm.... in fact I found a nasm tutorial yesterday... let's see how it goes.

Is it possible to embed assmbly code in C using nasm? what I've seen is making complete asm code (with no embedding).

PS... oh, and I made it simple just to get to compile it.... once I see how it's done, I'll go on with more difficult stuff.

Last edited by eantoranz; 04-21-2004 at 07:11 PM.
 
Old 04-21-2004, 09:28 PM   #5
jinksys
Member
 
Registered: Aug 2003
Location: 63123
Distribution: OpenSuSE/Ubuntu
Posts: 419

Rep: Reputation: 35
When you embed assembly code into your C code, all you are doing is instructing your C compiler to use your own assembly code instead of constructing its own. You cant choose to use one assembler over another (at least not with gcc), because the compiler uses its own assembler to create the executable. I suggest reading dr paul carter's assembly book, which is free for download at drpaulcarter.com
 
Old 04-22-2004, 12:05 AM   #6
eantoranz
Senior Member
 
Registered: Apr 2003
Location: Costa Rica
Distribution: Kubuntu, Debian, Knoppix
Posts: 2,092
Blog Entries: 1

Original Poster
Rep: Reputation: 90
well... call me lucky or something.... it's the tutorial I told you about yesterday.
 
Old 04-22-2004, 03:33 AM   #7
jinksys
Member
 
Registered: Aug 2003
Location: 63123
Distribution: OpenSuSE/Ubuntu
Posts: 419

Rep: Reputation: 35
oh!, well thats how I originally started out with assembly! Its a very good book.
 
Old 04-22-2004, 11:48 AM   #8
eantoranz
Senior Member
 
Registered: Apr 2003
Location: Costa Rica
Distribution: Kubuntu, Debian, Knoppix
Posts: 2,092
Blog Entries: 1

Original Poster
Rep: Reputation: 90
I'm having troubles running a BIOS int 0x13. I get segmentation faults. This interruption is used to get low level HD access. Could it be a kernel security restriction?
 
Old 04-22-2004, 04:10 PM   #9
jinksys
Member
 
Registered: Aug 2003
Location: 63123
Distribution: OpenSuSE/Ubuntu
Posts: 419

Rep: Reputation: 35
Yes, you cant use the bios interrupts under linux because the kernel takes care of all of that.
If you want to mess around with bios interupts youll either have to write a bootable program, or write a Dos program and use a dos emulator running as root. I can help you with either one of those things.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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
Help Needed paradox_of_life Linux - Newbie 9 02-25-2005 06:05 PM
Help needed srps1579 Linux - Newbie 1 11-23-2004 08:37 AM
help needed here... c12ayon Programming 2 10-29-2003 11:59 AM
Help Needed sandy Linux - Newbie 1 09-22-2003 03:54 AM
Recompile kernel: patches, as86 vs. as kdaru Linux - Newbie 2 05-19-2002 11:05 AM

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

All times are GMT -5. The time now is 07:30 PM.

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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration