Writing C Routines with nasm

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Post Reply
srg

Writing C Routines with nasm

Post by srg »

[attachment deleted by admin]
User avatar
Pype.Clicker
Member
Member
Posts: 5964
Joined: Wed Oct 18, 2006 2:31 am
Location: In a galaxy, far, far away
Contact:

Re:Writing C Routines with nasm

Post by Pype.Clicker »

could we have the C code as well ?
srg

Re:Writing C Routines with nasm

Post 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();
}
drizzt

Re:Writing C Routines with nasm

Post 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();
srg

Re:Writing C Routines with nasm

Post by srg »

No Change
srg

Re:Writing C Routines with nasm

Post by srg »

Thankyou for your contributions, but I now have got it running.

Thanks all the same
Tim

Re:Writing C Routines with nasm

Post by Tim »

How did you get it working? Somebody else reading this might have the same problem.
User avatar
Pype.Clicker
Member
Member
Posts: 5964
Joined: Wed Oct 18, 2006 2:31 am
Location: In a galaxy, far, far away
Contact:

Re:Writing C Routines with nasm

Post 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 ?
srg

Re:Writing C Routines with nasm

Post 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++
Post Reply