flat assembler
Message board for the users of flat assembler.

Index > DOS > ..

Author
Thread Post new topic Reply to topic
pool



Joined: 08 Jan 2007
Posts: 97
Location: Philippines
pool
..


Last edited by pool on 17 Mar 2013, 11:44; edited 1 time in total
Post 11 Mar 2008, 06:31
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: 16861
Location: In your JS exploiting you and your system
revolution
IIRC the value of DS if undefined upon entry so we need to give a value so that DS:DX will point to the proper place.

The reason for push/pop is usually historical. We can also use mov ax,cs/mov ds,ax and other similar things, but push/pop is shorter and thus became common.
Post 11 Mar 2008, 06:46
View user's profile Send private message Visit poster's website Reply with quote
edfed



Joined: 20 Feb 2006
Posts: 4218
Location: 2018
edfed
ok!!! then, if i need to have a multisegemnted code.

cs = segmentcode
ds = segment0
es = segment1
fs = segment2
gs = segment3
ss = segment4

how can i assign the segment1 to direct to screen memory? is there a value to create in the source?

segment code:

segment data:

segment screen:

segment stack:

etc...

i never code MZ or exe... then, it's new for me.
Post 11 Mar 2008, 11:10
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: 16861
Location: In your JS exploiting you and your system
revolution
edfed wrote:
ok!!! then, if i need to have a multisegemnted code.

cs = segmentcode
ds = segment0
es = segment1
fs = segment2
gs = segment3
ss = segment4

how can i assign the segment1 to direct to screen memory? is there a value to create in the source?

segment code:

segment data:

segment screen:

segment stack:

etc...

i never code MZ or exe... then, it's new for me.
The relocation mechanism doesn't work that way. You still have to manually load your screen segment (probably 0xb800) into the segment register at runtime. eg. mov ax,0xb800/mov es,ax
Post 11 Mar 2008, 11:30
View user's profile Send private message Visit poster's website Reply with quote
edfed



Joined: 20 Feb 2006
Posts: 4218
Location: 2018
edfed
ok, but the multisegment, what does it mean? can we choose the exact value for a segment during compile? or is it just a segment symbol that don't have assigned value?

in another way, i what to make a .exe, the code segment will be 1000h, the first dta segment will be 2000h, and so on... or are these values undefined?
Post 11 Mar 2008, 11:58
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: 16861
Location: In your JS exploiting you and your system
revolution
edfed wrote:
ok, but the multisegment, what does it mean? can we choose the exact value for a segment during compile? or is it just a segment symbol that don't have assigned value?

in another way, i what to make a .exe, the code segment will be 1000h, the first dta segment will be 2000h, and so on... or are these values undefined?
You can't choose your segments, the loader will relocate your code and you have to use what you are given. Using fixed segments is a sure recipe to disaster.
Post 11 Mar 2008, 12:04
View user's profile Send private message Visit poster's website Reply with quote
DOS386



Joined: 08 Dec 2006
Posts: 1903
DOS386
pool wrote:

Quote:
Why we need to PUSH CS and POP DS in MZ format?


CS points to code (surprisingly), DS and ES to the PSP (but is this guaranteed ??? Question ) ... just try to remove them and the code will break Idea

In DOS .COM , both CS and DS point to the code, thus PUSH CS and POPE DS is not needed, but won't cause any damage if present Smile

revolution wrote:

Quote:
IIRC the value of DS if undefined upon entry so we need to give a value so that DS:DX will point to the proper place.


Seems to point to the PSP Wink

edfed wrote:

Quote:

ok!!! then, if i need to have a multisegemnted code.
cs = segmentcode
ds = segment0
es = segment1
fs = segment2
gs = segment3
ss = segment4
how can i assign the segment1 to direct to screen memory? is there a value to create in the source?


1. SS is the stack. Abusing SS or SP for anything else is VERY RISKY - DON'T DO do this except with interrupts disabled. BTW, FASM's format MZ will set up the stack for you Wink
2. You need those stupid RM code segments only if your code is > 64 KiB ... but then DPMI32 is a better choice Wink Also, FS and GS exist on >=80386 only -> then DPMI32 is better, for 8086 compatibility and > 64 KiB code, you need segments, and have only CS, DS, ES, and SS available.

revolution wrote:

Quote:
The relocation mechanism doesn't work that way. You still have to manually load your screen segment (probably 0xb800) into the segment register at runtime. eg. mov ax,0xb800/mov es,ax


Yes.

Code:
   mov   ax,$B800   ; $B800 for text, $A000 for VGA
   push  ax            
   pop   es         ; "PUSH const" is not 8086-compatible, OTOH "MOV ES,AX" would be  
    


Quote:
in another way, i what to make a .exe, the code segment will be 1000h, the first dta segment will be 2000h, and so on... or are these values undefined?


Code will be at 0 inside segment (CS:0) for MZ, absolute address is not fixed (CS=???).

EDIT: fixed bug pointed by revolution


Last edited by DOS386 on 12 Mar 2008, 01:00; edited 1 time in total
Post 12 Mar 2008, 00:42
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 16861
Location: In your JS exploiting you and your system
revolution
DOS386 wrote:
[DS] Seems to point to the PSP
Okay, I must have remembered wrongly
DOS386 wrote:
Neither PUSH const nor MOV ES,AX is 8086-compatible
"mov es,ax" is perfectly valid in 8086.
Post 12 Mar 2008, 00:50
View user's profile Send private message Visit poster's website 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-2019, Tomasz Grysztar.

Powered by rwasa.