Author Topic: Get NASM code from C code automatically  (Read 7001 times)

Offline Frank Kotler

  • NASM Developer
  • Hero Member
  • *****
  • Posts: 2358
  • Country: us
Re: Get NASM code from C code automatically
« Reply #15 on: June 04, 2014, 11:47:50 AM »
A little experimentation has revealed that it doesn't seem to be the "rel" keyword that is causing the problem, but the dot on ".LC0" etc. Nasm can't find that local label (apparently out of scope). As for the "absolute address can't be RIP relative", it seems Nasm "always says that" if it can't find the symbol. Or so it seems to me, at this point. The dword data does not seem to be a problem.

So I think what you're going to have to do is figure out which variable those lines are referencing, and make the names match. If "LC0", "LC1", etc are not duplicated it may be as simple as removing the dots. If they are, the "full names" in the "undefined" errors may give a clue to which one you want. (although that seems weird to me) If you can discern the "purpose" of these variables, now might be a good time to give them meaningful names.

Best,
Frank


Offline AndrewF

  • Jr. Member
  • *
  • Posts: 15
Re: Get NASM code from C code automatically
« Reply #16 on: June 04, 2014, 03:17:05 PM »
I'm way over my head with this, AndrewF. I have almost no experience with 64-bit code. The first three lines are "only" warnings. It "might" work anyway, but probably not. You could try removing the "rel", but that probably won't work either. You might try making the whole thing "default rel". If objconv thinks gcc encoded it as "rel", it probably did. I don't know why Nasm thinks it's a problem.

As you know, symbols starting with a dot are Nasm's idea of how to implement a local label. The scope is from one non-local label to the next. Do you see labels like "?_015", "matrixum", and/or "?_025" anywhere (with or without a ':)'? You might try stuffing such labels in - someplace that looks probable. If ".LC0" etc. are reused, you're going to have to be careful to get 'em in the right place! If they're not reused, removing the dot might work(?).

I think that all addresses would be oword, but I don't see any problem that they point to dword or even byte data. As I said, this is way beyond my experience. Good luck!

Best,
Frank

Thanks again Frank.
Now i have fixed the previous problem and in x64 version, compiles.
I have tried to do a similar procedure for x86 but unfortunately get these errors
Code: [Select]
test32.asm:259: error: comma, colon or end of line expected
test32.asm:273: error: comma, colon or end of line expected
test32.asm:281: error: comma, colon or end of line expected
test32.asm:286: error: comma, colon or end of line expected
test32.asm:288: error: comma, colon or end of line expected
test32.asm:326: error: comma, colon or end of line expected


all the lines that the compiler marks as wrong

Code: [Select]
fucomip st(0), st1   
Code: [Select]
fucomi  st(0), st2
Code: [Select]
fucomip st(0), st3 
Code: [Select]
fucomip st(0), st2
Code: [Select]
fcmovbe st(0), st1
Code: [Select]
fucomi  st(0), st1

Offline Rob Neff

  • Forum Moderator
  • Full Member
  • *****
  • Posts: 430
  • Country: us
Re: Get NASM code from C code automatically
« Reply #17 on: June 04, 2014, 04:03:59 PM »
all the lines that the compiler marks as wrong

Code: [Select]
fucomip st(0), st1

My memory may be a bit fuzzy but that looks like syntax issue.  Remove the parenthesis and try:
Code: [Select]
fucomip st0, st1