Author Topic: i need some help about nasm  (Read 3027 times)

Offline smaldona

  • Jr. Member
  • *
  • Posts: 2
i need some help about nasm
« on: September 28, 2010, 08:01:48 PM »
hi,

Im Smaldona and I am searching somebody can help me about nasm..

i got a problem, i did a sudoku's generator and i don know how can i call the sudoku's program from other program..

what i wanna do is like do other code (program) who calls the sudokus program for 100 times, and i have this part of other code,,

the sudokus code is ready,

my question is :
how can i call or invoc a code from other code..

jmm... and excuse me for the  grammar ,  im learning english at this moment....

extern printf
extern sudoku

section .data


%macro  setup_stack_frame    0     
    push   ebp                       
    mov    ebp, esp
    push   ebx                       
    push   esi                     
    push   edi                       
%endmacro                           

%macro  destroy_stack_frame  0     
    pop    edi                       
    pop    esi                       
    pop    ebx                         
    mov    esp, ebp                   
    pop    ebp                       
%endmacro

section .bss
section .text

global main:
   
main:
   setup_stack_frame
   call sudoku
   destroy_stack_frame
   ret



Offline Frank Kotler

  • NASM Developer
  • Hero Member
  • *****
  • Posts: 2437
  • Country: us
Re: i need some help about nasm
« Reply #1 on: September 28, 2010, 09:50:55 PM »
Ah, Sudoku - Hirohito's Revenge. :)

Looks like the Nasm part is about done, Smaldona. You've got "extern sudoku" in your calling program. Have you got "global sudoku" in the called code? That should be all it takes. "gcc -o myprog caller.o callee.o"...

If you're not using gcc in Linux (or so), there may be an issue with underscores on globals and externs. Since you haven't got 'em, I'm ASSuming you don't need 'em. If you do, adding "--prefix _" to Nasm's command line will add them, so you don't have to touch the code. OpenWatcom wants "--postfix _", I understand...

If that isn't working, tell us just what you did, and just what happened. Chances are, if you read any error messages carefully, you can figure it out yourself - did they spell it "main" or "_main"... that kind of thing...

Best,
Frank


Offline smaldona

  • Jr. Member
  • *
  • Posts: 2
Re: i need some help about nasm
« Reply #2 on: September 30, 2010, 01:59:38 AM »

Hi, Frank

in the called code I´ve got "global main"; so what I have to do is "global _main"?? the prefix??..... yes, I`m using "gcc"..

the sudoku`s file I`ve named it "sudo.asm"
and other file is named "menu.asm"

I wanna do is to call sudo.asm from menu.asm...
somebody told me that I had to generate an object "sudo.o" and that were the way for calling it, but it didnt work!

Offline Frank Kotler

  • NASM Developer
  • Hero Member
  • *****
  • Posts: 2437
  • Country: us
Re: i need some help about nasm
« Reply #3 on: September 30, 2010, 03:23:53 AM »
"Didn't work" isn't much to go on...

Probably want to "define out" the "main" in sudo.asm...

Code: [Select]
; sudo.asm

; let me guess...
extern printf

%ifdef TESTMAIN
global main

main:
call sudoku
ret

%endif

global sudoku
sudoku:
...

Then you can assemble it in "test" mode by adding "-dTESTMAIN" to Nasm's command line. When you're ready to call it from "menu":

Code: [Select]
nasm -f elf32 sudo.asm
nasm -f elf32 menu.asm
gcc -o outname menu.o sudo.o

Best,
Frank