Author Topic: drpaulcarter.com help  (Read 27331 times)

Offline dstudentx

  • Jr. Member
  • *
  • Posts: 18
drpaulcarter.com help
« on: February 13, 2010, 02:16:22 AM »
I'm trying to learn Nasm and I'm using Dr Paul Carters book and sample codes but cant get anything to run.
I'm trying to run the first asm project in the book.

in the command terminal he says to type (im using xp)

; nasm -f win32 first.asm
; cl first.obj driver.c asm_io.obj

; nasm -f win32 first.asm <- this works but

; cl first.obj driver.c asm_io.obj <- I get a error message-> " 'cl ' not a recognized as an internal or external command.

I don't know what to do.
What do I need to do to get one of his sample programs to load? I looked every where for information but am lost.

Any help would be greatly appreciated.

Offline Bryant Keller

  • Forum Moderator
  • Full Member
  • *****
  • Posts: 360
  • Country: us
    • About Bryant Keller
Re: drpaulcarter.com help
« Reply #1 on: February 13, 2010, 02:56:50 AM »
CL.EXE is the Microsoft C/C++ Compiler. You can get a free copy of Microsoft Visual C++ 2008 Express Edition from the following site:

http://www.microsoft.com/express/Downloads/#2008-Visual-CPP

Alternatively,
If you look at the bottom of this page:
http://www.drpaulcarter.com/pcasm/

You'll see multiple versions of the example code. DJGPP and OpenWatcom are decent compilers in their own right (also free) and can be found easily on the Internet. If you wish to use any of these alternative C/C++ compilers you'll want to look at the Makefile in the examples to figure out how to build software with these alternative compilers.

About Bryant Keller
bkeller@about.me

Offline dstudentx

  • Jr. Member
  • *
  • Posts: 18
Re: drpaulcarter.com help
« Reply #2 on: February 13, 2010, 08:12:26 AM »
Thank you for the help but in still confused. visual basic seems to only compile c++, isn't this code for nasm.
I cant get the code to compile in visual basic.

How can I get Dr paul Carters code to compile in nasm?

Offline TmX

  • Jr. Member
  • *
  • Posts: 7
Re: drpaulcarter.com help
« Reply #3 on: February 13, 2010, 08:55:01 AM »
How can I get Dr paul Carters code to compile in nasm?

What do you mean by that?
Dr Paul Carter tutorial is NASM based already.

Offline Frank Kotler

  • NASM Developer
  • Hero Member
  • *****
  • Posts: 2667
  • Country: us
Re: drpaulcarter.com help
« Reply #4 on: February 13, 2010, 04:15:22 PM »
Dr. Carter's tut is Nasm based, but uses the C library to talk to the OS - that's how it works on both Windows and Linux! So you need *some* C compiler, and library(!) installed for it to work. "Installed" probably involves more than downloading it and unzipping it - environment variables need to be set (so it can *find* the library!). If you haven't already got a C compiler (and linker!) installed and working, this tut may not be as easy for you as it's supposed to be.

If you're running XP, you should have "fake dos" available. A dos .com file is about the simplest thing to get running. (no linker... and its command line... required) Dos is "dead", or at least not at "the top of the charts" (it still works fine, so it isn't "dead"). There isn't much point in spending time learning it. 16-bit code has "complications" you'll be glad to forget, too. But if you get frustrated, and just want to get *something* working, we can provide examples of something simple.

But say you've got some C compiler installed, and can compile some kind of "hello world" in C. Now we can get back to Dr. Carter's tut. The first thing you probably want to do is assemble "asm_io.asm" with Nasm - the command lines are in comments in the file. (I hope you got the examples package that matches the compiler you've got - get the right one, if you haven't!). This will produce "asm_io.obj", which we will be asking the C compiler to use, so it has to be there! Then assemble "first.asm". I guess the command line you've got is okay - I'd have to use "nasm -f elf -dELF_TYPE first.asm" (C is not as "portable" as it looks, once you get under the hood).

Now you're ready for that compiler. "driver.c" is very simple, it just calls "asm_main" - take a look at it. Some compilers want you to specify an output name with the "-o" switch - "-o first.exe" - but "cl" apparently uses the first filename provided.

cl first.obj driver.c asm_io.obj

"first.asm", as you see, is full of macros, provided in "asm_io.inc". These macros do some setup, and call subroutines provided by "asm_io.asm", which mostly call printf. Hiding away the "workings" makes it "easy" if all goes well. If you have a problem, it makes you look harder to find it. :)

