• Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

Problem combining Assembly and C

avinsinanan

New Member
Hello I am using TURBO C to read an input valuie from the Parallel Port.

I am putting Assembly language in Turbo C. However the printf statement is not printing the value in the regsiter. WHy?

Here is the code -

# include <stdio.h>
#define PORT_ADDRESS 0x379

void main()
{
for(int i=0;;i++)
{
asm {
MOV DX , 0379H
IN AX,DX
}
printf(DX);
}
}



Why isn't it working?

Thanks
 

kinjalgp

Active Member
I think the last printf should be:
printf(AX);
Since IN instruction puts the value of port in accumulator.

You can also use InportB and OutportB functions defined in conio.h file.
 

Pilot

New Member
Would it not be better to call printf() from within the asm block....

ie.

# include <stdio.h>
#define PORT_ADDRESS 0x379

void main()
{
for(int i=0;;i++)
{
asm {
MOV DX , 0379H
IN AX,DX
call printf();
}
}
}

I await instant correction from anyone - too many years since I did C - too much COBOL recently.
 

kinjalgp

Active Member
There is no keyword called "call" in 'C'. And also you have not passed any parameter to printf() function. So it won't print anything.
 

Latest threads

EE World Online Articles

Loading

 
Top