flat assembler
Message board for the users of flat assembler.

Index > DOS > INT 2FH AX=4810H - Read Command Line

Goto page 1, 2  Next
Author
Thread Post new topic Reply to topic
geekbasic@gmx.com



Joined: 25 Oct 2022
Posts: 65
Location: Arizona
geekbasic@gmx.com 22 Jan 2023, 03:10
INT 2FH AX=4810H - Read Command Line

ah=48h
al=10h

I want to be able to read and print the command line to a string in a COM program.

This is essentially what I am attempting. It's not working.
Code:
use16
org 256

call cmdline

mov dx,cmdlineparams
call strecho

int 32

cmdline:

        mov dx,cmdlineparams
        mov ax,18448
        int 47

ret

strecho:

        mov si,dx
        nextchar:
        mov al,byte [ds:si]
        cmp al,0
        jz echoed
        inc si
        call strcharecho
        jmp nextchar
        echoed:

ret

strcharecho:

        mov ah,14
        int 16

ret

cmdlineparams db "",0
rb 1023
    


I'm reading around about this having something do with the command line being in PSP, but I am not sure what to do.

_________________
http://www.basicgames.xyz
Post 22 Jan 2023, 03:10
View user's profile Send private message Visit poster's website Reply with quote
macomics



Joined: 26 Jan 2021
Posts: 701
Location: Russia
macomics 22 Jan 2023, 08:31
You don't need functions to access the command line. It is written in the PSP of the program at the relative address 128 (80h) and has the following format.
Code:
cmd_length db ? ; PSP+80h
cmd_string db 7Fh dup (?) ; PSP+81h    


cmd_line.asm
Code:
format binary as "COM"
org 256
use16

label CMD_LENGTH byte at 128
label CMD_STRING byte at 129

; fwrite as is
    mov dx, CMD_STRING ; ds:dx = PSP+81h
    movzx cx, [CMD_LENGTH] ; cx = byte ptr PSP+80h
    mov bx, 1 ; stdout (CON)
    mov ah, 64 ; fWrite
    int 33

; move
    cld
    lea di, [buffer]
    lea si, [CMD_STRING]
    movzx cx, [CMD_LENGTH]
    rep movs byte [di], [si]
    mov al, '$' ; EOLN
    stos byte [di]

; print
    lea dx, [buffer]
    mov ah, 9 ; Print line
    int 33

; wait key
    mov ah, 7 ; read key (without echo)
    int 33

; exit
    mov ax, 76 * 256 + 0 ; exit to DOS (code = 0)
    int 33

buffer rb 128    


Description:
Filesize: 1.28 KB
Viewed: 670 Time(s)

cmd_line.png


Post 22 Jan 2023, 08:31
View user's profile Send private message Reply with quote
DimonSoft



Joined: 03 Mar 2010
Posts: 1155
Location: Belarus
DimonSoft 22 Jan 2023, 20:41
May I also add my 5 pennies of offtopic? I find it quite an arguable style to use decimal value representation for stuff that is almost everywhere written/described/explained in hexadecimal. Besides making the code look different from what a debugger would show by default (which makes it harder to the author (and those who try to help them) to debug), it might also force people make mistakes. Say, it’s quite easy to mix int 16 and int 16h. The former is the BIOS video stuff interrupt, the latter is for keyboard input stuff. single letter of difference makes it easy to miss it and treat one thing as another.

Programming large projects is already hard enough. Why make it even harder for ourselves?
Post 22 Jan 2023, 20:41
View user's profile Send private message Visit poster's website Reply with quote
sinsi



Joined: 10 Aug 2007
Posts: 767
Location: Adelaide
sinsi 23 Jan 2023, 05:04
Isn't INT 2Fh 4810h a DosKey interrupt and nothing to do with a command line?

