Author Topic: A "global" issue  (Read 10511 times)

Offline hjckevin

  • New Member
  • Posts: 1
A "global" issue
« on: March 15, 2011, 01:52:51 AM »
I have a C programme as follows:
Code: [Select]
#include<stdio.h>
int sum(int n)
{
  int ret, i;
  ret = 0;
  for(i = 0; i < n; i++){
    ret = ret + i;
  }
  return ret;
}

int main(void)
{
  int n , s;

  n = 7 + 1;
  s = sum(n);
  
  return 0;
}
After compiling, it's like:
Code: [Select]
global _sum
.text
_sum:
mov r44,sp
pushr r56
pushr r60
mov r56,0
mov r60,r56
jmp L5
L2:
add r56,r60
L3:
add r60,1
L5:
mov r24,r44
add r24,16
mov r24,[r24]
cmp r60,r24
jlt 6
jp 8
jmp L2
mov r40,r56
L1:
popr r60
popr r56
mov sp,r44
ret

global _main
_main:
start:
mov r44,sp
sub sp,8
mov r24,r44
add r24,-4+4
mov r20,8
mov [r24],r20
mov r24,r44
add r24,-4+4
mov r24,[r24]
pushr r24
pushr r44
call _sum
popr r44
add sp,4
mov r20,r44
add r20,-8+4
mov [r20],r40
mov r40,0
L7:
mov sp,r44
ret

Then, when i use nasm to assemble it, something wrong happened:
Code: [Select]
sum.asm:1: fatal: preprocessor directive `%rotate' not yet implemented

It tured out to be OK when I change it as follows:
Code: [Select]
[global _sum]
or:
Code: [Select]
;global _sum

My nasm version is 0.98, and I've changed some instructions.
I really don't know what to do.
« Last Edit: March 15, 2011, 01:56:23 AM by hjckevin »

Offline Frank Kotler

  • NASM Developer
  • Hero Member
  • *****
  • Posts: 2667
  • Country: us
Re: A "global" issue
« Reply #1 on: March 15, 2011, 05:11:59 AM »
First, upgrade to a newer version of Nasm.

http://www.nasm.us

I don't think anyone wants to debug problems with 0.98 at this point!

I don't think it's going to assemble anyway - doesn't look like Nasm syntax to me. Exactly what did you do to produce this code?

Best,
Frank