flat assembler
Message board for the users of flat assembler.

Index > DOS > EXE vs COM | Dos Read String/Output String Error

Goto page Previous  1, 2
Author
Thread Post new topic Reply to topic
Tomasz Grysztar



Joined: 16 Jun 2003
Posts: 7756
Location: Kraków, Poland
Tomasz Grysztar
revolution wrote:
Then you want to use:
Code:
format mz    
But then you will need to include sections references and you wouldn't want to use org 0x100. See the "multiseg" MZ file example in the fasm download example folder.
The MZ executable also immediately follows the PSP segment in memory, and you have PSP in DS/ES at program startup - so if you don't define any segment and use "org 100h" instead, the things still should work for you, EXCEPT the "int 20h" to exit application, because it needs to have PSP in CS, and default entry point set up by fasm will be a pointer to first segment of executable (which is just after PSP).
Post 11 Mar 2012, 09:33
View user's profile Send private message Visit poster's website Reply with quote
Tomasz Grysztar



Joined: 16 Jun 2003
Posts: 7756
Location: Kraków, Poland
Tomasz Grysztar
DOS386 wrote:
DOS is dumb so your "format binary org $0100" may work, but it's faulty.
DOS recognizes the executable by its header, not by extension. If was always allowing to have MZ disguised as .COM and vice versa.
Post 11 Mar 2012, 09:35
View user's profile Send private message Visit poster's website Reply with quote
DOS386



Joined: 08 Dec 2006
Posts: 1901
DOS386
> DOS recognizes the executable by its header, not by extension

Right ... but it's still dumb. Rename "FASM.TXT" into "FASM.COM" and type "FASM" -> hangs Very Happy

IIRC DOS will even hapilly "launch" an empty ZERO-Byte's-file and hang Very Happy

Anything without MZ "qualifies" as DOS COM ...
Post 11 Mar 2012, 09:39
View user's profile Send private message Reply with quote
freecrac



Joined: 19 Oct 2011
Posts: 117
Location: Germany Hamburg
freecrac
drewtoby wrote:
Hello, I am new to dos Shocked and am working on a basic dos code inspired by: http://www.skynet.ie/~darkstar/assembler/tut5.html

Only I want mine to read a 15 character input and then output it to the screen. Nothing too hard.

Ralf Browns x86/MSDOS Interrupt List (RBIL)
http://www.pobox.com/~ralf
http://www.pobox.com/~ralf/files.html
ftp://ftp.cs.cmu.edu/afs/cs.cmu.edu/user/ralf/pub/

RBIL->inter61a.zip->Interrup.a
Quote:

--------V-100E-------------------------------
INT 10 - VIDEO - TELETYPE OUTPUT
AH = 0Eh
AL = character to write
BH = page number
BL = foreground color (graphics modes only)
Return: nothing
Desc: display a character on the screen, advancing the cursor and scrolling
the screen as necessary
Notes: characters 07h (BEL), 08h (BS), 0Ah (LF), and 0Dh (CR) are interpreted
and do the expected things
IBM PC ROMs dated 1981/4/24 and 1981/10/19 require that BH be the same
as the current active page
BUG: if the write causes the screen to scroll, BP is destroyed by BIOSes
for which AH=06h destroys BP
SeeAlso: AH=02h,AH=06h,AH=0Ah

RBIL->inter61b.zip->Interrup.f
Quote:

--------D-20---------------------------------
INT 20 - DOS 1+ - TERMINATE PROGRAM
CS = PSP segment
Return: never
Notes: (see INT 21/AH=00h)
this function sets the program's return code (ERRORLEVEL) to 00h
SeeAlso: INT 21/AH=00h,INT 21/AH=4Ch

--------D-2100-------------------------------
INT 21 - DOS 1+ - TERMINATE PROGRAM
AH = 00h
CS = PSP segment
Notes: Microsoft recommends using INT 21/AH=4Ch for DOS 2+
this function sets the program's return code (ERRORLEVEL) to 00h
execution continues at the address stored in INT 22 after DOS performs
whatever cleanup it needs to do (restoring the INT 22,INT 23,INT 24
vectors from the PSP assumed to be located at offset 0000h in the
segment indicated by the stack copy of CS, etc.)
if the PSP is its own parent, the process's memory is not freed; if
INT 22 additionally points into the terminating program, the
process is effectively NOT terminated
not supported by MS Windows 3.0 DOSX.EXE DOS extender
SeeAlso: AH=26h,AH=31h,AH=4Ch,INT 20,INT 22
--------D-2101-------------------------------
INT 21 - DOS 1+ - READ CHARACTER FROM STANDARD INPUT, WITH ECHO
AH = 01h
Return: AL = character read
Notes: ^C/^Break are checked, and INT 23 executed if read
^P toggles the DOS-internal echo-to-printer flag
^Z is not interpreted, thus not causing an EOF if input is redirected
character is echoed to standard output
standard input is always the keyboard and standard output the screen
under DOS 1.x, but they may be redirected under DOS 2+
SeeAlso: AH=06h,AH=07h,AH=08h,AH=0Ah

