Working with the bcc compiler

binford2k's picture

If you've started on the homework for Cpts 460, you've no doubt discovered by now that the bcc compiler sucks little tiny hamster nuts.

The package from the CptS 460 homepage installs over system files, so instead of using it, you should install the package that comes with your distribution. It may be called bcc (Ubuntu) or dev86 (Gentoo) or something similar.

If you have issues with that, you can always go straight to the source and compile it yourself. The homepage for bcc is here: http://homepage.ntlworld.com/robert.debath/

Once you have the compiler running, the first thing that you will notice is the syntax; bcc only understands traditional K&R syntax. (There is a flag for ANSI support, but that support is incomplete.)

Make your functions look like this and you'll be ok:

void mygets(c) char *c;
{
    /* function body */
}

One thing that you will need to watch out for is this. Do not include any system libraries. There's two reasons for this. First, we only get 512 bytes to work with; including libraries would quickly over-run this size limitation. Second, bcc barfs on them anyways and your compile will fail.

To access the functions in the posted assembly file, simply call the function name without the preceding underscore. Don't declare them extern or anything, just use them. Compile both the assembly file and your source file to object files and link them and the calls will work.

Here's an example:

$ bcc -c -Mf -Mc main.c
$ as86 -o boots.o boots.s
$ ld86 -d boots.o main.o /usr/lib/bcc/libc.a

(Make sure to link them in this order too so that the bootstrapper is at the beginning of the image.)

Good luck, post comments if you have any troubles.

Comments

Anonymous's picture

Re: Working with the bcc compiler

Please say something about how to use the compiler. The command 'bcc -o outfile file' can only generate octet stream. Is there any command that may generate excutable file?

binford2k's picture

Re: Working with the bcc compiler

It's not octet. It's just not a complete executable. You'll need to compile to object files and assemble the .s file KC gives you. Once you have these, you'll link them into the final executable.

Here's an example:

$ bcc -c -Mf -Mc main.c
$ as86 -o boots.o boots.s
$ ld86 -d boots.o main.o /usr/lib/bcc/libc.a

(Make sure to link them in this order too so that the bootstrapper is at the beginning of the image.)

binford2k's picture

Re: Working with the bcc compiler

By the way, I compiled this on an Intel Mac a few months ago and forgot to post it.

  • Download the package
  • Untar it:
    • tar -xvzf Dev86src-0.16.17.tar.gz
      cd dev86-0.16.17

  • Configure and build it:
    • make PREFIX=/usr/local config bcc86 unproto copt ld86 as86 lib-386

  • Install it:
    • make install-bcc

bcc and friends are now installed in /usr/local/bin and the libraries are in /usr/local/lib/bcc.

Alternatively, untar the package attached to this comment and install it. 

Enjoy!

AttachmentSize
dev86.pkg_.tar_.gz329.7 KB
binford2k's picture

more information

After some more poking, I've discovered that the ld86 and as86 binaries that are installed on your system come from the same package anyways, so installing his tarball shouldn't hurt your system. Still, a better solution is to install the dev86 package from your distribution rather than plopping random binaries across your filesystem.

Anonymous's picture

Using the -ansi flag, I

Using the -ansi flag, I didn't have any trouble with using the standard C prototypes instead of the K&R style above.

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.