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 |
|
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
|
||||||||||
22 Jan 2023, 08:31 |
|
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? |
|||
22 Jan 2023, 20:41 |
|
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 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') |
|||
23 Jan 2023, 05:04 |
|
revolution 23 Jan 2023, 05:23
I prefer a prefix instead of a postfix.
Code: int 0x21 ; good int 21h ; bad (IMO) But best is to use a symbolic constant: Code: DOS_INTERRUPT = 0x21 ; best ;... int DOS_INTERRUPT |
|||
23 Jan 2023, 05:23 |
|
sinsi 23 Jan 2023, 06:58
0x21 begone, demon of C
DOS_INTERRUPT waaaay too much typing |
|||
23 Jan 2023, 06:58 |
|
revolution 23 Jan 2023, 07:17
Copy + Paste
|
|||
23 Jan 2023, 07:17 |
|
sinsi 23 Jan 2023, 08:50
edlin didn't have such fancy stuff
|
|||
23 Jan 2023, 08:50 |
|
revolution 23 Jan 2023, 08:56
Code: DOS = 0x21 ;... int DOS |
|||
23 Jan 2023, 08:56 |
|
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 |
|||
23 Jan 2023, 10:14 |
|
DimonSoft 24 Jan 2023, 14:20
revolution wrote: I prefer a prefix instead of a postfix. I prefer being paid for my code then, instead of having zeroes all over: Code: int $21 revolution wrote:
Very confusing for Spanish-speaking people |
|||
24 Jan 2023, 14:20 |
|
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. |
|||
24 Jan 2023, 14:47 |
|
DimonSoft 26 Jan 2023, 08:12
Do you have an option to avoid mousetraps?
|
|||
26 Jan 2023, 08:12 |
|
revolution 26 Jan 2023, 08:20
DimonSoft wrote: Do you have an option to avoid mousetraps? Code: mov eax,805306371 ; the bit mask, it is so much better in decimal |
|||
26 Jan 2023, 08:20 |
|
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. |
|||
26 Jan 2023, 09:21 |
|
revolution 26 Jan 2023, 09:41
al_Fazline wrote: I''d rather have everybody switch to hex everywhere, why not? al_Fazline wrote: Though then, preferably there would be completely new digits for A-F so it can''t be confused with written words. |
|||
26 Jan 2023, 09:41 |
|
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:
This is completely unnecessary. Does anybody count with fingers still? |
|||
26 Jan 2023, 09:53 |
|
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. |
|||
26 Jan 2023, 20:08 |
|
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?
|
||||||||||
26 Jan 2023, 21:51 |
|
sinsi 26 Jan 2023, 23:15
|
|||
26 Jan 2023, 23:15 |
|
Goto page 1, 2 Next < Last Thread | Next Thread > |
Forum Rules:
|
Copyright © 1999-2024, Tomasz Grysztar. Also on GitHub, YouTube.
Website powered by rwasa.