No announcement yet.

How do I do this with ASM?

  • Filter
  • Time
  • Show
Clear All
new posts

  • How do I do this with ASM?

    How do I get the command line arguments passed to an EXE
    from within the EXE itself, using ASM? I have been VERY busy
    converting a bunch of my UNIT's to OBJ files, as I downloaded
    the MASM 6.14 macro assembler about a week ago. I already know how
    to use the PSP to retrieve the path/name of the EXE itself.
    I have tried various searches through the PSP, and none of them
    seem to contain the command lines. I *could* use the part of the
    environment block that starts with "CMDLINE=", BUT, that is only
    valid if the program is run from a DOS command prompt. (i.e.,
    that env var does not get set when, for example, the EXE is SHELL'd
    to from another app).

    Any replies gratefully received.

    P.S. This question applies BOTH to my PB/DOS programs, and the standalone
    EXE files that I wish to write with MASM. I figured it'd be OK to post this
    question because of its partial relevance to PB/DOS programs.

    ADDED: got another question: how can I allocate/free memory from within
    ASM? In other words, do the same thing as PB's SETMEM statement.
    I've tried using int 21h, service 48h, but it ALWAYS fails. So, I read
    up on SETMEM in the online Help, and it referenced the "far heap."
    How can I do the same thing it does? I couldn't find anything in
    Ralf Brown's interrupt lists that would do it. I also tried the
    DPMI allocator interrupt service, but it always generated the
    "...has performed an illegal function...please restart your computer..."
    Windows error message.


    [This message has been edited by Clay Clear (edited April 08, 2003).]

  • #2
    Got the command line arguments figured out! Complete thanks for that
    goes to Barry Erick. I found one of his routines that SETS the command
    line for a CHAIN or RUN program. But, it also works to READ the command
    line in the destination EXE. And, it is located in the PSP, so I
    do not have to worry about being stuck with reading environment
    variables. I owe ya one, Barry!

    Now, if somebody could please tell me how to FREE memory so a
    shelled program, via int 21h, service 4b00h, will successfully run,
    then I'll be a happy camper. It's no problem doing it with programs
    written with PB/DOS, as I already have a UNIT set up whose sole purpose
    is to use SETMEM. My PB/DOS OBJ files can call that UNIT as an
    external. My problem is with the standalone EXE's that
    I wish to write with the MASM 6.14 compiler. Anybody?



    • #3
      If you're using PowerBASIC, you need to free memory using SETMEM.
      You can then allocate it using function 48h.

      If you're not using PowerBASIC, this is off-topic... but, for .COM
      programs, all available memory is already allocated; use it as-is
      or deallocate the part you're not using and reallocate as needed.
      For .EXE programs, no memory is reserved, and you need to allocate
      it as needed.

      If that doesn't help, perhaps you could tell us more than "always fails".
      Like, what's the error code, and have you checked for an extended error

      Tom Hanlin
      PowerBASIC Staff


      • #4
        Thanks for your reply, Tom. I guess I will stick to SHELLing to
        programs by using PB/DOS programs as the caller. Then I can continue
        to use the RunProgram OBJ file included in my PBL, and also still
        use SETMEM, which I have set up in a UNIT, so external modules
        can call it.

        Mainly, I wanted to LEARN. So, it's not a biggie. Thanks, though.