--------D-2102-------------------------------
INT 21 - DOS 1+ - WRITE CHARACTER TO STANDARD OUTPUT
AH = 02h
DL = character to write
Return: AL = last character output (despite the official docs which state
nothing is returned) (at least DOS 2.1-7.0)
Notes: ^C/^Break are checked, and INT 23 executed if pressed
standard output is always the screen under DOS 1.x, but may be
redirected under DOS 2+
the last character output will be the character in DL unless DL=09h
on entry, in which case AL=20h as tabs are expanded to blanks
if standard output is redirected to a file, no error checks (write-
protected, full media, etc.) are performed
SeeAlso: AH=06h,AH=09h

--------D-2109-------------------------------
INT 21 - DOS 1+ - WRITE STRING TO STANDARD OUTPUT
AH = 09h
DS:DX -> '$'-terminated string
Return: AL = 24h (the '$' terminating the string, despite official docs which
state that nothing is returned) (at least DOS 2.1-7.0 and
NWDOS)
Notes: ^C/^Break are checked, and INT 23 is called if either pressed
standard output is always the screen under DOS 1.x, but may be
redirected under DOS 2+
under the FlashTek X-32 DOS extender, the pointer is in DS:EDX
SeeAlso: AH=02h,AH=06h"OUTPUT"
--------D-210A-------------------------------
INT 21 - DOS 1+ - BUFFERED INPUT
AH = 0Ah
DS:DX -> buffer (see #01344)
Return: buffer filled with user input
Notes: ^C/^Break are checked, and INT 23 is called if either detected
reads from standard input, which may be redirected under DOS 2+
if the maximum buffer size (see #01344) is set to 00h, this call returns
immediately without reading any input
SeeAlso: AH=0Ch,INT 2F/AX=4810h

Format of DOS input buffer:
Offset Size Description (Table 01344)
00h BYTE maximum characters buffer can hold
01h BYTE (call) number of chars from last input which may be recalled
(ret) number of characters actually read, excluding CR
02h N BYTEs actual characters read, including the final carriage return

RBIL->inter61b.zip->Interrup.g
Quote:

--------D-214C-------------------------------
INT 21 - DOS 2+ - "EXIT" - TERMINATE WITH RETURN CODE
AH = 4Ch
AL = return code
Return: never returns
Notes: unless the process is its own parent
(see #01378 [offset 16h] at AH=26h), all open files are closed and
all memory belonging to the process is freed
all network file locks should be removed before calling this function
SeeAlso: AH=00h,AH=26h,AH=4Bh,AH=4Dh,INT 15/AH=12h/BH=02h,INT 20,INT 22
SeeAlso: INT 60/DI=0601h

Dirk
Post 11 Mar 2012, 09:47
View user's profile Send private message Send e-mail Reply with quote
Tomasz Grysztar



Joined: 16 Jun 2003
Posts: 7756
Location: Kraków, Poland
Tomasz Grysztar
DOS386 wrote:
Right ... but it's still dumb. Rename "FASM.TXT" into "FASM.COM" and type "FASM" -> hangs Very Happy

IIRC DOS will even hapilly "launch" an empty ZERO-Byte's-file and hang Very Happy

Anything without MZ "qualifies" as DOS COM ...
I thought there was some beauty in this naïve simplicity. Wink

BTW, to convert the source of .com program into MZ executable, it should work to put this on top of the source:
Code:
        format  MZ
        segment text
        PSP = text - 10h
        entry   PSP:start
        stack   PSP:0FFFEh

        org     100h 
        ...    
It emulates most of the things, but exiting program with RET might not work, because the word that is at 0FFFEh offset might not be zero (you could make sure that it is zero by putting "db (10000h-$) dup 0" at the end of source, but that would be very crude).
And, as another side note, this is a kind of .com to .exe conversion that fasm does when you specify a non-MZ file as a stub for PE.
Post 11 Mar 2012, 09:51
View user's profile Send private message Visit poster's website Reply with quote
shutdownall



Joined: 02 Apr 2010
Posts: 518
Location: Munich
shutdownall
drewtoby wrote:
@shutdownall: tried to get your code to display 0 after any string has been entered, only the zero will display over and over again once a char is entered. Well, it has the beeping and random chars (charector) outputs over and over again Mad. Just like my code above Sad

Code:
format binary as "EXE"

org 0x100 

Start: 

;Print String-------------------------------------------------------- 

mov ah,09   ;start with input
int 21h    ;call the interupt
dec bl      ;have dl register limit string to 10 chars
mov bl,10     ;finishing ^
mov dx, msg  ;has dx display 0, in theory  Laughing 
int 21h  ;interupt

msg  db '0' ;the zero, held in a variable


    


So what can I do to fix both of my codes, anyone?


First, you call print function (ah,9) but you do not set dx register.
dx has to point to the string you want to display.
So what the hell should the funtion print instead of some random data.

Second, string has to end with '$' not with 0. I put the 0 at the end because it looks nicer, but not necessary. But '$' is necessary.

Third, you have to manually exit the program with int 21h and ah,0.
If you do not, program will continue and execute the code at label msg. Which causes CPU to execute random data.

You should read the DOS functions carefully, what you need for input and what is output. Also take in mind that some register contents are destroyed after calling int 21h. Normally ax is used as feedback, contains 0 if function successful or error code if not successful. Not always. int 21h functions are very simple but you have to read the manual carefully. I propose to use Ralph Brown's interrupt list, can find with google.
Post 11 Mar 2012, 20:35
View user's profile Send private message Send e-mail Reply with quote
avcaballero



Joined: 02 Feb 2004
Posts: 191
Location: Madrid - Spain
avcaballero
Maybe help... but only com source, most of them nasm sintax

URL NForum.7z

* Age. Asked how old are you, and you have to insert it using keyboard. The program answer accordingly your age.
* Guess. Game of the secret number between 1 and 30.
* GuessF. The same for the FASM compiler.
* Length. Returns the length of a string.
* Rpstrcn1. Replace one string within another.
* Strings. Prints a string and its length.

Regards

_________________
Siempre aprendiendo
Post 12 Mar 2012, 09:17
View user's profile Send private message Visit poster's website Reply with quote
drewtoby



Joined: 05 Mar 2012
Posts: 19
drewtoby
Okay, thanks! I'll look over those the next couple days, and they should help a lot!!!!!
Post 12 Mar 2012, 23:56
View user's profile Send private message Reply with quote
shutdownall



Joined: 02 Apr 2010
Posts: 518
Location: Munich
shutdownall
drewtoby wrote:
Okay, thanks! I'll look over those the next couple days, and they should help a lot!!!!!


Believe me, reading carefully helps more than just to take a look on the code.
Regardless what documentation or examples you use. Cool
Post 13 Mar 2012, 00:06
View user's profile Send private message Send e-mail Reply with quote
p3rlphr33k



Joined: 22 Dec 2009
Posts: 17
Location: Grand Forks ND
p3rlphr33k
I am only coding this to learn the language so please dont make fun of my awful code Sad

I had the same issue with getting symbols and beeps, i managed to get passed the issue, but now it appears the text is being hidden by previous lines (if this makes sense). Any one seen this type of problem before?

Here is my learning code:
Code:
org 256                             ;make COM instead of BIN

mov ah,09h
mov dx,mesg
int 21h
jmp FETCH

FETCH:
mov ah,0Ah                          ;call keyboard buffered input
mov dx,buffer                       ;move buffer of 5 chars to data register
int 21h                               
jmp HELLO

HELLO:
mov ah,09h                          ;call display
mov dx,ello                         ;print hello
int 21h
jmp KEYS

KEYS:
mov ah,09h                          ;call display
mov dx,buffer                       ;mov buffer
int 21h                            
jmp BR

BR:
mov ah,09h
mov dx,CRLF
int 21h
jmp FETCH

EXIT:
mov ax,4C00h                        ;call EXIT
int 21h                            

buffer db 10                        ;Buffer of 10

mesg db 'Welcome to test',13,10,'Enter text:','$'
ello db 'Hello $'
CRLF db 13,10
db '$'                                                    ;rest db to NULL
    


I think I might need to clear the screen before printing the buffer. Would that solve my problem?

PS - I know the code loops, i plan on adding CMP soon to read input

_________________
-p3rlphr33k-
(Soon to be ASMphr33k)
Post 07 Apr 2012, 03:17
View user's profile Send private message Visit poster's website Yahoo Messenger MSN Messenger ICQ Number Reply with quote
Picnic



Joined: 05 May 2007
Posts: 1288
Location: behind the arc
Picnic
Hi p3rlphr33k,

The INT 21h / AH=0Ah is a bit more complex, however not difficult.

Checkout these links 1 2
Post 07 Apr 2012, 07:07
View user's profile Send private message Reply with quote
freecrac



Joined: 19 Oct 2011
Posts: 117
Location: Germany Hamburg
freecrac
Try this sample:
Code:
mov ah,0Ah                    ; call keyboard buffered input
mov dx,buffer                 ; move buffer of 10 chars to data register
mov si,dx                     ; store address of buffer
int 21h                               

xor bx,bx                     ; clear register
mov bl,[si+01h]               ; number of chars from last input
mov [si+bx+3],"$"             ; after CR we place a "$"
mov ah,09h                    ; call display
mov dx,buffer+02h             ; mov buffer
int 21h                            

EXIT:
mov ax,4C00h                  ; call EXIT
int 21h                            

buffer db 10, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, "$" 
; Format of DOS input buffer:
; Offset Size Description (Table 01344)
; 00h BYTE maximum characters buffer can hold
; 01h BYTE (call) number of chars from last input which may be recalled (ret) number of characters actually read, excluding CR
; 02h N BYTEs actual characters read, including the final carriage return (placeholder for 10 chars + CR)
;--------------------------------------
; $ (placeholder for string output function 09h)
    

Dirk
Post 07 Apr 2012, 18:46
View user's profile Send private message Send e-mail Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  
Goto page Previous  1, 2

< 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. Also on YouTube, Twitter.

Website powered by rwasa.