If you continue to have trouble, perhaps this tutorial is not the right one for you. There are other ways of doing it. Don't give up! It gets easier as you go along... except for the hard parts. :)

Best,
Frank


Offline dstudentx

  • Jr. Member
  • *
  • Posts: 18
Re: drpaulcarter.com help
« Reply #5 on: February 13, 2010, 08:29:10 PM »
thank you for the help.

so just having nasm running isnt enough? I need to also get a c compiler? where/how do i do that?

im running xp and also ubuntu.

Offline Keith Kanios

  • Full Member
  • **
  • Posts: 383
  • Country: us
    • Personal Homepage
Re: drpaulcarter.com help
« Reply #6 on: February 14, 2010, 03:30:17 AM »
thank you for the help.

so just having nasm running isnt enough? I need to also get a c compiler? where/how do i do that?

im running xp and also ubuntu.

If you plan on compiling and mixing C code, the no, NASM alone isn't enough.

If you wish to merely link against the standard c library, NASM and a linker are sufficient. For example, in Windows and with GoLink, you can link your asm code against MSVCRT.DLL to utilize the C library.

Offline TmX

  • Jr. Member
  • *
  • Posts: 7
Re: drpaulcarter.com help
« Reply #7 on: February 14, 2010, 06:37:44 AM »
thank you for the help.

so just having nasm running isnt enough? I need to also get a c compiler? where/how do i do that?

im running xp and also ubuntu.

http://www.drpaulcarter.com/pcasm/

In Windows, you can use DJGPP, MinGW, Borland, or Open Watcom.
In Linux, there is GCC.

And since you use Ubuntu, try this:
Code: [Select]
sudo apt-get install build-essential

Offline Frank Kotler

  • NASM Developer
  • Hero Member
  • *****
  • Posts: 2667
  • Country: us
Re: drpaulcarter.com help
« Reply #8 on: February 14, 2010, 12:06:42 PM »
Well, yeah, if you want to use Dr. Carter's tut, you need a C compiler. Says that right on the web page. You apparently downloaded the "Microsoft" version of the examples, so you probably want the Microsoft compiler - the link Bryant gave you in the very first answer.

BUT... if you're running Ubuntu, you might want to go back and get the Linux version of the examples instead. (the differences are very slight, but important!) Dr. Carter mentions on his web page that he uses Linux as a primary development platform. So we know that's going to work. :) I honestly think you'll find it easier.

TmX has done us a big favor by reminding us of that magical incantation: "apt-get"! There was a guy, I forget his name, who was complaining that he'd spent all day - maybe it was several days - trying to install Nasm on Ubuntu, and couldn't get it to work. Someone gave him that clue. I usually run Slackware, but I booted Ubuntu from a live CD, just to try this out. "sudo apt-get install nasm", and Nasm was ready to go in about ten seconds. Nice system!

I don't know what "build-essential" gets, but it's what you want. "gcc" stands for Gnu Compiler Collection. There's more to it than just a C compiler - Fortran... Java, I think - a bunch of them. Huge package! And it still doesn't include a linker! "ld" is part of the "binutils" package - which includes other stuff you'll want. I expect this stuff to "be there" in Linux - type "ld", and if it says "no input files", you've already got it. "sudo apt-get install build-essential" will probably update it to the latest version, so is probably worth doing anyway. Thanks TmX!

A linker is a tool designed to do a specific job. We can do that job without a linker, if we want to. We can drive a nail with a rock... but a hammer works better. If you really want to write programs using just Nasm, I can show you examples for dos (easy), Linux, even Windows! But I don't think it's the best way to do it.

Dr. Carter's tut doesn't involve any "C programming" at all, and you really only need the compiler once, to compile "driver.c". After that, you could get by with just a linker (but it's easier to let the compiler figure out the command-line to hand the linker :) If you really don't want to mess with C at all, this is not the tut for you. There are other ways to learn... you could read the book and not run the examples, I suppose. :) I see the book has been translated into a bunch of languages - and is available in hard copy. Congratulations, Dr. Carter!

Best,
Frank


Offline dstudentx

  • Jr. Member
  • *
  • Posts: 18
Re: drpaulcarter.com help
« Reply #9 on: February 15, 2010, 09:44:47 PM »
that for the enormous help.  Ive done every thing you have suggested but I get an error "driver.c: file not recognized: file format not recognized"  How do I go about getting it to recognize .c files

