From: Nate Eldredge Newsgroups: comp.os.msdos.djgpp Subject: Re: self-mod code and DJGPP - writable code segment? Date: 14 Mar 2000 00:26:28 -0800 Organization: InterWorld Communications Lines: 30 Message-ID: <838zzmdkjv.fsf@mercury.st.hmc.edu> References: <8ak78h$dsd$1 AT mulga DOT cs DOT mu DOT OZ DOT AU> NNTP-Posting-Host: mercury.st.hmc.edu Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: nntp1.interworld.net 953022513 54510 134.173.45.219 (14 Mar 2000 08:28:33 GMT) X-Complaints-To: usenet AT nntp1 DOT interworld DOT net NNTP-Posting-Date: 14 Mar 2000 08:28:33 GMT User-Agent: Gnus/5.0802 (Gnus v5.8.2) Emacs/20.5 To: djgpp AT delorie DOT com DJ-Gateway: from newsgroup comp.os.msdos.djgpp Reply-To: djgpp AT delorie DOT com apsh AT ecr DOT mu DOT oz DOT au (Alistair_P SHILTON) writes: > I was wondering if it is possible to link self-modifying assembler > code to DJGPP. When I try, I get an error message. So I checked > the documentation, which says that the code segment is not writable. > Is there some way around this? > > I was planning to use the self-mod to make the code act differently > after the first call to it (ie. setup on first call, normal operation > on subsequent calls). Now I know that there are other ways of achieving > the same end, but I like the concept of self-modding code. Any > suggestions? The code segment, as addressed via the CS register, is not writable, true. This is a feature of the cpu. However, the DS segment addresses exactly the same memory (in DJGPP) and is writable. So something like this should work: movb interrupt_number, %al movb %al, modify_here+1 modify_here: int 0x42 Do be careful to make sure you write it maintainably, though. Self-modifying code is dangerous in that respect. -- Nate Eldredge neldredge AT hmc DOT edu