A avinsinanan New Member Mar 20, 2003 #1 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
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 Mar 20, 2003 #2 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.
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.
P Pilot New Member Mar 22, 2003 #3 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.
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 Mar 22, 2003 #4 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.
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.
P Pilot New Member Mar 22, 2003 #5 Kinjalgp I got it wrong. I should not have included the brackets or semi-colon as that denotes a c function and I forgot to push AX. Using the 8086 inline assembler the instruction call printf is valid. See the following example.... https://msdn.microsoft.com/library/...re_calling_c_functions_in_inline_assembly.asp Like I said.. too many years away from C/assembler.
Kinjalgp I got it wrong. I should not have included the brackets or semi-colon as that denotes a c function and I forgot to push AX. Using the 8086 inline assembler the instruction call printf is valid. See the following example.... https://msdn.microsoft.com/library/...re_calling_c_functions_in_inline_assembly.asp Like I said.. too many years away from C/assembler.