Skip to main content
GameDev.net gamedev.net
🔒 Locked

Self modifying code

Started by baskuenen May 10, 2000 at 2:05 AM 10 replies 2.4k views
Original Post
baskuenen
baskuenen
Hey fellow proggers, I''ve got a question concerning self modifying code in MSVC. When I modify the index in an instruction width inline assembly, I get an Access Violation. How do I fix this? Bas.
MadKeithV
MadKeithV
I sure as hell am not telling you, you''re programming viruses again aren''t you


#pragma DWIM // Do What I Mean!
~ Mad Keith ~
**I use Software Mode**
It's only funny 'till someone gets hurt.And then it's just hilarious.Unless it's you.
baskuenen
baskuenen
NO, NEVER, NIE, NOP!!!!

I want to use it for optimizing the inner loop of my 3D Engine.
I''m a little short on regs and want to use it like this:

add eax, xxxxxxxx
add ebx, xxxxxxxx

Setting interpolation values in them.
Speed is what I''m interrested in!
Bas.


P.S.: I must confess in the old days I wrote a virus once. But it was .com files only. Only to prove I could (virus wasn''t harmfull)
Today I despise these people: "building something is hard, to destroy something is easy."
Danack
Danack
Its probably because the memory that the actual code sits in is protected, ie you''re not meant to be able to write to it...

You should be able to define a new Data? section and tell the linker to put the code in there, rather than in the protected section....or, apparently you can tell the linker in Visual C to make a specific section readable....


but IMHO you ought to spend your time speeding the code up in other ways such as trying to improve the algorithm, which code produce a dramatic improvement in speed, rather than trying to get a small improvement by making self-modifying code, which will then be very hard to maintain.


Also just noted, one of the options is:

"P Pageable Marks the section as not pageable "

Hmm, a way to stop windows from putting the exe to swap disk? Does anybody have a ver large excutable ( and not much memory ) they can test this with?

if you define /SECTION:.text,PER (non-pageable, executable, and allow read operations) it should stop the actual executable from being swapped out....


Game production:
Good, quick, cheap: Choose two.
Game production:Good, quick, cheap: Choose two.
Rock2000
Rock2000
How is writing to the code going to be any faster than writing to a data variable?

Even if you can fake the compiler/linker into letting you write to this ''code'' segment, it pretty much won''t work anymore. I''m almost certain the code cache is not writable. So either your change won''t get out to memory, or the previously loaded code is going to be executed again anyways because its still in the cache. It may not be impossible, but you aren''t going to get a speed increase. Those days are long gone.

Rock
goltrpoat
goltrpoat
oh dear.. protected mode SMC. you don''t wanna go there. you could force cpl0 (doesnt need to be a vxd, there''s info floating around on how to do it), but isn''t that a bit of an overkill?

-goltrpoat


--
Float like a butterfly, bite like a crocodile.

--Float like a butterfly, bite like a crocodile.
CheeseGrater
CheeseGrater
This optimization is highly unlikely to speed anything up, since you''re now doing memory writes to change the code. You might as well have saved your registers into memory in the first place (which would probably be better for cache coherence).

But if you really wanna do it, I think the easiest way (though it''s been a while since I''ve needed to do this) is to put the code into a variable in your data space, and just do a jump into the variable.

I wanna reiterate, though. There are good reasons to write self-modifying code, but this probably isn''t one of them.
3dModelMan
3dModelMan
How did this old thread re-surface? Look at the date it was posted guys! I remember Bas actually posting it and he doesn''t post on here anymore (not that I''ve seen anyhow).



Main site | Free source | Email
Taulin
Taulin
I think I will dig up some old DX6 threads and respond to them by saying they should use DX8. Or better yet, find a thread where someone is saying how proud of their P2 they are, and then brag about my p4-2. I better get started...
TerranFury
TerranFury
Hmmm.... since this thread has been resurrected, I might as well ask this useless question.

Let''s assume for the moment that I''m a weirdo who refuses to use DirectDraw for access to the framebuffer like most normal people and instead want to go into Mode 13h and get a pointer to video memory.

I can fool Windows into letting me do this? I see at the geocities site I can get the pointer. But how can I call the interrupt?

I''m interested in trying this simply because it is strange! (Why aren''t useful things interesting?)

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.