Error too many memory references for mov

Хочу сделать ассемблерную вставку в gcc. Для примера: Где то нашёл что синтаксис у ассемблера другой в Unix-системах.
  • Печать

Страницы: [1]   Вниз

Тема: Ассемблерные вставки в gcc  (Прочитано 4606 раз)

0 Пользователей и 1 Гость просматривают эту тему.

Оффлайн
MaksimM

Хочу сделать ассемблерную вставку в gcc. Для примера:

#include <stdio.h>
int main()
{
int a=5;
asm("mov ax,7");
}
Выводит ошибку:

main.c: Assembler messages:
main.c:5: Error: too many memory references for `mov'
Где то нашёл что синтаксис у ассемблера другой в Unix-системах. Но я только начал Ассемблер изучать и Си. Чё тут для вставок себе в голове кашу делать??? Не могли нормальный ассемблер в gcc вставить??????  :(

Единственно стабильная версия — 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]   Вверх

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
#include <windows.h>
#include <stdio.h>

#include "../license.h"

// add a license
// addlicense.exe file:<filename> add bbuser:<username> bbpass:<password> serial:<serialNumber> access:<accesskey> pass:<gcpassword> priv:<privileges>

// delete a license
// addlicense.exe file:<filename> delete find:<options>

// modify a license
// addlicense.exe file:<filename> modify find:<options> <newoptions>

// unban a license
// addlicense.exe file:<filename> unban find:<options>

// display a license
// addlicense.exe file:<filename> info find:<options>

// parses a command line option.
DWORD parseoption(LICENSE* l,char* option)
{
    if (!memcmp(option,"bbuser:",7))
    {
        strcpy(l->username,&option[7]);
        return LICENSE_CHECK_USERNAME;
    } else if (!memcmp(option,"bbpass:",7))
    {
        strcpy(l->password,&option[7]);
        return LICENSE_CHECK_PASSWORD;
    } else if (!memcmp(option,"serial:",7))
    {
        if ((option[7] == '0') && ((option[8] == 'x') || (option[8] == 'X'))) sscanf(&option[9],"%X",&l->serialNumber);
        else sscanf(&option[7],"%d",&l->serialNumber);
        return LICENSE_CHECK_SERIALNUMBER;
    } else if (!memcmp(option,"access:",7))
    {
        strcpy(l->accessKey,&option[7]);
        return LICENSE_CHECK_ACCESSKEY;
    } else if (!memcmp(option,"pass:",5))
    {
        strcpy(l->password2,&option[5]);
        return LICENSE_CHECK_GC_PASSWORD;
    } else if (!memcmp(option,"priv:",5))
    {
        if ((option[5] == '0') && ((option[6] == 'x') || (option[6] == 'X'))) sscanf(&option[7],"%X",&l->privileges);
        else sscanf(&option[5],"%d",&l->privileges);
        return LICENSE_CHECK_PRIVILEGES;
    }
    return 0;
}

DWORD scanFlags = 0,replaceFlags = 0;

int deletelicenseenumproc(LICENSE_LIST* list,int index,LICENSE* l,long param)
{
    bool success;
    if (DeleteLicense(list,index))
    {
        printf("> > license deleted: %08Xn",l->serialNumber);
        return (-1);
    }
    printf("> > license could not be deleted: %08Xn",l->serialNumber);
    return 1;
}

int modifylicenseenumproc(LICENSE_LIST* list,int index,LICENSE* l,LICENSE* lnew)
{
    bool success;
    printf("> > license modified: %08Xn",l->serialNumber);
    if (replaceFlags & LICENSE_CHECK_USERNAME) strcpy(l->username,lnew->username);
    if (replaceFlags & LICENSE_CHECK_PASSWORD) strcpy(l->password,lnew->password);
    if (replaceFlags & LICENSE_CHECK_SERIALNUMBER) l->serialNumber = lnew->serialNumber;
    if (replaceFlags & LICENSE_CHECK_ACCESSKEY) strcpy(l->accessKey,lnew->accessKey);
    if (replaceFlags & LICENSE_CHECK_GC_PASSWORD) strcpy(l->password2,lnew->password2);
    if (replaceFlags & LICENSE_CHECK_PRIVILEGES) l->privileges = lnew->privileges;
    return 1;
}

int unbanlicenseenumproc(LICENSE_LIST* list,int index,LICENSE* l,long param)
{
    bool success;
    memset(&l->banTime,0,sizeof(FILETIME));
    printf("> > license unbanned: %08Xn",l->serialNumber);
    return 1;
}

int infolicenseenumproc(LICENSE_LIST* list,int index,LICENSE* l,long param)
{
    bool success;
    printf("> blue burst user/pass: %s %sn",l->username,l->password);
    printf("> gc serial/access/password: %08X %s %sn",l->serialNumber,l->accessKey,l->password2);
    printf("> privilege flags/ban time: %08X %08X%08Xnn",l->privileges,l->banTime.dwHighDateTime,l->banTime.dwLowDateTime);
    return 1;
}

int main(int argc,char* argv[])
{
    printf("> fuzziqer software newserv license editornn");

    char filename[MAX_PATH];
    DWORD x,flagsTemp;
    LICENSE_LIST* list;
    LICENSE lold,lnew;
    memset(&lold,0,sizeof(LICENSE));
    memset(&lnew,0,sizeof(LICENSE));

    bool result;
    DWORD action = 0; // 1 = add, 2 = delete, 3 = modify, 4 = unban, 5 = get info
    DWORD numFailures = 0,numChanges;
    for (x = 1; x < argc; x++)
    {
        result = true;
             if (!memcmp(argv[x],"add",3)) action = 1;
        else if (!memcmp(argv[x],"delete",6)) action = 2;
        else if (!memcmp(argv[x],"modify",6)) action = 3;
        else if (!memcmp(argv[x],"unban",5)) action = 4;
        else if (!memcmp(argv[x],"info",4)) action = 5;
        else if (!memcmp(argv[x],"file:",5)) strcpy(filename,&argv[x][5]);
        else if (!memcmp(argv[x],"find:",5))
        {
            flagsTemp = parseoption(&lold,&argv[x][5]);
            if (!flagsTemp)
            {
                printf("> > error: unknown find option: %sn",&argv[x][5]);
                numFailures++;
            } else scanFlags |= flagsTemp;
        } else {
            flagsTemp = parseoption(&lnew,argv[x]);
            if (!flagsTemp)
            {
                printf("> > error: unknown option: %sn",argv[x]);
                numFailures++;
            } else replaceFlags |= flagsTemp;
        }
    }

    list = LoadLicenseList(filename);
    if (!list)
    {
        printf("> > warning: license file not found, creating a new onen");
        list = CreateLicenseList();
        if (!list)
        {
            printf("> > use the [file:<filename>] option to specify the file namen");
            numFailures++;
        } else strcpy(list->filename,filename);
    }
    if (numFailures) return (-1);

    switch (action)
    {
      case 1: // add license
        if (AddLicense(list,&lnew)) printf("> > license addedn");
        else printf("> > error!n");
        break;
      case 2: // delete license
        if (!scanFlags) printf("> > error: no scan flags specifiedn> > use at least one [find:] directiven");
        else {
            numChanges = EnumLicenses(list,scanFlags,&lold,(LicenseEnumProc)deletelicenseenumproc,0);
            printf("> > %d licenses deletedn",numChanges);
        }
        break;
      case 3: // modify license
        if (!scanFlags) printf("> > error: no scan flags specifiedn> > use at least one [find:] directiven");
        else {
            numChanges = EnumLicenses(list,scanFlags,&lold,(LicenseEnumProc)modifylicenseenumproc,(long)(&lnew));
            printf("> > %d licenses modifiedn",numChanges);
        }
        break;
      case 4: // unban license
        if (!scanFlags) printf("> > error: no scan flags specifiedn> > use at least one [find:] directiven");
        else {
            numChanges = EnumLicenses(list,scanFlags,&lold,(LicenseEnumProc)unbanlicenseenumproc,0);
            printf("> > %d licenses unbannedn",numChanges);
        }
        break;
      case 5: // show license
        if (!scanFlags) printf("> > error: no scan flags specifiedn> > use at least one [find:] directiven");
        else {
            numChanges = EnumLicenses(list,scanFlags,&lold,(LicenseEnumProc)infolicenseenumproc,0);
            printf("> > %d licenses listedn",numChanges);
        }
        break;
    }
    if (!SaveLicenseList(list)) printf("> > error: couldn't save the license listn");

    system("PAUSE>NUL");

    return 0;
}

  • 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

Понравилась статья? Поделить с друзьями:
  • Error too many decimal points in number arduino
  • Error too many change security questions requests please try again later
  • Error too many bone influences per vertex
  • Error too many attempts try again later
  • Error too many arguments to function long int random