Inline ASM

From: Dan McLeran (dan.r.mcleran_at_seagate.com)
Date: 05/18/04

  • Next message: Ludovic Brenta: "Re: [GNAT] Project manager and C source files"
    Date: 18 May 2004 10:13:54 -0700
    
    

    First of all, let me say that I am using Gnat 3.15p. Now the problem.
    I have a piece of C code that outports 16-bit values to an ISA-bus
    card. It seemed that I should be able to do this from within Ada,
    using the Asm capabilities. I have been able to embed other Asm
    instructions with success but this one is frustrating me. I keep
    getting this error message:

    "Error: suffix or operands invalid for 'out'"

    Although, when I use the -S compiler option, it generates the asm code
    without error and it appears to be correct.

    I have checked the asm output of my C-code and it looks like this:

    out dx, ax

    So, I figured the following Ada code should work. Does anyone see a
    problem here?

    with Ada.Text_IO;
    with System.Machine_Code;
    with Interfaces;

    procedure Main is
        use Ada.Text_IO;
        
        procedure Outport(Address,Value : in Interfaces.Unsigned_16) is
            use System.Machine_Code;
            use Interfaces;
            use ASCII;
        begin
            Asm("out %%dx, %%ax" & LF & HT,
                Inputs =>
    (Unsigned_16'Asm_Input("d",Address),Unsigned_16'Asm_Input("a",Value)));
        end Outport;
        
        Address : Interfaces.Unsigned_16 := 16#110#;
        Value : Interfaces.Unsigned_16 := 16#F#;
        
    begin
        Put(Item => "** Using inline Asm **");
        New_Line;
        Put(Item => "Address = " & Interfaces.Unsigned_16'Image(Address));
        New_Line;
        Put(Item => "Value = " & Interfaces.Unsigned_16'Image(Value));
        New_Line;
        Outport(Address => Address, Value => Value);
    end Main;


  • Next message: Ludovic Brenta: "Re: [GNAT] Project manager and C source files"