Author Topic: Error: label or instruction expected at start of line  (Read 30018 times)

Offline namea

  • Jr. Member
  • *
  • Posts: 2
Error: label or instruction expected at start of line
« on: June 27, 2011, 08:35:28 AM »

hello.
i'm trying to use nasm on windows7 64bit.

downloaded nasm and also copied a code from example code section of this forum.
but i got error when compiling.
below is picture of error and code.



please help me to understand it.
thanks.

Offline MJaoune

  • Jr. Member
  • *
  • Posts: 94
Re: Error: label or instruction expected at start of line
« Reply #1 on: June 27, 2011, 01:35:26 PM »
Works well on Windows 7 32-bit, with NASM 2.10rc6, here is the code I took from you (I modified it a bit):
Code: [Select]
section .data
msg db "hello world!",0
len equ $-msg

section .text
global ..start
..start: mov edx, len
mov ecx,msg
mov ebx,1
mov eax,4
int 80h

mov ebx,0
mov eax,1
int 80h

I don't think that nasm has a 64bit version of there Assembler, I might be wrong.
try download 2.10rc6 and if it didn't work reply here.

Note: There are many mistakes in this code, try another example, and don't try any example for FASM, since it has a different syntax.
« Last Edit: June 27, 2011, 01:40:58 PM by MJaoune »

Offline brethren

  • Jr. Member
  • *
  • Posts: 28
Re: Error: label or instruction expected at start of line
« Reply #2 on: June 27, 2011, 05:12:05 PM »
Quote
Works well on Windows 7 32-bit, with NASM 2.10rc6, here is the code I took from you (I modified it a bit):

wtf? thats a hello world example for linux. look at the int 80h and the setting up of registers for the calls to sys_write and sys_exit.

Offline JoeCoder

  • Jr. Member
  • *
  • Posts: 72
  • Country: by
Re: Error: label or instruction expected at start of line
« Reply #3 on: June 27, 2011, 06:07:40 PM »
Just a guess but if NASM doesn't support Unicode UTF8 then that would explain the message the OP is getting.
If you can't code it in assembly, it can't be coded!

Offline brethren

  • Jr. Member
  • *
  • Posts: 28
Re: Error: label or instruction expected at start of line
« Reply #4 on: June 27, 2011, 08:36:10 PM »
Quote
I said it assembles well

no you didn't, you said this...

Quote
Works well on Windows 7 32-bit

it can be really frustrating for a new asm programmer at the best of times but telling him that a linux example works well on win 7 is just gonna make the poor guy wanna rip his hair out :D what he needs is a nice simple example that runs on win 7

Offline Frank Kotler

  • NASM Developer
  • Hero Member
  • *****
  • Posts: 2667
  • Country: us
Re: Error: label or instruction expected at start of line
« Reply #5 on: June 27, 2011, 10:44:30 PM »
I ASSume that the line numbers shown to the left of your code do not appear in the disk file? They're just in the display, right? That would do it! Any sort of a typo would likely cause that error. One of my favorites is:

Code: [Select]
mob eax, ebx

Joe suggests UTF8. I think that plain ascii, encoded as UTF8, is... plain ascii. If I'm wrong, that could account for it. Save your source code as plain ascii, if your editor gives you a choice. Regular notepad has a habit of saving your text as "test.asm.txt" if you don't tell it otherwise. That doesn't seem to be happening here. (and would give a different error message)... Some editors like to save as ".doc" format by default, which might cause a problem... I think notepad++ is okay(?).

The example you've got is for Linux, and won't run on any version of Windows. It "should" assemble without complaint, though. The command line you've given Nasm will assemble to a 16-bit, flat binary file, which won't run either...

Find an example for Windows. I think a 32-bit Windows example will run on Win64. Something with "MessageBoxA" in it would be a good one to start with. It'll say "extern MessageBoxA" near the top of it, probably. Then you'll want an appropriate command line for Nasm. "nasm -f win32 test.asm", probably (Nasm will create files in several different output formats). That will ("should") create "test.obj". Then you'll need a linker...

Your best bet might be to grab the NASMX package:

http://sourceforge.net/projects/nasmx/files/nasmx-1.0/windows/

That'll have examples in it, and a linker, which you'll need...

That doesn't really explain the error message... I suspect a typo, or maybe your source file is saved in some "weird" format...

I see Mathi's online... I'll bet he's got this solved!

Best,
Frank


Offline Mathi

  • Jr. Member
  • *
  • Posts: 82
  • Country: in
    • Win32NASM
