Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

help with NASM...int 21h with 04bh

jkzhjkzh Member Posts: 2
Hi guys, I'm new to assembly!!!...I need to know how can I run a program with another program. I have being trying to use int 21h with 04bh, but...less not say anything. another thing is that I'm stuck with this NASM assembler, it doesn't give me a lot of choices...please guys...with me a hand here...I really don't know what to do...please!

Comments

  • BretBret Member Posts: 114
    : Hi guys, I'm new to assembly!!!...I need to know how can I run a
    : program with another program. I have being trying to use int 21h
    : with 04bh, but...less not say anything. another thing is that I'm
    : stuck with this NASM assembler, it doesn't give me a lot of
    : choices...please guys...with me a hand here...I really don't know
    : what to do...please!

    Here's some relevant excerpts from one of my programs that calls a child program. I use the A86 Assembler, not NASM, so some of the syntax will probably be a little different for you. This should help you get started.

    You need to fill in PathToUse (the Child Programs Path, File Name, and File Extension), CmdTail (the switch Options you want to pass to the Child Program), and CmdTailSize (the size of the Option String).

    [code]
    ;----------------------------------------------------------------------------
    ;Special ASCII Characters
    ;----------------------------------------------------------------------------
    CR EQU 13 ;Carriage Return

    ;----------------------------------------------------------------------------
    ;Sizes of various DOS data structures
    ;----------------------------------------------------------------------------
    FCBSize EQU 44 ;Size of DOS File Control Block
    CmdTailMax EQU 128 ;Maximum size of a DOS Command Tail
    MaxPathSize EQU 64 ;Maximum Size of a DOS Path/FileName String

    ;----------------------------------------------------------------------------
    ;Structure needed to Initialize DOS EXEC Function
    ;----------------------------------------------------------------------------
    ParamBlockStruc STRUC
    PBEnvirSegment DW ? ;Environment Segment to use (0 = Copy Callers Segment)
    PBCmdTailPtr DD ? ;Pointer to Command Tail
    PBFCB1Offset DD ? ;Pointer to File Control Block #1
    PBFCB2Offset DD ? ;Pointer to File Control Block #2
    PBSSSPOnReturn DD ? ;Holds Childs Initial SS:SP on Return (if AL = 01)
    PBCSIPOnReturn DD ? ;Holds Entry Point (CS:IP) on Return (if AL = 01)
    ENDS
    ParamBlockSize EQU (TYPE ParamBlockStruc) ;Size of EXEC Parameter Block

    ;----------------------------------------------------------------------------
    ;Variables needed to do EXEC Call
    ;----------------------------------------------------------------------------
    PathToUse: DB MaxPathSize DUP (0) ;Path to Use

    CmdTailSize DB CmdTailMax-2 ;Length of command tail (Maximize it)
    CmdTail: DB CmdTailMax DUP (CR) ;Command Tail for EXEC Call
    ParamBlock: DB ParamBlockSize DUP (?) ;Parameter Block for EXEC Call
    FCB1: DB FCBSize DUP (?) ;File Control Block #1
    FCB2: DB FCBSize DUP (?) ;File Control Block #2
    OldSPExec DW ? ;SP may be destroyed by EXEC Call


    ;------------------------------------------------------------------------------
    ;SETUP PARAMETERS TO BE ABLE TO PERFORM THE EXEC FUNCTION
    ;Inputs:
    ;Outputs:
    ;Changes: Lots of stuff
    ;------------------------------------------------------------------------------
    SetupExec:
    PUSH AX,SI ;Save used registers
    MOV SI,ParamBlock ;Point at Parameter Block
    MOV AX,CS ;Use our data segment
    MOV [SI].PBEnvirSegment,0 ;Use Copy of our Environment
    MOV W [SI].PBCmdTailPtr[0],OFFSET CmdTailSize
    MOV W [SI].PBCmdTailPtr[2],AX ;Command Tail Pointer
    MOV W [SI].PBFCB1Offset[0],FCB1
    MOV W [SI].PBFCB1Offset[2],AX ;FCB #1 Pointer
    MOV W [SI].PBFCB2Offset[0],FCB2
    MOV W [SI].PBFCB2Offset[2],AX ;FCB #2 Pointer
    POP SI,AX ;Restore used registers
    RET

    ;------------------------------------------------------------------------------
    ;PERFORM THE EXEC FUNCTION
    ;Inputs: ParamBlock set up with appropriate data
    ; CmdTail/CmdTailSize set up with appropriate Info
    ; PathToUse contains Child Program to Call
    ; DS = Our Data Area
    ;Outputs: CF = Clear if Program Returned ErrorLevel 0
    ;Changes: Performs EXEC Function
    ;------------------------------------------------------------------------------
    DoExec:
    PUSH ES ;Save used register
    MOV ES,DS ;Point ES at our Data Area
    PUSHA ;Save all registers
    MOV OldSPExec,SP ;Save the Stack Pointer (may be destroyed by Call)
    MOV DX,PathToUse ;DS:[DX] = Child Program to Run
    MOV BX,ParamBlock ;ES:[BX] = Parameter Block
    MOV AX,4B00h ;Function 4B00h (Load and Execute child program)
    INT 21h ;Do it (May Destroy BX & DX)
    JC >X70 ;If Error, quit
    X00: ;When the Child Program Exits, here we are!
    CLD ;Go forward with string functions
    CLI ;Disable interrupts
    MOV DS,CS ;Restore
    MOV ES,DS ; all
    MOV SS,CS ; Segments
    MOV SP,OldSPExec ;Restore Stack Pointer
    STI ;Enable interrupts
    MOV AH,4Dh ;Function 4Dh (Get ErrorLevel)
    INT 21h ;Do it (Returns AH = Term Type, AL = ErrorLevel)
    OR AL,AL ;ErrorLevel 0?
    JZ >X80 ;If so, it was OK
    X70: ;Error
    STC ;Set Error Flag
    JMP >X90 ;Done
    X80: ;OK
    CLC ;Set OK Flag
    X90: ;Done
    POPA ;Restore all registers
    NOP ;POPA Bug Fix
    POP ES ;Restore used registers
    RET
    [/code]
  • jkzhjkzh Member Posts: 2
    : : Hi guys, I'm new to assembly!!!...I need to know how can I run a
    : : program with another program. I have being trying to use int 21h
    : : with 04bh, but...less not say anything. another thing is that I'm
    : : stuck with this NASM assembler, it doesn't give me a lot of
    : : choices...please guys...with me a hand here...I really don't know
    : : what to do...please!
    :
    : Here's some relevant excerpts from one of my programs that calls a
    : child program. I use the A86 Assembler, not NASM, so some of the
    : syntax will probably be a little different for you. This should
    : help you get started.
    :
    : You need to fill in PathToUse (the Child Programs Path, File Name,
    : and File Extension), CmdTail (the switch Options you want to pass to
    : the Child Program), and CmdTailSize (the size of the Option String).
    :
    : [code]:
    : ;----------------------------------------------------------------------------
    : ;Special ASCII Characters
    : ;----------------------------------------------------------------------------
    : CR EQU 13 ;Carriage Return
    :
    : ;----------------------------------------------------------------------------
    : ;Sizes of various DOS data structures
    : ;----------------------------------------------------------------------------
    : FCBSize EQU 44 ;Size of DOS File Control Block
    : CmdTailMax EQU 128 ;Maximum size of a DOS Command Tail
    : MaxPathSize EQU 64 ;Maximum Size of a DOS Path/FileName String
    :
    : ;----------------------------------------------------------------------------
    : ;Structure needed to Initialize DOS EXEC Function
    : ;----------------------------------------------------------------------------
    : ParamBlockStruc STRUC
    : PBEnvirSegment DW ? ;Environment Segment to use (0 = Copy Callers Segment)
    : PBCmdTailPtr DD ? ;Pointer to Command Tail
    : PBFCB1Offset DD ? ;Pointer to File Control Block #1
    : PBFCB2Offset DD ? ;Pointer to File Control Block #2
    : PBSSSPOnReturn DD ? ;Holds Childs Initial SS:SP on Return (if AL = 01)
    : PBCSIPOnReturn DD ? ;Holds Entry Point (CS:IP) on Return (if AL = 01)
    : ENDS
    : ParamBlockSize EQU (TYPE ParamBlockStruc) ;Size of EXEC Parameter Block
    :
    : ;----------------------------------------------------------------------------
    : ;Variables needed to do EXEC Call
    : ;----------------------------------------------------------------------------
    : PathToUse: DB MaxPathSize DUP (0) ;Path to Use
    :
    : CmdTailSize DB CmdTailMax-2 ;Length of command tail (Maximize it)
    : CmdTail: DB CmdTailMax DUP (CR) ;Command Tail for EXEC Call
    : ParamBlock: DB ParamBlockSize DUP (?) ;Parameter Block for EXEC Call
    : FCB1: DB FCBSize DUP (?) ;File Control Block #1
    : FCB2: DB FCBSize DUP (?) ;File Control Block #2
    : OldSPExec DW ? ;SP may be destroyed by EXEC Call
    :
    :
    : ;------------------------------------------------------------------------------
    : ;SETUP PARAMETERS TO BE ABLE TO PERFORM THE EXEC FUNCTION
    : ;Inputs:
    : ;Outputs:
    : ;Changes: Lots of stuff
    : ;------------------------------------------------------------------------------
    : SetupExec:
    : PUSH AX,SI ;Save used registers
    : MOV SI,ParamBlock ;Point at Parameter Block
    : MOV AX,CS ;Use our data segment
    : MOV [SI].PBEnvirSegment,0 ;Use Copy of our Environment
    : MOV W [SI].PBCmdTailPtr[0],OFFSET CmdTailSize
    : MOV W [SI].PBCmdTailPtr[2],AX ;Command Tail Pointer
    : MOV W [SI].PBFCB1Offset[0],FCB1
    : MOV W [SI].PBFCB1Offset[2],AX ;FCB #1 Pointer
    : MOV W [SI].PBFCB2Offset[0],FCB2
    : MOV W [SI].PBFCB2Offset[2],AX ;FCB #2 Pointer
    : POP SI,AX ;Restore used registers
    : RET
    :
    : ;------------------------------------------------------------------------------
    : ;PERFORM THE EXEC FUNCTION
    : ;Inputs: ParamBlock set up with appropriate data
    : ; CmdTail/CmdTailSize set up with appropriate Info
    : ; PathToUse contains Child Program to Call
    : ; DS = Our Data Area
    : ;Outputs: CF = Clear if Program Returned ErrorLevel 0
    : ;Changes: Performs EXEC Function
    : ;------------------------------------------------------------------------------
    : DoExec:
    : PUSH ES ;Save used register
    : MOV ES,DS ;Point ES at our Data Area
    : PUSHA ;Save all registers
    : MOV OldSPExec,SP ;Save the Stack Pointer (may be destroyed by Call)
    : MOV DX,PathToUse ;DS:[DX] = Child Program to Run
    : MOV BX,ParamBlock ;ES:[BX] = Parameter Block
    : MOV AX,4B00h ;Function 4B00h (Load and Execute child program)
    : INT 21h ;Do it (May Destroy BX & DX)
    : JC >X70 ;If Error, quit
    : X00: ;When the Child Program Exits, here we are!
    : CLD ;Go forward with string functions
    : CLI ;Disable interrupts
    : MOV DS,CS ;Restore
    : MOV ES,DS ; all
    : MOV SS,CS ; Segments
    : MOV SP,OldSPExec ;Restore Stack Pointer
    : STI ;Enable interrupts
    : MOV AH,4Dh ;Function 4Dh (Get ErrorLevel)
    : INT 21h ;Do it (Returns AH = Term Type, AL = ErrorLevel)
    : OR AL,AL ;ErrorLevel 0?
    : JZ >X80 ;If so, it was OK
    : X70: ;Error
    : STC ;Set Error Flag
    : JMP >X90 ;Done
    : X80: ;OK
    : CLC ;Set OK Flag
    : X90: ;Done
    : POPA ;Restore all registers
    : NOP ;POPA Bug Fix
    : POP ES ;Restore used registers
    : RET
    : [/code]:
    [color=Black]thanks a lot!!!...I'll try to assemble it with the A86.. I kind of understand what the code means, but there is still a lot to learn!!! :D ... also, do you know of any way to do the coding in C and then translate it to assembly?? thanks a lot for your help!![/color]
  • BretBret Member Posts: 114
    : [color=Black]thanks a lot!!!...I'll try to assemble it with the
    : A86.. I kind of understand what the code means, but there is still a
    : lot to learn!!! :D ... also, do you know of any way to do the coding
    : in C and then translate it to assembly?? thanks a lot for your
    : help!![/color]

    I've personally never done a C-to-ASM conversion, though I'm sure others around here have. I can't help you there.
Sign In or Register to comment.