Offline Frank Kotler

  • NASM Developer
  • Hero Member
  • *****
  • Posts: 2667
  • Country: us
Re: drpaulcarter.com help
« Reply #10 on: February 15, 2010, 10:12:56 PM »
I'm not clear what "it" is that isn't recognizing "driver.c". The compiler? It sounds to me like something you'd get from a linker. If you're trying Keith's suggestion of linking against msvcrt.dll, that might happen. I guess we could work out a "driver.asm" that would assemble into "driver.obj" and link against "first.obj" and "asm_io.obj". All it does is call "asm_main". Maybe just telling the linker that "asm_main" is the entrypoint would work? Better not get too far afield from the way the examples are supposed to work...

I really don't know what to suggest, at this point. Just what did you type to get that error message?

Best,
Frank


Offline dstudentx

  • Jr. Member
  • *
  • Posts: 18
Re: drpaulcarter.com help
« Reply #11 on: February 15, 2010, 10:32:43 PM »
I tried this


and also this
; nasm -f elf first.asm
cl -o first first.o driver.c asm_io.o

Offline Frank Kotler

  • NASM Developer
  • Hero Member
  • *****
  • Posts: 2667
  • Country: us
Re: drpaulcarter.com help
« Reply #12 on: February 16, 2010, 01:41:10 AM »
I didn't catch the first "this", and I'm confused whether you're doing this in Linux or Windows. "nasm -f elf ..." would suggest Linux, but "cl" is the MS compiler for Windows. Feeding the output of "nasm -f elf" to a windows compiler could produce "unrecognized file format"... but not from "driver.c".

For Windows:

nasm -f win32 -dCOFF_TYPE asm_io.asm
nasm -f win32 -dCOFF_TYPE first.asm
cl first.obj driver.c asm_io.obj

For Linux:

nasm -f elf -dELF_TYPE asm_io.asm
nasm -f elf -dELF_TYPE first.asm
gcc -o first first.o driver.c asm_io.o

Tell us which one of those you're trying, and where this error message appears. (it isn't Nasm, so I guess we know that :) The exact spelling of error messages can be a valuable clue. If the linker (the compiler invokes the linker after it's done) says "unresolved external _printf", you know you've got underscores, and don't want 'em. If it says "unresolved external printf", you haven't got underscores, and need 'em. That's the purpose of the "-dELF_TYPE" and "-dCOFF_TYPE" (there's an "OBJ_TYPE" too, but I don't think you'll need it...). A nuisance just 'cause C can't keep its underscores standardized, but we gotta fix it for 'em. (I understand OpenWatcom spells it "printf_"!)

Your mission, if you choose to accept it.... Good Luck! :)

Best,
Frank


Offline dstudentx

  • Jr. Member
  • *
  • Posts: 18
Re: drpaulcarter.com help
« Reply #13 on: February 16, 2010, 04:46:55 AM »
You have no idea how much I appreciate the help.
been trying to load this dr paul carter code. with ubuntu (linux).
When i try

cl -o first first.o driver.c asm_io.o

I get this message

Unrecognized command line argument 'first.o

When I tried
nasm -f elf -dELF_TYPE asm_io.asm
nasm -f elf -dELF_TYPE first.asm
gcc -o first first.o driver.c asm_io.o

when I used
gcc -o first first.o driver.c asm_io.o
I got this message

/tmp/ccwFBbkM.o: In function 'main'
driver.c:(.text+0xa): undefined reference to 'asm_main'
collect2: ld returned l exit status

I loaded nasm through sudo and cl-launch
this is driving me crazy.

« Last Edit: February 16, 2010, 05:15:05 AM by dstudentx »

Offline Keith Kanios

  • Full Member
  • **
  • Posts: 383
  • Country: us
    • Personal Homepage
Re: drpaulcarter.com help
« Reply #14 on: February 16, 2010, 06:23:59 AM »
A study of the Makefile supplied with Dr. Carter's linux-ex package suggests the following commands:

Code: [Select]
nasm -f elf -o first.o first.asm
nasm -f elf -d ELF_TYPE -o asm_io.o asm_io.asm
gcc -c -o driver.o driver.c
gcc -o first driver.o first.o asm_io.o

I've confirmed that the above sequence of commands assembles/compiles/links as desired on Ubuntu 8.04 (32-bit) with NASM 2.07 and a recent version of the GNU Toolchain.

Also, and as previously indicated, CL (CL.EXE) is a compiler for Windows. Running cl (cl-launch) on Linux invokes Common Lisp.