LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   as86 help needed! (https://www.linuxquestions.org/questions/programming-9/as86-help-needed-172698/)

eantoranz 04-20-2004 09:13 PM

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?

itsme86 04-20-2004 10:52 PM

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 :)

jinksys 04-21-2004 04:32 PM

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?

eantoranz 04-21-2004 06:09 PM

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.

jinksys 04-21-2004 08:28 PM

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

eantoranz 04-21-2004 11:05 PM

well... call me lucky or something.... it's the tutorial I told you about yesterday. :D

jinksys 04-22-2004 02:33 AM

oh!, well thats how I originally started out with assembly! Its a very good book.

eantoranz 04-22-2004 10:48 AM

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?

jinksys 04-22-2004 03:10 PM

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.


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