NASM Forum > Programming with NASM

File input error

<< < (2/2)

Frank Kotler:
Okay. This is "even worse than I remembered". I thought I had a "low level" or "raw" version - can't find it now. This uses macros... from .inc files that have been modified from their original form. It'll be even less use to you than I thought!

What I though might be relevant to the problem you were having (but apparently isn't) is the way arguments (and environment) are passed to sys_execve. I need an array of pointers to strings (both zero-terminated). The first arg needs to be the name of the program (argc is always at least 1), the rest of 'em are what we pretend was on the command line...


--- Code: ---section .data

; the argument strings
    editor db '/usr/bin/mcedit', 0   ; vi, emacs, e3, ...
    ed_in db 'hello.asm', 0

; the array to pass to sys_execve
    ed_args dd editor, ed_in, 0

    assembler db '/usr/local/bin/nasm', 0  ; Fasm, HLA, Gas, ...
    outform db '-felf', 0
    optim db '-O999', 0
    dbg db '-g', 0
    objname db '-ohello.o', 0
    inname db 'hello.asm', 0

    asm_args dd assembler, outform, optim, dbg, objname, inname, 0
   
    linker db '/usr/bin/ld', 0
    lnk_s db '-s', 0
    lnk_in db 'hello.o', 0
    lnk_out db '-ohello', 0

    lnk_args dd linker, lnk_s, lnk_out, lnk_in, 0

--- End code ---

I thought you might need something like that to pass arguments, but apparently C# is different (duh!).

As you can see, everything's hard-coded in. The "interface" consists of putting the code you want to assemble in the directory with this program - named "hello.asm" (whatever it is). I was mostly just trying to run another program from my program... and get back! sys_execve doesn't "return", it just exits, so I had to sys_fork first, and sys_wait for the child to return. It was my first experience with sys_fork, and it took me a while to sort out "being in two places at once"! I think I got it, but I didn't get any farther with it...

If the .tar.bz2 is a problem (I think 7zip will do it) I can provide other formats, but I really don't think it "applies" to what you're doing.

Are you looking for an archive "of" Nasm code - the code to Nasm itself? Yeah http://www.nasm.us has got it going way back. If you're looking for code to assemble with Nasm... not much but "demos". Jeff Owen wrote a lot of stuff for Linux - all in Nasm - including an IDE (or two). He's abandoned it. I thought it was on SourceForge, but I can't find it now. I've got it, anyway. A bit too large to post the whole package here. Best documentation of sys_calls I've ever seen, among other things. Really ought to be archived! Maybe I'll break it down into postable chunks...

Best,
Frank

gidak:
Thank you very much for all the help and support you gave me.
I hope to publish my program on the forums soon :)
Its not something very good cos i need to run the debugger as a external program but a nice source code editor
with options to make bin com exe and write boot-loaders to floppy's.

If you have any more ideas please tell me. ;)

Navigation

[0] Message Index

[*] Previous page

Go to full version