Question

Dans mon projet, je dois utiliser l'assembleur en ligne, mais il faut être Nasm, parce que je ne suis pas trop familier avec GAS.
Mon essai:

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);
}

Il y a une façon de le faire, mais en utilisant Nasm au lieu du gaz?

Je pense que je dois ajouter un argument lors de la compilation.

Était-ce utile?

La solution

J'ai fait un rapide sur Google 'nasm + gcc', un coup d'oeil ici , ici et .

En bref les commutateurs à utiliser pour nasm afin de relier avec l'objet compilé gcc est:

nasm -f elf

Edit: ci-dessus était absolument hors de propos que Nathan cherchait une syntaxe de gaz similaire à l'extrait de code dans la question..here est ma tentative de la version GAS'ified ...

void DateAndTime()
{
   int RTCaddress, RTCdata, RTCtimeSecond, RTCtimeHour, RTCtimeMinute, RTCtimeDay, RTCtimeMonth, RTCtimeYear;
   // Set RTCaddress and RTCdata respectively first...
   RTCaddress = 0x70;
   RTCdata = 0x71; 
   asm
   (
.l1:    
    movb $10, %al           ;Get RTC register A
    out %al, RTCaddress        ; Think RTCaddress needs to be declared...
    in RTCdata, %al            ; RTCdata needs to be declared
    test $80, %al            ;Is update in progress?
    jne .l1             ; yes, wait

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

    movb $2, %al         ;Get minutes (00 to 59)
    out %al, RTCaddress
    in RTCdata, %al
    movb %al, [RTCtimeMinute]

    movb $4, %al         ;Get hours (see notes)
    out %al, RTCaddress
    in RTCdata, %al
    movb %al, [RTCtimeHour]

    movb $7, %al         ;Get day of month (01 to 31)
    out %al, RTCaddress
    in RTCdata, %al
    movb %al, [RTCtimeDay]

    movb $8, %al         ;Get month (01 to 12)
    out %al, RTCaddress
    in RTCdata, %al
    movb %al, [RTCtimeMonth]

    movb $9, %al         ;Get year (00 to 99)
    out %al, RTCaddress
    in RTCdata, %al
    movb %al, [RTCtimeYear]

    ret);

A en juger par les données du BIOS où l'horloge RTC est, les ports utilisés est 0x70, 0x71 que je l'ai utilisé ici ... Je peux me tromper ...

Autres conseils

GCC utilise la syntaxe AT & T alors que MSNA utilise la syntaxe Intel.

Si vous vous trouvez devez convertir manuellement entre les deux formats les outils objdump et NDISASM seront de grande utilité,. Il suffit de se rassembler dans le format actuel, désassembler au format cible, puis réparer toute machine généré par la folie ajoutée désassembleur.

Si vous allez AT & T syntaxe spécifique, il peut être utile d'examiner le démontage dans GDB au lieu d'utiliser objdump.

Comme ce arrivé en tête de ma recherche, je vais ajouter les informations pertinentes:

Allez voir      Puis-je utiliser la syntaxe Intel assembleur x86 avec GCC?

GCC a également "-fverbose-asm", "-fno-asynchrone dérouleur-tables" et "-fconserve-pile" ce qui peut rendre l'assembleur généré une lecture plus facile.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top