Page 1 of 1

Writing C Routines with nasm

Posted: Tue Sep 10, 2002 3:38 am
by srg
[attachment deleted by admin]

Re:Writing C Routines with nasm

Posted: Tue Sep 10, 2002 3:57 am
by Pype.Clicker
could we have the C code as well ?

Re:Writing C Routines with nasm

Posted: Tue Sep 10, 2002 4:08 am
by srg
Yeah sure

Here's the header

#include <dos.h>
#include "global.h"

/* Definitions ######################### */

extern struct System DetectedSystem;

UCHAR String8086[] = "8086/8088\0";
UCHAR String80286[] = "80286\0";
UCHAR String80386[] = "80386\0";
UCHAR String80486[] = "80486\0";
UCHAR String80486DX4[] = "80486 DX4\0";
UCHAR StringAm4or586[] = "Am486 DX4 or Am5x86-PR75\0";

/* Fuction Prototypes ------------------------------------- */

void DetectCPU();
void SetCPUIdentString(UCHAR *String);
UCHAR Detect86();
UCHAR Detect286();
UCHAR Detect386();
UCHAR Detect486();


In the actuall module, the only code in question is simply a test variable that is then assigned the return value of one of these routines.

void DetectCPU()
{
UCHAR Test = 0;
Test = Detect86();
}

Re:Writing C Routines with nasm

Posted: Tue Sep 10, 2002 4:19 am
by drizzt
I think you must declare your asm routines with the "extern" in the C program:

extern UCHAR Detect86();
extern UCHAR Detect286();
extern UCHAR Detect386();
extern UCHAR Detect486();

Re:Writing C Routines with nasm

Posted: Tue Sep 10, 2002 4:48 am
by srg
No Change

Re:Writing C Routines with nasm

Posted: Tue Sep 10, 2002 5:17 am
by srg
Thankyou for your contributions, but I now have got it running.

Thanks all the same

Re:Writing C Routines with nasm

Posted: Tue Sep 10, 2002 5:19 am
by Tim
How did you get it working? Somebody else reading this might have the same problem.

Re:Writing C Routines with nasm

Posted: Tue Sep 10, 2002 5:20 am
by Pype.Clicker
hmmm ... really weird... wait ... you have CPU.asm -> cpu.obj and cpu.c -> cpu.obj. Are you sure the nasmed version isn't overwritten by the C one ? it would prevent LD from receiving the _Detectx86 stuff and could explain your problem ...

You didn't made that error, did you ?

Re:Writing C Routines with nasm

Posted: Tue Sep 10, 2002 9:45 am
by srg
Sorry

Right, first of all, I did make that mistake, but found it and fixed it, calling the asm file CPUDet.asm.

I followed drizzt's advice and put the externs in.

Then I Got some error about _TEXT segment, so I added this to line 2 of the asm file:

SEGMENT _TEXT PUBLIC CLASS=CODE USE16

Everything worked from them on!!

It's interesting how just speaking to someone often helps you fix the problem yourself!

hmm BTW, the linker I'm using for this is the Turbo Link that came with Turbo C++