flat assembler
Message board for the users of flat assembler.

Index > DOS > Simple trouble. (List of formats?)

Author
Thread Post new topic Reply to topic
PerryTachett



Joined: 08 Jun 2008
Posts: 5
PerryTachett 08 Jun 2008, 23:22
I am having a very basic trouble.
The following code doesn't output a D:
Code:
format MZ
jmp start
;=============
 hello    db 68
;=============
start:
  mov AH, 02
  mov DL, byte [hello]
  int 21h   ;Display a D!

  mov AH, 4Ch   ;Exit
  mov AL, 00
  int 21h
    


Now, when I insert "mov [hello], 68", it works fine.
I take this to mean that the variable isn't initialized to 68.

Is this related to the format?

I have been using: "format MZ"

What other formats are there?
In which of them can I get my precious DOS interrupts?
Well... actually any format where I have easy console output is okay.
Post 08 Jun 2008, 23:22
View user's profile Send private message Reply with quote
DOS386



Joined: 08 Dec 2006
Posts: 1905
DOS386 08 Jun 2008, 23:32
> flat assembler > Windows > Simple trouble. (List of formats?)
> I have been using: "format MZ"

Wrong forum. Sad Please make a decision whether you want to develop for DOS of for Windaube first Wink

> Is this related to the format?

NO. "push cs pop ds" missing.

> it works fine.

But isn't. You are trashing your PSP. It's a severe BUG Sad

> What other formats are there?

RTFM

> In which of them can I get my precious DOS interrupts?

All (binary, MZ, COFF, PE (YES !!!), ELF (theoretically only, no usefulness by now) ... as long as you develop for DOS Wink

> Well... actually any format where I have easy console output is okay.

Again, it's not the format, it's the target OS Wink
Post 08 Jun 2008, 23:32
View user's profile Send private message Reply with quote
PerryTachett



Joined: 08 Jun 2008
Posts: 5
PerryTachett 08 Jun 2008, 23:49
First off, thank you.
I can't believe I missed something so basic. (About push cs pop ds)
I am used to A86, with COM files, and not needing stuff like that.
Also, about the list of formats, I couldn't find it.
I looked in TFM that I Red, but to no avail.
Where is such a list located? (Or is that too something obvious that I missed?)
Post 08 Jun 2008, 23:49
View user's profile Send private message Reply with quote
DOS386



Joined: 08 Dec 2006
Posts: 1905
DOS386 09 Jun 2008, 00:07
> Where is such a list located?

http://flatassembler.net/docs.php?article=manual#2.4

+ my post above Wink

> Or is that too something obvious that I missed

NO, it's unique to FASM, not really obvious.

> I am used to A86, with COM files, and not needing stuff like that.

Right, DOS COM files don't need it (but it won't hurt if inserted nevertheless).

