How to pass/retrieve DOS command-line parameters in a 16-bit assembly program?

前端 未结 2 1560
天涯浪人
天涯浪人 2021-02-09 19:34

I am writing some little tools for MS-DOS. Now I\'m writing a Shutdown.com, like for Windows XP and greater. I have already written the entire code, now I just need

2条回答
  •  逝去的感伤
    2021-02-09 20:30

    According to this site, the length of the command-line is stored at DS:80h (single byte), and the actual command line itself starts at DS:81h. Here's some example code from that article that prints the command line:

    ; ----------------------------------------------------------------------------
    ; echo.asm
    ;
    ; Echoes the command line to standard output.  Illustrates DOS system calls
    ; 40h = write to file, and 4ch = exit process.
    ;
    ; Processor: 386 or later
    ; Assembler: MASM
    ; OS: DOS 2.0 or later only
    ; Assemble and link with "ml echo.asm"
    ; ----------------------------------------------------------------------------
    
            .model  small
            .stack  64                      ; 64 byte stack
            .386
            .code
    start:  movzx   cx,byte ptr ds:[80h]    ; size of parameter string
            mov     ah, 40h                 ; write
            mov     bx, 1                   ; ... to standard output
            mov     dx, 81h                 ; ... the parameter string
            int     21h                     ; ... by calling DOS
            mov     ah, 4ch
            int     21h
            end     start             
    

提交回复
热议问题