Mail Archives: djgpp/2000/03/14/06:29:27
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
- Raw text -