DimonSoft, agree 100% - it's weird seeing INT 33 everywhere (that's the mouse interrupt? 33H) for DOS INT 21H calls Smile
Just to confuse things even more, MASM had .radix which treated numbers differently, .radix 10 (the default) and .radix 16 (so you didn't have to use 'H')
Post 23 Jan 2023, 05:04
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 19121
Location: In your JS exploiting you and your system
revolution 23 Jan 2023, 05:23
I prefer a prefix instead of a postfix.
Code:
int 0x21 ; good
int 21h ; bad (IMO) Razz    
Tell me how to parse it before I start parsing, not after I have already passed it to find the postfix. Smile

But best is to use a symbolic constant:
Code:
DOS_INTERRUPT = 0x21 ; best
;...
int DOS_INTERRUPT    
Post 23 Jan 2023, 05:23
View user's profile Send private message Visit poster's website Reply with quote
sinsi



Joined: 10 Aug 2007
Posts: 767
Location: Adelaide
sinsi 23 Jan 2023, 06:58
0x21 begone, demon of C
DOS_INTERRUPT waaaay too much typing
Smile
Post 23 Jan 2023, 06:58
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 19121
Location: In your JS exploiting you and your system
revolution 23 Jan 2023, 07:17
Copy + Paste
Post 23 Jan 2023, 07:17
View user's profile Send private message Visit poster's website Reply with quote
sinsi



Joined: 10 Aug 2007
Posts: 767
Location: Adelaide
sinsi 23 Jan 2023, 08:50
edlin didn't have such fancy stuff
Post 23 Jan 2023, 08:50
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 19121
Location: In your JS exploiting you and your system
revolution 23 Jan 2023, 08:56
Code:
DOS = 0x21
;...
int DOS    
Same character count as int 21h, but better. Razz
Post 23 Jan 2023, 08:56
View user's profile Send private message Visit poster's website Reply with quote
macomics



Joined: 26 Jan 2021
Posts: 701
Location: Russia
macomics 23 Jan 2023, 10:14
Ahh
Code:
format binary as "COM"
org 256
use16

label CMD_LENGTH byte at 128
label CMD_STRING byte at 129

DOS equ int 0x21

; fwrite as is
    mov dx, CMD_STRING ; ds:dx = PSP+81h
    movzx cx, [CMD_LENGTH] ; cx = byte ptr PSP+80h
    mov bx, 1 ; stdout (CON)
    mov ah, 64 ; fWrite
    DOS

; move
    cld
    lea di, [buffer]
    lea si, [CMD_STRING]
    movzx cx, [CMD_LENGTH]
    rep movs byte [di], [si]
    mov al, '$' ; EOLN
    stos byte [di]

; print
    lea dx, [buffer]
    mov ah, 9 ; Print line
    DOS

; wait key
    mov ah, 7 ; read key (without echo)
    DOS

; exit
    mov ax, 76 * 256 + 0 ; exit to DOS (code = 0)
    DOS

buffer rb 128    
So very shortly
Post 23 Jan 2023, 10:14
View user's profile Send private message Reply with quote
DimonSoft



Joined: 03 Mar 2010
Posts: 1155
Location: Belarus
DimonSoft 24 Jan 2023, 14:20
revolution wrote:
I prefer a prefix instead of a postfix.
Code:
int 0x21 ; good
int 21h ; bad (IMO) Razz    
Tell me how to parse it before I start parsing, not after I have already passed it to find the postfix. Smile

I prefer being paid for my code then, instead of having zeroes all over:
Code:
int $21    
Smile Well, in fact I just hate the C ecosystem and its artefacts, so 21h looks like a neutral choice to avoid holy wars.

revolution wrote:
Code:
DOS = 0x21 ; best
;...
int DOS    

Very confusing for Spanish-speaking people Smile
Post 24 Jan 2023, 14:20
View user's profile Send private message Visit poster's website Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 19121
Location: In your JS exploiting you and your system
revolution 24 Jan 2023, 14:47
I don't care who designs the mousetrap. If it is better then I will use it.

Even if Satan herself designed the best mousetrap, I would use it simply because it is the best. Twisted Evil
Post 24 Jan 2023, 14:47
View user's profile Send private message Visit poster's website Reply with quote
DimonSoft



Joined: 03 Mar 2010
Posts: 1155
Location: Belarus
DimonSoft 26 Jan 2023, 08:12
Do you have an option to avoid mousetraps?
Post 26 Jan 2023, 08:12
View user's profile Send private message Visit poster's website Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 19121
Location: In your JS exploiting you and your system
revolution 26 Jan 2023, 08:20
DimonSoft wrote:
Do you have an option to avoid mousetraps?
The context was entering hex numbers. So, yes, you can avoid using any hex numbers. Convert everything to decimal forever.
Code:
mov eax,805306371 ; the bit mask, it is so much better in decimal Razz    
Post 26 Jan 2023, 08:20
View user's profile Send private message Visit poster's website Reply with quote
al_Fazline



Joined: 24 Oct 2018
Posts: 44
al_Fazline 26 Jan 2023, 09:21
I'd rather have everybody switch to hex everywhere, why not? Though then, preferably there would be completely new digits for A-F so it can't be confused with written words.

Or a 12-base system would be superior to decimal but unfortunately it didn't get traction.

Though English still has some traces of it, as 11 and 12 are called eleven and twelve instead of oneteen and twoteen.
Post 26 Jan 2023, 09:21
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 19121
Location: In your JS exploiting you and your system
revolution 26 Jan 2023, 09:41
al_Fazline wrote:
I''d rather have everybody switch to hex everywhere, why not?
Agreed. It is the genetic modification to grow six more fingers that gets tricky.
al_Fazline wrote:
Though then, preferably there would be completely new digits for A-F so it can''t be confused with written words.
Use Arabic: ۰۱۲۳۴۵.
Post 26 Jan 2023, 09:41
View user's profile Send private message Visit poster's website Reply with quote
al_Fazline



Joined: 24 Oct 2018
Posts: 44
al_Fazline 26 Jan 2023, 09:53
I think they are not quite distinct. Also try to think something you can display on 7-segment indicator.

Quote:

It is the genetic modification to grow six more fingers that gets tricky.

This is completely unnecessary. Does anybody count with fingers still?
Post 26 Jan 2023, 09:53
View user's profile Send private message Reply with quote
DimonSoft



Joined: 03 Mar 2010
Posts: 1155
Location: Belarus
DimonSoft 26 Jan 2023, 20:08
al_Fazline wrote:
I'd rather have everybody switch to hex everywhere, why not? Though then, preferably there would be completely new digits for A-F so it can't be confused with written words.

For backwards compatibility it’s not a matter of choosing one silver bullet for every purpose but to choose the most convenient for particular usecase. There’re $7C00 bytes (not 31744) from the beginning of the real-mode address space till the place a bootloader starts from, and PE EXE by default has image base of $400000 (not 4'194'304), but there’re 365 or 366 days in a year (not $16D or $16E). Recognizability causes better mental performance for those who read the code, including the code’s author.
Post 26 Jan 2023, 20:08
View user's profile Send private message Visit poster's website Reply with quote
geekbasic@gmx.com



Joined: 25 Oct 2022
Posts: 65
Location: Arizona
geekbasic@gmx.com 26 Jan 2023, 21:51
I got your example working, thank you.

People will write code in various ways. We should be thankful that FASM has such a flexible syntax.

There seems to be conflicting documentation regarding int 2fh ax=4810h

My source is "The Programmers PC Sourcebook" by Thom Hogan from Microsoft Press dated 1991.

What is my book referring to if not the Command Line?


Description:
Filesize: 637.56 KB
Viewed: 442 Time(s)

int 2fh ax=4810h.jpg



_________________
http://www.basicgames.xyz
Post 26 Jan 2023, 21:51
View user's profile Send private message Visit poster's website Reply with quote
sinsi



Joined: 10 Aug 2007
Posts: 767
Location: Adelaide
sinsi 26 Jan 2023, 23:15
Post 26 Jan 2023, 23:15
View user's profile Send private message Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  
Goto page 1, 2  Next

< 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-2023, Tomasz Grysztar. Also on GitHub, YouTube, Twitter.

Website powered by rwasa.