Problem combining Assembly and C

Status
Not open for further replies.

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
 
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.
 
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.
 
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.
 
Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…