Re: Error: label or instruction expected at start of line
« Reply #6 on: June 27, 2011, 11:57:46 PM »
Joe is right.

i created two files with the same contents and saved one in UTF-8 and the other in ANSI (in Notepad ++)

Just checked the file contents (first line) in unix using object dump.  (test2.asm is in UTF-08 and test3.asm in ANSI).

/homes/Mathi:$ head -1 test2.asm | od -c
0000000  357 273 277   s   e   c   t   i   o   n       .   d   a   t   a
0000020   \r  \n
0000022

/homes/Mathi:$ head -1 test3.asm | od -c
0000000    s   e   c   t   i   o   n       .   d   a   t   a  \r  \n
0000017

Obviously test3.asm compiles fine.
Those 3 bytes ( somekind of signature ??) was the only difference.

Thanks for the motivation Frank :)
« Last Edit: June 28, 2011, 12:00:57 AM by Mathi »

Offline Frank Kotler

  • NASM Developer
  • Hero Member
  • *****
  • Posts: 2667
  • Country: us
Re: Error: label or instruction expected at start of line
« Reply #7 on: June 28, 2011, 12:58:51 AM »
Thanks, Mathi! I ain't never seen none of that, notime, nohow. That explains it. So...

1) Figure out how to get your editor to save in ascii.
2) Find a suitable example for Windows.
3) Tell Nasm what output format you want - the output name is probably okay.
4) Find a linker.
5) Soar! :)

Heck of a lot easier in Linux. :)

Best,
Frank


Offline the_mart

  • Jr. Member
  • *
  • Posts: 14
  • Country: gb
Re: Error: label or instruction expected at start of line
« Reply #8 on: June 28, 2011, 09:35:25 AM »
Those 3 bytes ( somekind of signature ??) was the only difference.

Yep, that’s the UTF-8 Byte Order Mark. It can be a bit of a pain, since many Windows apps add it by default when saving UTF-8 encoded text, and often don’t offer a way to remove it. I had the same issue many years back when I wrote a C++ application which had a string containing a pound sign (British pound, not American pound).

Offline Rob Neff

  • Forum Moderator
  • Full Member
  • *****
  • Posts: 429
  • Country: us
Re: Error: label or instruction expected at start of line
« Reply #9 on: June 28, 2011, 10:50:04 AM »
In addition to the BOM look at the offsets of those characters and the "blank" characters between them which are in reality nul ('\0') characters.  That is UCS-2 16-bit encoding, not UTF-8.  UCS-2 (wide character representations as implemented by Microsoft in Windows) is a subset of UTF-16 which simply doesn't handle characters requiring surrogate pairs ( it only handles the Unicode BMP ).

Offline Frank Kotler

  • NASM Developer
  • Hero Member
  • *****
  • Posts: 2667
  • Country: us
Re: Error: label or instruction expected at start of line
« Reply #10 on: June 28, 2011, 02:03:16 PM »
Can we be a little more civil towards each other? "Shut up" is not an opcode... although I suppose what we're trying to do is get Nasm to "shut up"...

The Unix utility "tail" could perhaps be used to remove this "Byte Order Mark". The rest of it is okay, right? Ports of the Unix utilities are available for Windows, or we could write one (more "fun"), but surely there's an easier way! Unless I'm mistaken, notepad++ is commonly used for source code editing, so there must be a way. This may help:

http://npp-community.tuxfamily.org/documentation/notepad-user-manual/document-properties/encoding

Then maybe we can get on to "suitable example", "output format", and "linker". These three are interrelated, so maybe we first should ask "what linker?". If in doubt, grab that NASMX package, I guess...

Used to be so easy in the good old days! :)

Best,
Frank


Offline Rob Neff

  • Forum Moderator
  • Full Member
  • *****
  • Posts: 429
  • Country: us
Re: Error: label or instruction expected at start of line
« Reply #11 on: June 28, 2011, 06:11:21 PM »
Unless I'm mistaken, notepad++ is commonly used for source code editing, so there must be a way.

I use Notepad++ quite frequently when in Windows to convert line-ending from Unix (LF) to Windows (CR-LF) and vice-versa.  You can also save the file in many different output formats.  Use ANSI output format when saving source code files.

Used to be so easy in the good old days! :)
Best,

Unfortunately those days are long gone, my friend.  :(
Us old dogs have to learn the new tricks  ;D




Offline namea

  • Jr. Member
  • *
  • Posts: 2
Re: Error: label or instruction expected at start of line
« Reply #12 on: July 01, 2011, 07:07:01 AM »
thank u all.

yes. it was unicode/ansi issue.

now compiling works.

so learning so far...