Warning: preg_match(): Compilation failed: group name must start with a non-digit at offset 8 in /home/content/30/6867330/html/intellivision/wiki/includes/MagicWord.php on line 722

Warning: preg_match(): Compilation failed: group name must start with a non-digit at offset 8 in /home/content/30/6867330/html/intellivision/wiki/includes/MagicWord.php on line 722

Warning: preg_match_all(): Compilation failed: group name must start with a non-digit at offset 4 in /home/content/30/6867330/html/intellivision/wiki/includes/MagicWord.php on line 700

Warning: Invalid argument supplied for foreach() in /home/content/30/6867330/html/intellivision/wiki/includes/MagicWord.php on line 701

Warning: preg_replace(): Compilation failed: group name must start with a non-digit at offset 4 in /home/content/30/6867330/html/intellivision/wiki/includes/MagicWord.php on line 705

Warning: preg_match_all(): Compilation failed: group name must start with a non-digit at offset 4 in /home/content/30/6867330/html/intellivision/wiki/includes/MagicWord.php on line 700

Warning: Invalid argument supplied for foreach() in /home/content/30/6867330/html/intellivision/wiki/includes/MagicWord.php on line 701

Warning: preg_replace(): Compilation failed: group name must start with a non-digit at offset 4 in /home/content/30/6867330/html/intellivision/wiki/includes/MagicWord.php on line 705

Warning: preg_match_all(): Compilation failed: group name must start with a non-digit at offset 4 in /home/content/30/6867330/html/intellivision/wiki/includes/MagicWord.php on line 700

Warning: Invalid argument supplied for foreach() in /home/content/30/6867330/html/intellivision/wiki/includes/MagicWord.php on line 701

Warning: preg_replace(): Compilation failed: group name must start with a non-digit at offset 4 in /home/content/30/6867330/html/intellivision/wiki/includes/MagicWord.php on line 705

Warning: preg_match_all(): Compilation failed: group name must start with a non-digit at offset 4 in /home/content/30/6867330/html/intellivision/wiki/includes/MagicWord.php on line 700

Warning: Invalid argument supplied for foreach() in /home/content/30/6867330/html/intellivision/wiki/includes/MagicWord.php on line 701

Warning: preg_replace(): Compilation failed: group name must start with a non-digit at offset 4 in /home/content/30/6867330/html/intellivision/wiki/includes/MagicWord.php on line 705

Warning: preg_match(): Compilation failed: group name must start with a non-digit at offset 8 in /home/content/30/6867330/html/intellivision/wiki/includes/MagicWord.php on line 722

Warning: preg_match(): Compilation failed: group name must start with a non-digit at offset 8 in /home/content/30/6867330/html/intellivision/wiki/includes/MagicWord.php on line 722

Warning: preg_match(): Compilation failed: group name must start with a non-digit at offset 8 in /home/content/30/6867330/html/intellivision/wiki/includes/MagicWord.php on line 722

Warning: preg_match(): Compilation failed: group name must start with a non-digit at offset 8 in /home/content/30/6867330/html/intellivision/wiki/includes/MagicWord.php on line 722

Warning: preg_match(): Compilation failed: group name must start with a non-digit at offset 8 in /home/content/30/6867330/html/intellivision/wiki/includes/MagicWord.php on line 722
Introducing the Instruction Set Part 3 - Intellivision Wiki

Introducing the Instruction Set Part 3


Warning: preg_match(): Compilation failed: group name must start with a non-digit at offset 8 in /home/content/30/6867330/html/intellivision/wiki/includes/MagicWord.php on line 722
From Intellivision Wiki

Jump to: navigation, search
m (Using INCR to Skip an Instruction)
(Clever (or Silly) Branch Tricks)
Line 650: Line 650:
The example also shows a minor optimization:  The highest numbered case can always be put right at the end of the list of branches, rather than having a branch to it there.
The example also shows a minor optimization:  The highest numbered case can always be put right at the end of the list of branches, rather than having a branch to it there.
-
= Clever (or Silly) Branch Tricks =
+
== Clever (or Silly) Branch Tricks ==
The program counter, R7, can be accessed by almost any of the CPU's instructions.  This leads to several cute tricks that border on being a bit too clever.  Since these show up in actual code, it's worth at least explaining how they work.
The program counter, R7, can be accessed by almost any of the CPU's instructions.  This leads to several cute tricks that border on being a bit too clever.  Since these show up in actual code, it's worth at least explaining how they work.
-
== Using INCR to Skip an Instruction ==
+
=== Using INCR to Skip an Instruction ===
The instruction <CODE>[[INCR]] PC</CODE> adds 1 to the program counter.  The net effect of this is skip the next word of code.  If the next instruction is a 1 word instruction, this acts like a compact version of an unconditional branch.  Why is this attractive?  It is 1 word smaller and 2 cycles faster than a <CODE>[[B]]</CODE> instruction.
The instruction <CODE>[[INCR]] PC</CODE> adds 1 to the program counter.  The net effect of this is skip the next word of code.  If the next instruction is a 1 word instruction, this acts like a compact version of an unconditional branch.  Why is this attractive?  It is 1 word smaller and 2 cycles faster than a <CODE>[[B]]</CODE> instruction.
Line 672: Line 672:
         ENDP
         ENDP
-
== Using ADCR to Conditionally Skip an Instruction ==
+
=== Using ADCR to Conditionally Skip an Instruction ===
The instruction <CODE>[[ADCR]] PC</CODE> adds 1 to the program counter whenever the [[Carry Flag]] is 1.  This amounts to a limited version of the <CODE>[[BC]]</CODE> instruction.  This can come up in all sorts of situations.
The instruction <CODE>[[ADCR]] PC</CODE> adds 1 to the program counter whenever the [[Carry Flag]] is 1.  This amounts to a limited version of the <CODE>[[BC]]</CODE> instruction.  This can come up in all sorts of situations.
Line 685: Line 685:
Here, the <CODE>[[ADCR]] PC</CODE> instruction skips the <CODE>[[PULR]] PC</CODE> instruction if <CODE>BGMAKE</CODE> successfully found a slot for a new bad guy.
Here, the <CODE>[[ADCR]] PC</CODE> instruction skips the <CODE>[[PULR]] PC</CODE> instruction if <CODE>BGMAKE</CODE> successfully found a slot for a new bad guy.
-
== Using DECR to Spin "Forever" ==
+
=== Using DECR to Spin "Forever" ===
Sometimes, your program will need to simply "sit and spin."  This most often happens when trying to synchronize with an interrupt, say as part of an initialization sequence.  (This will be covered in more detail in a future tutorial.)  The <CODE>[[DECR]] PC</CODE> instruction decrements the program counter after executing the instruction.  This puts the program counter right back at the same instruction, resulting in an infinite loop.  The only thing that will break out of this infinite loop is an interrupt.  
Sometimes, your program will need to simply "sit and spin."  This most often happens when trying to synchronize with an interrupt, say as part of an initialization sequence.  (This will be covered in more detail in a future tutorial.)  The <CODE>[[DECR]] PC</CODE> instruction decrements the program counter after executing the instruction.  This puts the program counter right back at the same instruction, resulting in an infinite loop.  The only thing that will break out of this infinite loop is an interrupt.  

Revision as of 22:21, 6 November 2007

Personal tools
Namespaces
Variants
Actions
Navigation
Toolbox