flat assembler
Message board for the users of flat assembler.

Index > DOS > Cannot get command line tail from parameter structure

Author
Thread Post new topic Reply to topic
ChrisLeslie



Joined: 04 Jun 2006
Posts: 50
Location: Australia
ChrisLeslie
I am having trouble getting a command line tail member from a structure when calling a child program. If I pass a null command line member value to the structure then I can run the child program by successfully. When I pass the command line offset to the structure the parent program just terminates.
I suspect that I am not passing the address of the structure correctly to the bx register before the execute function, or that my structure syntax is incorrect, but I am not sure how to do this using FASM.
Here is the code I have used, using fasmw.exe as the child. Can anybody help me to get it going?
Code:
;Parent program
org 100h
jmp begin
child    db "C:\fasm\fasmw.exe",0
cmdLine  db 12," parent3.asm",0dh
f1: times 37 db 0
f2: times 37 db 0
msg1     db "Cannot resize memory block",0dh,1Ah,'$'
msg2     db "Error trying to execute",0dh,0ah,'$'

struc paramBlock env,cmdLine,f1,f2
{
  .env  dw env
  .pcmd dd cmdLine
  .f1   dd f1
  .f2   dd f2
}

begin:
  mov bx,50h   ; resize memory block
  mov ah,4Ah
  int 21h
  jc resizeProblem

  my paramBlock 0,cmdLine,0,0   ;establish an instance of paramBlock with cmdLine

  mov dx,child
  mov bx,my.env     ; not sure here if I am passing the address of the parameter block
  mov ax,4B00h
  int 21h
  jc executeProblem
  jmp quit

executeProblem:
  mov ah,09h
  mov dx,msg2
  int 21h
  jmp quit

resizeProblem:
  mov ah,09h
  mov dx,msg1
  int 21h
  jmp quit

quit:  
  mov ax,4C00h
  int 21h                
Post 04 Jun 2006, 10:06
View user's profile Send private message Reply with quote
ChrisLeslie



Joined: 04 Jun 2006
Posts: 50
Location: Australia
ChrisLeslie
Hmmm! Perhaps I did not make the problem clear:

I am writing a .com program that calls up a child program. I am able to call a child program OK but I cannot pass a command line argument to the child program. The DOS interupt that enables this expects that the address of the string with my command line is part of a memory block. I have defined a structure to form the memory block. My problem is that the DOS interupt will not pick up the part of the structure with the comman line address. I am not sure if: 1) I am putting the address correctly to the structure, or 2) If I am addressing the whole structure correctly, or 3) maybe something else is wrong.
I have not used structures much in the past and I am also not sure about the FASM syntax.

My code in the post uses fasmw.exe as the child program to call up, and the command line could be any text file.

Chris
Post 06 Jun 2006, 09:11
View user's profile Send private message Reply with quote
LocoDelAssembly
Your code has a bug


Joined: 06 May 2005
Posts: 4633
Location: Argentina
LocoDelAssembly
http://board.flatassembler.net/topic.php?t=5193 <- This calls a child program passed as argument, check it out.

Hope it helps you

Regards
Post 06 Jun 2006, 15:34
View user's profile Send private message Reply with quote
ChrisLeslie



Joined: 04 Jun 2006
Posts: 50
Location: Australia
ChrisLeslie
Thanks locodelassembly. However, your example passes a child program as an argument. My problem is different as I need to pass an argument WITH the child program. I have looked at your code and I can't see any tips in there to help me. Any other suggestions?

Regards

Chris
Post 06 Jun 2006, 22:00
View user's profile Send private message Reply with quote
LocoDelAssembly
Your code has a bug


Joined: 06 May 2005
Posts: 4633
Location: Argentina
LocoDelAssembly
Code:
;Parent program
org 100h 
jmp begin 
child    db "C:\fasm\fasmw.exe",0 
cmdLine  db 12," parent3.asm",0dh 
msg1     db "Cannot resize memory block",0dh,1Ah,'$'
msg2     db "Error trying to execute",0dh,0ah,'$' 

struc paramBlock env,cmdLine,f1,f2
{ 
  .env  dw env 
  .pcmd dd cmdLine 
  .f1   dd f1 
  .f2   dd f2 
} 
my paramBlock 0,0,0,0   ;establish an instance of paramBlock with cmdLine

begin:
  mov bx,50h   ; resize memory block 
  mov ah,4Ah 
  int 21h 
  jc resizeProblem 

  mov  word [my.pcmd], cmdLine
  mov  word [my.pcmd+2], cs

  mov dx,child 
  mov bx,my.env     ; not sure here if I am passing the address of the parameter block 
  mov ax,4B00h 
  int 21h 
  jc executeProblem 
  jmp quit 

executeProblem: 
  mov ah,09h 
  mov dx,msg2 
  int 21h 
  jmp quit 

resizeProblem: 
  mov ah,09h 
  mov dx,msg1 
  int 21h 
  jmp quit 

quit:   
  mov ax,4C00h 
  int 21h            
    


http://board.flatassembler.net/topic.php?t=290 <- Here there is an example by Tomasz too.

Also note I relocated the instantiation of the structure, I did't do that for styling I did that to prevent the execution of the structure. You was extremately lucky that the structure by accident has data which also was valid opcodes (for example 0000h is ADD [BX+SI], AL).

Regards

[edit]
Here a struc for make cmd lines
Code:
struc CmdLine cmdLine
{
  . db 0, cmdLine, $0D

  store $ - . - 2 at .
}

cmdLine  CmdLine "test.asm" ; A space at the start seems to be unnecesary 

anotherCmdLine CmdLine "fasm.asm"    

I don't remember which is the size limit for the cmdline, if you know which is then add that check. At this time you have a limit of 255 bytes.[/edit]
Post 06 Jun 2006, 23:13
View user's profile Send private message Reply with quote
ChrisLeslie



Joined: 04 Jun 2006
Posts: 50
Location: Australia
ChrisLeslie
Thankyou again locodelassembly. Very Happy

The key section of code that made it all work was "mov word [my.pcmd+2], cs". Since my.pcmd is a dword then you have moved the word cmdLine address into the high word end but I can't understand why we need to move cs to the low word end. Can you explain to me why this is needed. Confused

Regards

Chris
Post 07 Jun 2006, 02:48
View user's profile Send private message Reply with quote
LocoDelAssembly
Your code has a bug


Joined: 06 May 2005
Posts: 4633
Location: Argentina
LocoDelAssembly
Because this COM file is running on 16-bit mode so when something is asking you for a dword ptr that means you need both offset and segment. Note that since in COM executables CS = DS = SS = ES you can use any of these. Note that actually I'm moving CS to the high word and the offset to low word, it's little endian.

Regards
Post 07 Jun 2006, 14:00
View user's profile Send private message Reply with quote
ChrisLeslie



Joined: 04 Jun 2006
Posts: 50
Location: Australia
ChrisLeslie
That makes sense. I thank you very much for your interest in helping me.

Regards

Chris
Post 07 Jun 2006, 22:21
View user's profile Send private message Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  


< Last Thread | Next Thread >
Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Copyright © 1999-2020, Tomasz Grysztar.

Powered by rwasa.