- Печать
Страницы: [1] Вниз
Тема: Ассемблерные вставки в gcc (Прочитано 4606 раз)
0 Пользователей и 1 Гость просматривают эту тему.
MaksimM
Хочу сделать ассемблерную вставку в gcc. Для примера:
#include <stdio.h>
Выводит ошибку:
int main()
{
int a=5;
asm("mov ax,7");
}
main.c: Assembler messages:
Где то нашёл что синтаксис у ассемблера другой в Unix-системах. Но я только начал Ассемблер изучать и Си. Чё тут для вставок себе в голове кашу делать??? Не могли нормальный ассемблер в gcc вставить???
main.c:5: Error: too many memory references for `mov'
Единственно стабильная версия — LTS, остальные — беты.
kiv
Там AT&T синтакс. То есть надо писать не mov ax, 7, а movw $7, %ax. Так что единственный способ юзать ассемблер с нормальным синтаксисом — это писать ассемблерные процедуры на ассемблере (да хотя бы на моём любимом fasm), компилировать в объектный файл, а потом линковать его с основным файлом.
Grem
$, % нужны для того, чтоб включать в код переменные С, без конфликтов.
$хх — адрес в памяти.
%хх — имя регистра.
mov ax,7
это синтаксис Интела.
Mam(O)n
MaksimM
ну тогда скажите ВСЕ отличия Unix-синтаксиса ассемблера от обычного.
kiv, спс.
Единственно стабильная версия — LTS, остальные — беты.
Mam(O)n
MaksimM
а в этой статье в Википедии все отличия синтаксиса AT&T от «Intel»?
Единственно стабильная версия — LTS, остальные — беты.
- Печать
Страницы: [1] Вверх
|
|
-
Add bookmark
-
#1
As some of you know, I’ve been working on porting some DOS/Windows device drivers to Linux. The piece of code I’m working on now contains mainly blocks of x86 assembly code. I’ve taken it and enclosed it in asm(«»), but I’m getting the following error message (for every assembler call):<BR><BR>Error: Too many memory references for ‘mov'<BR><BR>Below is a code snippet:<BR><BR><pre class=»ip-ubbcode-code-pre»><BR> unsigned char RxData;<BR> asm(«mov dx,Z16C30_CNTL_REG;»<BR> «mov al,RX_STATUS_REG;»<BR> «out dx,AL;»<BR> «mov dx,Z16C30_CNTL_DATA;»<BR>»RXW1: in al,dx;»<BR> «and al,_RX_READY;»<BR> «jz RXW1;»<BR> «mov dx,Z16C30_SER_DATA;»<BR> «in al,dx;»<BR> «mov RxData,al;»)<BR> return(RxData);<BR> </pre><BR><BR>I’ve tried it like this, and I’ve tried giving each line it’s own asm(«»), no difference. Let me know if you guys have any idea what might be causing this….<BR><BR>-glyph78
-
Add bookmark
-
#4
Your code might be correct, but to gcc it is syntactically wrong. Someone had a similar problem a few weeks ago; here is a link to the reply I gave, which has some links I found helpful.<BR><BR>You’ll have to make quite a few changes, but it shouldn’t be too hard after you read those tutorials.<BR><BR>edit: there is more missing than just some % signs
-
Add bookmark
-
#5
There exists a program named, oddly enough, «intel2gas» that will probably suffice.
-
Add bookmark
-
#6
Alright, turns out I’m learning a whole lot more about ASM than I planned….<BR><BR>Intel2GAS worked fairly well. The only problems I’m having involve the fact that you can’t use ‘mov’ to load a register with a local variable. From the documentation I’ve found, you must load the register using extended inline assembly.<BR><BR>So, this:<BR><pre class=»ip-ubbcode-code-pre»><BR>asm mov dx,Z16C30_CNTL_REG<BR>asm mov al,RX_STATUS_REG<BR>asm out dx,AL</pre><BR><BR>becomes:<BR><BR><pre class=»ip-ubbcode-code-pre»><BR>__asm__ («outb %al, %dx»: :»d» (Z16C30_CNTL_REG), «b» (RX_STATUS_REG): «%al», «%dx»);<BR></pre><BR><BR>But the docs say that you can’t load the byte registers (al) like this…..I’m almost there…..just need a little pointing in the right direction. Does this code transformation look correct?<BR><BR>-Scott
-
Add bookmark
-
#7
This seems to compile okay. Is this a syntactically correct replacement for the Intel code shown above?<BR><BR><pre class=»ip-ubbcode-code-pre»> __asm__ («mov %0, %%al nt»<BR> «outb %%al, %%edx nt» : : «d» (Z16C30_CNTL_REG), «r» (RX_STATUS_REG)); </pre><BR><BR>-glyph78