1. 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.
    Dismiss Notice

Problem combining Assembly and C

Discussion in 'Microcontrollers' started by avinsinanan, Mar 20, 2003.

  1. avinsinanan

    avinsinanan New Member

    Joined:
    Mar 17, 2003
    Messages:
    22
    Likes:
    0
    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
     
  2. kinjalgp

    kinjalgp Active Member

    Joined:
    Oct 28, 2002
    Messages:
    1,851
    Likes:
    3
    Location:
    INDIA/USA
    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.
     
  3. Pilot

    Pilot New Member

    Joined:
    Jan 5, 2003
    Messages:
    191
    Likes:
    0
    Location:
    England
    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.
     
  4. dave

    Dave New Member

    Joined:
    Jan 12, 1997
    Messages:
    -
    Likes:
    0


     
  5. kinjalgp

    kinjalgp Active Member

    Joined:
    Oct 28, 2002
    Messages:
    1,851
    Likes:
    3
    Location:
    INDIA/USA

    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.
     
  6. Pilot

    Pilot New Member

    Joined:
    Jan 5, 2003
    Messages:
    191
    Likes:
    0
    Location:
    England

Share This Page