I am using NASM, x86 and it give me this error and I don’t understand why
%include "io.inc"
section .data
msg: db "hello world",0
msg2: db 13
count: dw 13
section .text
extern printf
global CMAIN
CMAIN:
push ebp
mov ebp,esp
mov eax,msg
mov ebx,count
mov esi,0
mov edi,0
add edi,count
dec edi
again:
mov eax, msg[esi]
mov msg2[edi],eax
inc esi
dec edi
loop again
call printf
mov esp,ebp
pop ebp
ret
pirho
11.1k12 gold badges44 silver badges68 bronze badges
asked Nov 2, 2017 at 11:03
3
Because those two lines are not in NASM syntax.
The mov eax, msg[esi] is almost parsed as mov eax,msg (load eax with address of msg), but then unexpected [esi] happens instead of new line.
The mov msg2[edi],eax is hard to guess, what it is like for parser (mov immediate,eax doesn’t exist), but nothing legal either.
If you want to work with memory values, put whole address calculation inside brackets, like:
mov eax, [msg+esi]
mov [msg2+edi], eax
See NASM documentation — 3.3 Effective Addresses for full syntax of memory operands.
answered Nov 2, 2017 at 11:15
Ped7gPed7g
16.1k2 gold badges28 silver badges61 bronze badges
Syntactically, using NASM, there is no PTR keyword. Removing those allows the code to compile up to the undefined ___main. For example:
push ebp
mov ebp, esp
and esp, -16
sub esp, 16
call ___main: ; semi-colon starts comment (should be colon)
mov DWORD [esp+12], 753664
mov eax, DWORD [esp+12]
mov BYTE [eax], 65
leave
ret
Then compiling with:
$ nasm -felf -o asm_recompile.o asm_recompile.asm
The only error returned is:
asm_recompile.asm:5: error: symbol `___main' undefined
Generally, NASM assembly programs require:
section .text
global _start
_start:
Note: Just because you compile to assembly with gcc, do not expect to be able to simply compile the code back to a working elf executable using NASM. gcc by default generates AT&T syntax that is incompatible with NASM. Even telling gcc to output assembly using the -masm=intel option to produce intel format assembly will not compile as-is in NASM. gcc uses as as the assembler. You will have varying luck using as as well, due to the myriad of compiler scripts and options gcc uses by default. The best examination of the process you can get with gcc is to compile your c program to executable using the -v, --verbose option. That will show all of the compiler commands gcc uses to generate the assembly associated with the c code.
Здравствуйте, я только начинаю изучать ассемблер. Есть код программы, пытаюсь его скомпилировать:
Код программы
.model tiny
.286
.data
msg db 'Hello World11111111111111111111111111111111111111111111111111111111'
position word 0312h
color db 03dh
count word 0043h
.code
org 100h
start:
call clrscr
mov ax, 0 ;word
mov ax, 1300h
mov bp, offset msg
mov cx, count
mov dx, position
mov bl, color
int 10h
mov ah, 02h
mov dx, position
sub dx, 0101h
int 10h
mov ah, 09h
mov al, 0c9h
mov cx, 1
int 10h
mov ah, 02h
inc dx
int 10h
mov ah, 09h
mov al, 0cdh
mov cx, count
int 10h
add dx, count
mov ah, 02h
int 10h
mov ah, 09h
mov al, 0bbh
mov cx, 1
int 10h
mov ah, 02h
add dx, 0100h
int 10h
mov ah, 09h
mov al, 0bah
mov cx, 1
int 10h
mov ah, 02h
sub dx, count
dec dx
int 10h
mov ah, 09h
int 10h
mov ah, 02h
add dx, 0100h
int 10h
mov ah, 09h
mov al, 0c8h
int 10h
mov ah, 02h
inc dx
int 10h
mov ah, 09h
mov al, 0cdh
mov cx, count
int 10h
mov ah, 02h
add dx, count
int 10h
mov ah, 09h
mov al, 0bch
mov cx, 01h
int 10h
mov ah, 02h
mov dx, 1801h
int 10h
int 20h
clrscr:
mov ah, 0h
mov al, 03h
int 10h
ret
end start
Компилирую командой: nasm -f bin first.asm -o first.com
Получаю следующие ошибки:
D:Assembler>nasm -f bin first.asm -o first.com
first.asm:1: error: attempt to define a local label before any non-local labels
first.asm:1: error: parser: instruction expected
first.asm:2: warning: label alone on a line without a colon might be in error [-w+orphan-labels]
first.asm:2: error: attempt to define a local label before any non-local labels
first.asm:3: warning: label alone on a line without a colon might be in error [-w+orphan-labels]
first.asm:3: error: attempt to define a local label before any non-local labels
first.asm:5: error: parser: instruction expected
first.asm:7: error: parser: instruction expected
first.asm:8: warning: label alone on a line without a colon might be in error [-w+orphan-labels]
first.asm:16: error: comma, colon, decorator or end of line expected after operand
first.asm:95: error: parser: instruction expected
Мои знакомые просто как-то переносят этот код в DoxBOX и там у них всё прекрасно работает. Подскажите пожалуйста как можно исправить код программы, чтобы он правильно компилировался NASM-ом. Спасибо.
Issue
I am programming in c and i compiled a c code to assembly code but when i re-compile the code with the NASM assembler , it is giving me a error
Expected comma , colon , decorator or end of line expected after operand . This occurs in
line number 6 , line number 7 and 8 . Please help me with this .
push ebp
mov ebp, esp
and esp, -16
sub esp, 16
call ___main ;
mov DWORD PTR [esp+12], 753664
mov eax, DWORD PTR [esp+12]
mov BYTE PTR [eax], 65
leave
ret
Thanks,
Solution
Syntactically, using NASM, there is no PTR keyword. Removing those allows the code to compile up to the undefined ___main. For example:
push ebp
mov ebp, esp
and esp, -16
sub esp, 16
call ___main: ; semi-colon starts comment (should be colon)
mov DWORD [esp+12], 753664
mov eax, DWORD [esp+12]
mov BYTE [eax], 65
leave
ret
Then compiling with:
$ nasm -felf -o asm_recompile.o asm_recompile.asm
The only error returned is:
asm_recompile.asm:5: error: symbol `___main' undefined
Generally, NASM assembly programs require:
section .text
global _start
_start:
Note: Just because you compile to assembly with gcc, do not expect to be able to simply compile the code back to a working elf executable using NASM. gcc by default generates AT&T syntax that is incompatible with NASM. Even telling gcc to output assembly using the -masm=intel option to produce intel format assembly will not compile as-is in NASM. gcc uses as as the assembler. You will have varying luck using as as well, due to the myriad of compiler scripts and options gcc uses by default. The best examination of the process you can get with gcc is to compile your c program to executable using the -v, --verbose option. That will show all of the compiler commands gcc uses to generate the assembly associated with the c code.
Answered By — David C. Rankin
Содержание
- Compilation problem following examples #312
- Comments
- Анализ ошибок NASM, ожидается инструкция
- 1 ответы
Compilation problem following examples #312
Hi,
I’m trying to follow the fuzzing example for libjpeg-turbo (https://github.com/google/honggfuzz/tree/master/examples/libjpeg), and it appears to fail at compiling libjpeg using honggfuzz’s compilers. Below are the steps I used and the errors the makefile gives.
- Compiled hongfuzz
- Got libjpeg-turbo source with $apt-get source libjpeg-turbo
- Got required tools to config with $sudo apt-get install autoconf libtool nasm
- Run $autoreconf because of an automake version mismatch error when trying to config libjpeg-turbo. Autoreconf fixes it.
- Configured libjpeg-turbo with CC=../honggfuzz/hfuzz_cc/hfuzz-clang CXX=../honggfuzz/hfuzz_cc/hfuzz-clang++ CFLAGS=»-fsanitize=address» ./configure
- Run $make -j$(nproc)
As far as I can tell, the «ignoring unknown tag NASM» error should not cause issues, but the other errors seem to be syntax-related. Honggfuzz’s compiler seems to see a lot of «comma, colon, decorator or end of line expected after operand», «symbol not defined before use», and «unable to multiply two non-scalar objects» errors.
I’ve compiled libjpeg-turbo using AFL’s compilers before, and AFL seems to compile with no issues, so this can’t be a problem with libjpeg-turbo.
What can I do to compile libjpeg-turbo with Honggfuzz’s instrumentation? Any help is appreciated.
The text was updated successfully, but these errors were encountered:
Источник
Анализ ошибок NASM, ожидается инструкция
Я задал похожий вопрос здесь но я сменил ассемблеры, и вопрос почти полностью изменился, поэтому, чтобы избежать беспорядка, я публикую совершенно новый вопрос. Короче говоря, у меня Windows 7, я только что установил NASM и пытаюсь собрать листинг кода из книги Майкла Абраша под названием Zen of Assembly. Вот код листинга:
Я добавил nasm.exe в свой путь, сохранил этот файл как listing1.asm и попытался использовать следующую команду CMD для его сборки:
Однако он не собрался и вместо этого выдал следующие ошибки:
Не знаю, что мне здесь делать; Я пытался немного погуглить, но ничего не придумал. Кто-нибудь признает эти ошибки?
задан 20 июля ’12, 04:07
Это код для старой доброй MS-DOS. Он не будет работать под Windows 7, где вам не разрешено перенастраивать оборудование из пользовательской программы. — Bo Persson
1 ответы
Этот язык ассемблера — MASM, а не NASM.
Во-первых, сегменты NASM определяются по-разному.
И это заявление «ПРЕДПОЛАГАЕТ». У вас, должно быть, есть древняя книга. Это старый, старый код MASM. Навевает воспоминания о начале 1980-х!
Между NASM и MASM есть много различий, и ваш код требует немалой работы для переноса. Если вы хотите перенести этот код MASM на NASM, см. MASM / NASM Различия или документацию по NASM или погуглите «NASM vs MASM»
TL;DR: вы пишете код MASM, а не NASM.
ответ дан 23 мая ’17, 12:05
Большое спасибо, именно то, что я искал. — Линкольн Бергесон
Не тот ответ, который вы ищете? Просмотрите другие вопросы с метками assembly x86 nasm or задайте свой вопрос.
Источник
I am trying to reassemble code reversed from an executable using radare2. I have managed to extract the asm and am using nasm for reassembling.
The question is, the code also contains commands like
byte ptr [esi],pushal, fucomi st(3) and sqrtps xmm5, xmmword [edx - 1] which I’m unfamiliar with.
I tried assembling with the nasm -felf -o command. However, I’m getting the following errors.
test.asm:68: error: comma, colon, decorator or end of line expected after operand
test.asm:69: error: comma, colon, decorator or end of line expected after operand
test.asm:85: error: comma, colon, decorator or end of line expected after operand
test.asm:133: error: comma, colon, decorator or end of line expected after operand
test.asm:167: error: impossible combination of address sizes
test.asm:167: error: invalid effective address
test.asm:298: error: symbol `pushal' redefined
test.asm:423: error: comma, colon, decorator or end of line expected after operand
test.asm:637: error: comma, colon, decorator or end of line expected after operand
test.asm:802: error: symbol `pushal' redefined
According to this stackoverflow post, the keyword ptr does not exist in nasm and it suggested that the word be removed. Doing that resolved a few errors. Now I have the following errors:
test.asm:68: error: comma, colon, decorator or end of line expected after operand
test.asm:69: error: comma, colon, decorator or end of line expected after operand
test.asm:85: error: comma, colon, decorator or end of line expected after operand
test.asm:133: error: comma, colon, decorator or end of line expected after operand
test.asm:298: error: symbol `pushal' redefined
test.asm:423: error: comma, colon, decorator or end of line expected after operand
test.asm:637: error: comma, colon, decorator or end of line expected after operand
test.asm:802: error: symbol `pushal' redefined
Since I have no idea what pushal and sqrtps mean, I’m reluctant to remove them from the code. Could someone please explain what these commands mean?
Additionally suggestions on how I can get this as a compilable error-free code are also welcome.
EDIT:
Following user blabb s suggestion, i replaced pushal with pushad and now I have only 2 errors
test.asm:80: error: comma, colon, decorator or end of line expected after operand
test.asm:127: error: comma, colon, decorator or end of line expected after operand
The 2 lines in question are:
fucomi st(3)
and
sqrtps xmm5, xmmword [edx - 1]
any suggestions as to how to handle this?
EDIT 2:
including lines 76-83
pop esi
int3
sti
xor ebx,ebx
fucomi st(0),st(3)
jmp 0x400299
pop es
xor ebx, ebx
and lines 122-132
add cl, bh
iretd
mov dr0, ebx
and eax, ebx
ret
push 0xf
sqrtps xmm5, xmmword [edx - 1]
push ecx
push 0xffffffffffffffff
call dword [ecx + 0x51]
push ecx
EDIT3:
Based on user blabb s suggestion and also by referring the NASM docs, I found that NASM does not accept st(0),st(3) and instead it accepts st0,st3. Now only one error left.
test.asm:127: error: comma, colon, decorator or end of line expected after operand
Still did not understand how to handle this.
|
Saraharas 0 / 0 / 0 Регистрация: 14.10.2014 Сообщений: 53 |
||||
|
1 |
||||
|
07.08.2015, 20:30. Показов 3148. Ответов 9 Метки нет (Все метки)
Здравствуйте! Помогите, пожалуйста, разобраться с ошибкой. На 13 и 15 строке ошибка «error: comma, colon or end of line expected». Подскажите, пожалуйста, как исправить.
__________________
0 |
|
Mikl___ Ушел с форума 15703 / 7377 / 980 Регистрация: 11.11.2010 Сообщений: 13,321 |
||||
|
08.08.2015, 13:57 |
2 |
|||
|
попробуй вот так
0 |
|
Saraharas 0 / 0 / 0 Регистрация: 14.10.2014 Сообщений: 53 |
||||
|
08.08.2015, 15:53 [ТС] |
3 |
|||
|
Mikl___, попробовала Ваш вариант, теперь выдает ошибки: «error: invalid combination of opcode and operands» на 12 и 14 строчке.
0 |
|
Mikl___ Ушел с форума 15703 / 7377 / 980 Регистрация: 11.11.2010 Сообщений: 13,321 |
||||
|
09.08.2015, 06:21 |
4 |
|||
|
Saraharas,
0 |
|
Charles Kludge Клюг 7673 / 3188 / 382 Регистрация: 03.05.2011 Сообщений: 8,380 |
||||
|
09.08.2015, 11:56 |
5 |
|||
|
Собственно, если nasm’у указать ключик -f win или -f elf , то накаких ошибок:
1 |
|
Saraharas 0 / 0 / 0 Регистрация: 14.10.2014 Сообщений: 53 |
||||
|
09.08.2015, 13:46 [ТС] |
6 |
|||
|
Mikl___, диалект NASM Добавлено через 16 минут
0 |
|
Ушел с форума 15703 / 7377 / 980 Регистрация: 11.11.2010 Сообщений: 13,321 |
|
|
09.08.2015, 14:10 |
7 |
|
Saraharas,
0 |
|
0 / 0 / 0 Регистрация: 14.10.2014 Сообщений: 53 |
|
|
09.08.2015, 14:32 [ТС] |
8 |
|
Mikl___, так выводит 993183617.625000, т. е. тоже самое.
0 |
|
Charles Kludge Клюг 7673 / 3188 / 382 Регистрация: 03.05.2011 Сообщений: 8,380 |
||||
|
09.08.2015, 14:51 |
9 |
|||
|
Решение
Подскажите, пожалуйста, в чем ошибка. Дело в том, что printf не умеет выводить числа с плавающей запятой одинарной точности(dword), а только двойной(qword). Так что придётся извращаться:
1 |
|
0 / 0 / 0 Регистрация: 14.10.2014 Сообщений: 53 |
|
|
09.08.2015, 15:20 [ТС] |
10 |
|
Charles Kludge, Спасибо большое! Все получилось!
0 |
I am using NASM, x86 and it give me this error and I don’t understand why
%include "io.inc"
section .data
msg: db "hello world",0
msg2: db 13
count: dw 13
section .text
extern printf
global CMAIN
CMAIN:
push ebp
mov ebp,esp
mov eax,msg
mov ebx,count
mov esi,0
mov edi,0
add edi,count
dec edi
again:
mov eax, msg[esi]
mov msg2[edi],eax
inc esi
dec edi
loop again
call printf
mov esp,ebp
pop ebp
ret
Because those two lines are not in NASM syntax.
The mov eax, msg[esi] is almost parsed as mov eax,msg (load eax with address of msg), but then unexpected [esi] happens instead of new line.
The mov msg2[edi],eax is hard to guess, what it is like for parser (mov immediate,eax doesn’t exist), but nothing legal either.
If you want to work with memory values, put whole address calculation inside brackets, like:
mov eax, [msg+esi]
mov [msg2+edi], eax
See NASM documentation — 3.3 Effective Addresses for full syntax of memory operands.
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and
privacy statement. We’ll occasionally send you account related emails.
Already on GitHub?
Sign in
to your account
Closed
Mardoxx opened this issue
Oct 17, 2017
· 16 comments
Comments
x86 Native Tools Command Prompt for VS 2017
> perl Configure VC-WIN32 --prefix="C:UsersOwneropenssl-1.0.2l"
> msdo_ms.bat
> nmake -f msnt.mak
Assembling: tmp32sha1-586.asm
tmp32sha1-586.asm(1432) : error A2070:invalid instruction operands
tmp32sha1-586.asm(1576) : error A2070:invalid instruction operands
NMAKE : fatal error U1077: '"C:Program Files (x86)Microsoft Visual Studio2017EnterpriseVCToolsMSVC14.11.25503binHostX86x86ml.EXE"' : return code '0x1'
Stop.
> where ml
> C:Program Files (x86)Microsoft Visual Studio2017EnterpriseVCToolsMSVC14.11.25503binHostX86x86ml.exe
> where cl
> C:Program Files (x86)Microsoft Visual Studio2017EnterpriseVCToolsMSVC14.11.25503binHostX86x86cl.exe
Also tried with x64_x86 Cross Tools Command Prompt for VS 2017, same results.
Mardoxx
changed the title
Compiling 1.0.2l with VS2017 fails with A2070:invalid instruction operands
Compiling 1.0.2l with VS2017 for x86 fails with A2070:invalid instruction operands
Oct 17, 2017
x64 compiles okay, but fails at linking:
x64 Native Tools Command Prompt for VS 2017
> perl Configure VC-WIN64A --prefix=C:Build-OpenSSL-VC-64
> msdo_win64a
> nmake -f msnt.mak
tmp32x86_64cpuid.obj : fatal error LNK1112: module machine type 'x64' conflicts with target machine type 'x86'
NMAKE : fatal error U1077: '"C:Program Files (x86)Microsoft Visual Studio2017EnterpriseVCToolsMSVC14.11.25503binHostX64x64lib.EXE"' : return code '0x458'
Stop.
Also tried with x86_x64 Cross Tools Command Prompt for VS 2017, same results.
1.0.2k fails identically too.
1.0.2k compiles and links fine under x86 with no-asm
1.0.2l does not.
From INSTALL.W32:
- Netwide Assembler, a.k.a. NASM, available from http://nasm.sourceforge.net/
is required if you intend to utilize assembler modules. Note that NASM
is now the only supported assembler.
Please try installing NASM and use msdo_nasm.bat instead of msdo_ms.bat
... lots more errors/warns
tmp32sha1-586.asm:3962: error: comma, colon, decorator or end of line expected after operand
tmp32sha1-586.asm:3963: warning: `PTR' is not a NASM keyword [-w+ptr]
tmp32sha1-586.asm:3963: error: comma, colon, decorator or end of line expected after operand
tmp32sha1-586.asm:3964: warning: `PTR' is not a NASM keyword [-w+ptr]
tmp32sha1-586.asm:3964: error: comma, colon, decorator or end of line expected after operand
tmp32sha1-586.asm:3970: error: symbol `__sha1_block_data_order_avx' redefined
tmp32sha1-586.asm:3970: error: parser: instruction expected
tmp32sha1-586.asm:3972: error: parser: instruction expected
tmp32sha1-586.asm:3983: error: parser: instruction expected
tmp32sha1-586.asm:3985: error: parser: instruction expected
tmp32sha1-586.asm:3986: error: parser: instruction expected
tmp32sha1-586.asm:3987: warning: label alone on a line without a colon might be in error [-w+orphan-labels]
NMAKE : fatal error U1077: '"c:Program Files (x86)NASMnasm.EXE"' : return code '0x1'
Stop.
NMAKE : fatal error U1077: 'if' : return code '0x2'
Stop.
NMAKE : fatal error U1077: '"c:Program Files (x86)Microsoft Visual Studio2017EnterpriseVCToolsMSVC14.11.25503binHostX86x86nmake.exe"' : return code '0x2'
Stop.
NMAKE : fatal error U1077: '"c:Program Files (x86)Microsoft Visual Studio2017EnterpriseVCToolsMSVC14.11.25503binHostX86x86nmake.exe"' : return code '0x2'
Stop.
Sorry should be nmake -f msnt.mak clean on windows
Was just about to say 😄!
One min.
If OpenSSL only supports building with nasm, why not remove do_ms.bat? @mattcaswell
It’s a good question. I’ll leave it to @dot-asm to answer.
do_nasm.bat assumes that you have configured with asm acceleration enabled, i.e. no no-asm.
do_ms.bat assumes that you have configured with no-asm.
Here’s the piece of text that actually says so, although maybe not in the clearest of ways…
@levitte so you should never run do_ms.bat without prior configuration of no-asm? Thanks
As for x64 thing, see #4508.


Сообщение было отмечено Saraharas как решение
