views:

527

answers:

2

In my project I need to use inline Assembly, but it need to be Nasm, because I'm not too much familiar with GAS.
My try:

void DateAndTime()
{
   asm
   (.l1:    mov al,10           ;Get RTC register A
    out RTCaddress,al
    in al,RTCdata
    test al,0x80            ;Is update in progress?
    jne .l1             ; yes, wait

    mov al,0            ;Get seconds (00 to 59)
    out RTCaddress,al
    in al,RTCdata
    mov [RTCtimeSecond],al

    mov al,0x02         ;Get minutes (00 to 59)
    out RTCaddress,al
    in al,RTCdata
    mov [RTCtimeMinute],al

    mov al,0x04         ;Get hours (see notes)
    out RTCaddress,al
    in al,RTCdata
    mov [RTCtimeHour],al

    mov al,0x07         ;Get day of month (01 to 31)
    out RTCaddress,al
    in al,RTCdata
    mov [RTCtimeDay],al

    mov al,0x08         ;Get month (01 to 12)
    out RTCaddress,al
    in al,RTCdata
    mov [RTCtimeMonth],al

    mov al,0x09         ;Get year (00 to 99)
    out RTCaddress,al
    in al,RTCdata
    mov [RTCtimeYear],al

    ret);
}

There is any way to do this but using Nasm instead of GAS?

I think I need to add a argument when compiling.

+1  A: 
tommieb75
But I need to be as inline code to be used inside a function.
Nathan Campos
@Nathan@ Ok... sorry for the misleading answer...can you post the actual assembler code and I'll try GAS'ify it?
tommieb75
Nasm code added. **;-)**
Nathan Campos
There may be typos in there...in GAS, the syntax is mnemonic src, dest, MASM/TASM is the reverse i.e. mnemonic dest, src. Mnemonics prefixes are b, s, i, l (byte, short, int, long) respectively. Registers are prefixed with %. Numbers as constants are prefixed with $.
tommieb75
Please have a look here... http://en.wikibooks.org/wiki/X86_Assembly/GAS_Syntax, for further details...that's my basic knowledge of GAS which I have learnt from the above link...
tommieb75
+2  A: 

GCC uses AT&T syntax while NASM uses Intel syntax.

If you find you need to manually convert between the two formats the objdump and ndisasm tools will come in very handy. Just assemble in the current format, disassemble in the target format, then fix up any machine-generated craziness added by the disassembler.

If you're going to AT&T syntax specifically, it may be helpful to look at the disassembly in GDB instead of using objdump.

Dan Olson