You main problem is that A86 is most likely a DOS-only ASM (I don't use it), and DOS COM is a DOS-only executable format ... it won't run natively in Windaube (it might run using (auto-invoked) "NTVDM" hack ... but then don't ask how to access physical disks, how to OGL, how to VESA, how to RDMSR, how to increase priority, and why it doesn't work on 64 bits Laughing ).

http://board.flatassembler.net/topic.php?t=6735 MZ via binary, MZ, PE via binary
http://board.flatassembler.net/topic.php?t=8670 DOS PE and DOS LE via binary
Post 09 Jun 2008, 00:07
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 20627
Location: In your JS exploiting you and your system
revolution 09 Jun 2008, 05:41
PerryTachett wrote:
I am used to A86, with COM files, and not needing stuff like that.
You can make COM files with fasm.
PerryTachett wrote:

Also, about the list of formats, I couldn't find it.
I looked in TFM that I Red, but to no avail.
Where is such a list located? (Or is that too something obvious that I missed?)
Section "2.4 Formatter directives".
Post 09 Jun 2008, 05:41
View user's profile Send private message Visit poster's website Reply with quote
DOS386



Joined: 08 Dec 2006
Posts: 1905
DOS386 09 Jun 2008, 09:22
> You can make COM files with fasm.

Code:
format binary as "COM"
org $0100

    jmp @f
xx: db 68
@@:
    mov dl,byte [xx]
    mov ah,2
    int $21
    mov ax,$4C00
    int $21
    


But now this should get moved into DOS or Main
Wink
Post 09 Jun 2008, 09:22
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 20627
Location: In your JS exploiting you and your system
revolution 09 Jun 2008, 10:06
From the examples that come with fasm:
Code:
; fasm example of writing 16-bit COM program

    org     100h                    ; code starts at offset 100h
        use16                           ; use 16-bit code

display_text = 9

       mov     ah,display_text
     mov     dx,hello
    int     21h

     int     20h

hello db 'Hello world!',24h    
The format directive is not needed for simple com programs.
Post 09 Jun 2008, 10:06
View user's profile Send private message Visit poster's website Reply with quote
PerryTachett



Joined: 08 Jun 2008
Posts: 5
PerryTachett 09 Jun 2008, 16:21
Urk... now I'm cornfuzzled:

Code:
format MZ

 push CS
 pop DS

  mov AH, 02
  mov DL, byte [vara]
  int 21h

  mov AH, 4Ch
  mov AL, 00
  int 21h

  vara db 'B'
    


This works fine. (Outputs a 'B')
When I add use32, it stops working.
Outputs a 't', and this doesn't change with the value in vara.
Does this mean that the 't' is the low order 8 bits of the address vara is at?
Or maybe this is a similar issue to the one I had before?
Is there some sort of special 32-bit addressing mode where I need to address it differently?
Grr... curse these 32-bit directives...
Post 09 Jun 2008, 16:21
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 20627
Location: In your JS exploiting you and your system
revolution 09 Jun 2008, 16:28
MZ format is meant for 16bit code. That means the CPU is in 16bit mode. If you start trying to use 32bit code in 16bit mode then it is not surprising that you get unexpected results. Fortunately the simple remedy is don't put in use32 when you are coding for 16bit modes.

You can still use all the 32bit registers (eax, ebx, ...) for data in 16bit mode, the assembler inserts the necessary override bytes automatically. For addressing I don't recommend you use 32bit registers unless you can guarantee that the high order 16bits are zero, else you will get an exception (read: it will crash).
Post 09 Jun 2008, 16:28
View user's profile Send private message Visit poster's website Reply with quote
System86



Joined: 15 Aug 2007
Posts: 77
System86 09 Jun 2008, 19:19
Quote:

For addressing I don't recommend you use 32bit registers unless you can guarantee that the high order 16bits are zero, else you will get an exception (read: it will crash).


Unless you switch into protected mode, load segments with 4 GB limit selectors, and switch back into real mode without restoring segment limits (aka switch into flat real mode).
Post 09 Jun 2008, 19:19
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 20627
Location: In your JS exploiting you and your system
revolution 09 Jun 2008, 19:32
System86 wrote:
Unless you switch into protected mode, load segments with 4 GB limit selectors, and switch back into real mode without restoring segment limits (aka switch into flat real mode).
Yeah, thanks, if you're an expert programmer with a good debugger then no problem. We all have to learn to walk before we can run.
Post 09 Jun 2008, 19:32
View user's profile Send private message Visit poster's website Reply with quote
DOS386



Joined: 08 Dec 2006
Posts: 1905
DOS386 09 Jun 2008, 23:06
> When I add use32, it stops working.

Read this: http://board.flatassembler.net/topic.php?t=6633

> The format directive is not needed for simple com programs.

Maybe true ... but I prefer straightforward design from black magic in the background.

> For addressing I don't recommend you use 32bit registers unless you can guarantee

Yeah ... 16-bit RM has 64 KiB segment limit Neutral

Quote:

Unless you switch into protected mode, load segments with 4 GB limit selectors, and switch back into real mode without restoring segment limits (aka switch into flat real mode).


http://board.flatassembler.net/topic.php?t=2528
Post 09 Jun 2008, 23:06
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-2025, Tomasz Grysztar. Also on GitHub, YouTube.

Website powered by rwasa.