Programming in c and assembly language: Compilers and alternatives for PC

Pincha aquí para verlo en español

At the time of writing this tutorial the main alternatives to program in c and mixing lines of assembly code with the code in c are z88dk and SDCC. Another alternative is to use SDCC to compile and generate an assembler file, then use SDCC2Pasmo to convert and then use Pasmo to assemble/link. On the other hand we can program in assembly directly and use Pasmo. Let's compare these alternatives:

 

  • z88dk: A c compiler for PC (Linux, MacOS X, Solaris, BeOS, Win32, Win16 and MSDOS) that generates code for z80 and has an assembler / linker. It has a good part of the c standard library implemented and supports lots of platforms including Amstrad CPC, for which, for example, supports file handling, console (read keyboard, screen print on ...). That is, using z88dk can compile and generate a binary executable directly on Amstrad CPC.
  •  

  • SDCC: A c compiler for PC (Linux, Windows and Mac OS X) that generates code for Intel 8051, Maxim 80DS390, Zilog Z80, Z180, Motorola 68HC08 Rabbit 2000, and has an assembler / linker for each of these platforms. Generates code 'generic' for those platforms, so in the case of Amtrad not executed directly, we must make some changes we'll see later to use it for the CPC. It also includes their own implementation of the c standard library, but as a generic implementation can not, for example, directly print text on screen.
  •  

  • SDCC + SDCC2Pasmo + Pasmo: On the Web http://www.norecess.net there are some good tutorials for using this method. We use SDCC to generate assembly code from our code in c, then we use SDCC2Pasmo to 'translate' this code to Maxam format, then use Pasmo to compile and generate the final binary. I think this method is used for people that really almost only use assembler, since it is very limited the use of the code in c, for the simple reason that the assembly code generated by SDCC includes only our code in c, but not has included anything from the library of c, so we can not use the usual functions of c (memory management, strings, etc.), we can not, for example, doing an integer division, or many other things as the final binary compiled by Pasmo fails on execution when trying to 'jump' to these functions ... I think this method is more like a algorithms code converter from c to assembly code.
  •  

  • Pasmo: If you want to program directly in assembly, Pasmo is a great option, which allows for example to generate binary with Amsdos header (directly runs in Amstrad CPC).

 

www.CPCMania.com 2012