flat assembler
Message board for the users of flat assembler.
 Home   FAQ   Search   Register 
 Profile   Log in to check your private messages   Log in 
flat assembler > DOS > real segmented memory(dos) programming

Author
Thread Post new topic Reply to topic
mns



Joined: 20 Dec 2007
Posts: 98
Location: Piliyandala,Sri lanka
real segmented memory(dos) programming
I want to call a function which is in an another *.inc file from a segmented memory programme and experimented with a test programme. Although finally i could made a working programme(attached here with), i had to make the function (in the .inc file) as a separate segment and call it from the main source as below
call segment name:function name
eg:
call extra:wrtsrn , in my programme

is there any other way that i could call a function in a .inc file with only it's function name(without segment name or without giving it a segment name in .inc file) in segmented memory programme?


Description:
Download
Filename: test1.zip
Filesize: 635 Bytes
Downloaded: 13 Time(s)

Post 26 Sep 2015, 06:56
View user's profile Send private message Send e-mail Reply with quote
ACP



Joined: 23 Sep 2006
Posts: 196
Since you've declared another segment named "extra" you need to call functions from include file using segment:offset. Remove segment keyword from the inc file and move include keyword (test1.asm) a bit down after the main segment definition. This will do the trick.

Basically there is no need to define separate segments unless you have a reason to do it like heaving more then 64kb of code so you can't fit it into single code segment. As for FASM you can even reference other labels (data, code) from include files that are defined in main source file. Could be useful for larger projects.
Post 26 Sep 2015, 08:11
View user's profile Send private message Reply with quote
mns



Joined: 20 Dec 2007
Posts: 98
Location: Piliyandala,Sri lanka
thanks ACP. I tried by including .inc in data segment(of the main programme) +without another code segment name in .inc file but failed.(in vbox winxp system).then only i came up with above solution.
Post 26 Sep 2015, 17:18
View user's profile Send private message Send e-mail Reply with quote
ACP



Joined: 23 Sep 2006
Posts: 196
You are welcome.

Placing code in data segment is a good idea in most cases and could be considered bad practice generally speaking. DOS compatible systems are quite flexible due to their simplicity but more modern operating systems working in protected/long mode will not allow you to execute code from data section (or stack) without actually marking the memory as executable. Stick to the solution I've gave you and you will be fine Smile
Post 26 Sep 2015, 18:17
View user's profile Send private message Reply with quote
mns



Joined: 20 Dec 2007
Posts: 98
Location: Piliyandala,Sri lanka
ACP, i'm afraid you didn't understand what i.ve said.i tried lot of things including your solution they all show either empty console which has to be close forcefully or continuous loop of my strings(character strings in data section) printed in console window (in winxp) which also have to forcefully close.
Post 27 Sep 2015, 05:16
View user's profile Send private message Send e-mail Reply with quote
ACP



Joined: 23 Sep 2006
Posts: 196
This is one way to make your code working. I don't know why are you touching ES register in second file. Also pusha/popa does not touch segment registers so either add push ds / pop ds at your procedure or you have to reinitializate it after returning to main if you are about to add more code reference data using DS.

test1.asm



Code:

 format MZ
 heap   0
 stack 64
 entry main:start

segment main use16


start:
  mov  ax,data1
  mov  ds,ax
  mov  es,ax

 mov   dx,txt1
 mov     ah,9h
 int     21h

 call wrtsrn

 xor   ah,ah
 int   16h

 mov   ax,4c00h
 int   21h

include 'wrtsrn.inc'

;--------------------------------------------------------------------------------------------------------------------------------------------------
;------------------------------------------------------------data-------------------------------------------------------------------------
 segment data1

txt1 db 'testing segmented mode',24h




wrtsrn.inc:

Code:

;wrtsrn.inc-----------------------

wrtsrn:

pusha
mov  ax,data2
mov  ds,ax
mov  es,ax
mov     ah,9h
mov     dx,text
int     21h
popa
ret


segment data2
text db 9h,'hello world',24h


Post 27 Sep 2015, 08:24
View user's profile Send private message Reply with quote
mns



Joined: 20 Dec 2007
Posts: 98
Location: Piliyandala,Sri lanka
Thank you very much ACP pointing it out that mistakes and correcting me.Very Happy
so it is, where you include .inc file in the main program matters. it should include in the end of the code segment of the main programme then?
Post 27 Sep 2015, 17:20
View user's profile Send private message Send e-mail Reply with quote
ACP



Joined: 23 Sep 2006
Posts: 196

mns wrote:
Thank you very much ACP pointing it out that mistakes and correcting me.Very Happy
so it is, where you include .inc file in the main program matters. it should include in the end of the code segment of the main programme then?



No. It is included there due to a fact that you declare in inc file additional data segment and the way FASM is creating segments in MZ EXE file.
Post 27 Sep 2015, 17:53
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


Powered by phpBB © 2001-2005 phpBB Group.

Main index   Download   Documentation   Examples   Message board
Copyright © 2004-2016, Tomasz Grysztar.