Author Topic: comma or end of line expected PLS HELP  (Read 30895 times)

nobody

  • Guest
comma or end of line expected PLS HELP
« on: March 20, 2007, 11:21:06 AM »
Hi there. I really do not have much time so sorry if this topic was written earlier.
I'm newbie in nasm [ i preffer  at&t syntax ]
And I'm trying to find out wtf is wrong in this line:

mov edi, offset table

(nasm says: error: comma or end of line expected
                 (lea edi, table) same result.

where table is global char array from extern file1.c
whole code:


file2.asm
---snip snip----
section .text
  global cpuid_vendor
  (...)

cpuid_vendor:
   mov eax, 0
   cpuid
   mov edi, offset table
   mov [edi], ebx
   mov [edi+4],edx
   mov [edi+8],ecx
   ret
(...)

---snip snip---


and C code:
#include
int cpuid_vendor();
char table[1024];
int main() {
      int i; (...)
      cpuid_vendor();
      for(i=0;i<12;i++)
                printf("%c",table);
(...)

Thanx for any kind of help.
greetingz

Offline Frank Kotler

  • NASM Developer
  • Hero Member
  • *****
  • Posts: 2667
  • Country: us
Re: comma or end of line expected PLS HELP
« Reply #1 on: March 20, 2007, 01:06:38 PM »
Just "mov edi, table" will give you the offset in Nasm syntax. Alternately, "lea edi, ". Don't forget "extern table" in the .asm file.

I would think you'd want to pass the destination buffer as a parameter, though...

C file:

#include
int cpu_vendor(char *dest);

int main(){
    char buf[13];

cpu_vendor(buf);
    puts(buf);
    return (0);
    };

Asm file:

global cpu_vendor
cpu_vendor:
    push edi
    push ebx
    mov edi,
[esp + 12]
    xor eax, eax
    cpuid
    mov [edi], ebx
    mov [edi + 4], edx
    mov [edi + 8], ecx
    mov byte [edi + 12], 0
    pop ebx
    pop edi
    ret

By rights, I suppose we ought to make the caller pass in a "length", as well, and bail out early if we haven't got at least 13 bytes to play with. Hell with it, make the buffer big enough!

Best,
Frank

nobody

  • Guest
Re: comma or end of line expected PLS HELP
« Reply #2 on: March 20, 2007, 01:58:41 PM »
Thanks frank [; I really do not need nasm, but my project leader (he could be my father, and he is a leader of this small project, and lecturer of this subject (i'm a student)).
He told me that I've to do this via array in this way:

char table[32];
table=cpu_vendor(); <- can u feel this ? ::::D "returning array function in C (??????) poof poof" ;-)
What do You think about it ?

Best
Tito

Offline Frank Kotler

  • NASM Developer
  • Hero Member
  • *****
  • Posts: 2667
  • Country: us
Re: comma or end of line expected PLS HELP
« Reply #3 on: March 20, 2007, 04:06:01 PM »
Hi Tito,

> table=cpu_vendor(); <- can u feel this ?

Yes, I think so. Or maybe it's just gas - and I don't mean the assembler! :)

You'd better do it the way your project leader wants it done. I don't know much C, but I think that's going to be a *really* good trick. I did get it working - almost the way you posted originally, but without "offset". (and with "extern" on the buffer)

One thing that occurs to me is that I'm testing in Linux. If you're *not* doing ELF, you'll want underscores on those global/extern variables in the Nasm file. Add "--PREFIX_" to Nasm's command line to do that without altering the source. (I thought they told us C was portable!)

If you really want this thing to return a pointer to its data, you could malloc some in your asm routine. Horrible way to do it, IMO. Good luck!

Best,
Frank

Offline luis007553

  • New Member
  • Posts: 1
Re: comma or end of line expected PLS HELP
« Reply #4 on: July 15, 2013, 03:15:06 PM »
I have a problem making a game.
In assembly, in a section called ultimosataques, I have the following code:
Label is at line 124.
Code: [Select]
ultimosataques:
cmp ultimoataque, 0
je msg3 db "Não há ataques"
cmp ultimoataque, 1
je msg3 db "Firebit Saque: 300 moedas e 300 minerais"
call print
jmp inputstart
The section inputstart is in my program.
I have nasm on Windows 7 and it responds on Command Line (these are only the last 2 lines):
Code: [Select]
prog0101.asm:126: comma, colon or end of line expected
prog0101.asm:128: comma, colon or end of line expected