Sunday, March 15, 2009

C's Interface with Assembly Language

Writing assembly codes is tedious and difficult. You have to be closely oriented with the language before you can actually write a running code.

We can use interrupt commands to request our processor to halt its current operation and work on the requested action we made.

We have two types of interrupts: hardware and software interrupts. Hardware interrupts are made by our peripheral devices like printer and mouse and keyboard while software interrupts are codes that we write.

We can write interrupts with assemblers or DEBUG command for simpler codes. We can however, embed assembly codes in our C program. Do check the sample code of interrupts written by Niloy Mondal.

Check the sample program.

Click the link to view/hide more.

[+/-] show/hide

#include dos.h /*Enclose this in <> . The dos.h allows us to generate interrupts*/
void main()
char *message = "Interrupt Programming$";
_DX=(int) message;

Now compile and run this program the usual way you do it with other C programs. Take note that _AH=9 line assigns 9 to register AH and _DX line is to store the address of our message to register DX. The geninterrupt line is to create interrupt 21 where 0x denotes hexadecimal value.