So I'm emulating an extra instruction in C for the MSP440 called IFcc, where cc is the condition. How it works is if the condition is true, then the 'true instructions' are executed, and the 'false instructions' are skipped, and vice versa if the condition is false. The instruction takes two arguments, TC which is the number of instructions to execute if condition is true, and FC which is the number on instructions to execute if the condition is false. Here is an example of what the assembly code might look like:
CMP &ALPHA,&BETA
IFEQ 2,2 ; Execute the first and second instructions if ALPHA = BETA
; or the third and fourth instructions if ALPHA BETA
MOV #0,&ALPHA ; Executed if ALPHA = BETA
MOV #1,&BETA ; Executed if ALPHA = BETA
MOV &BETA,&ALPHA ; Executed if ALPHA ≠ BETA
ADD #1,&ALPHA ; Executed if ALPHA ≠ BETA
What I'm having trouble figuring out, is how to ignore the instructions that should not be executed. The assembly itself wouldn't be changed to use branches, because the point of the IFcc instruction is to eliminate the necessity for branches. Any help with this would be greatly appreciated.
I dont recognize that instruction, is this an instruction you are inventing within your emulator?
Assuming that is the case
The msp430 instruction set is variable word length so if you want the logic to simply say do or dont execute the next two instructions, you have to specify instructions, but you wont know until the first words of each are decoded to know how many words that is, but that doesnt matter you put a counter in and count down the number of instructions, and simply dont do the execute or write back stages of the pipe.
at the end of the day all you are doing here is a branch on condition or branch on not condition, how is this instruction different? not flushing the pipe vs flushing the pipe? who is to say that a branch flushes the pipe in current/modern designs, if the branch is near enough and the pipe is deep enough there may be an optimization in the design to not flush and refill but to instead just keep going and skip (for the very common cases where the branch is forward by some small number of words).
the simplest is to just branch, set the pc to the word after the instructions skipped, you should have already implemented this in a branch, but the ASSEMBLER should be the one responsible for computing how many words there are in the next N instructions. It may be that a skip two instructions in one case is skip over two words (add 4 to the pc) or it could elsewhere mean that skip over two instructions means skip 5 words. Just like the implementation of a branch where you specify a label and the assembler takes care of making multiple passes and finally computing the offset to where the label would be in the instruction flow. which basically means make this a branch with a label.
if you dont want to make this a branch with a label then you have to pretend to execute the next N instructions to the point that you decode them enough to know how many words wide they are and skip that many words, repeat for the number of instructions to skip. runtime there is no other way to do it.