3 ms·
If your architecture allows it, sure. I was reading some old Apple II assembly last year, and one very common way to do loops is like this: 1. Is 10 equal to
by danielweber 14y ago
If your architecture allows it, sure.
I was reading some old Apple II assembly last year, and one very common way to do loops is like this:
1. Is 10 equal to 0?
2. If so, go to step 6.
3. Do a bunch of stuff.
4. Decrement the first number written in step 1.
5. Go to step 1.
6. Rest of program.
- ajross 14y agoTo be clear, even on architectures that allow it (or OS environments: the NX bit on modern x86 boxes means that you can't write to code space without mmap'ing the region yourself), it's a Very Bad Idea. Code and data use different L1 caches (on Sandy/Ivy Bridge, there's even a still lower level "uop" cache for code!), and keeping them coherent after self-modifying code has run is (1) extraordinarily difficult to get right and (2) hugely slow, much slower than simply indirecting on data in the first place.