Extend your language: Difference between revisions

Content added Content deleted
Line 67: Line 67:
.endm</lang>
.endm</lang>


=={{header|68000 Assembly}}==
The 68000 actually has hardware support for extending the language, using the vector table. The "Line A Emulator" vector will trap any instruction that begins with the bit pattern "1010", as no 68000 instruction begins with those bits. This allows you to effectively create your own instructions using a handler that can look at the instruction that caused the trap and decode the rest of it by looking at the other bits. This process is slow, and won't be used for this task, but is worth a mention as it allows for forward compatibility with later versions of the M680x0 CPU family.

I'm using VASM as my assembler, which does support macros, however, the use of macros is somewhat limited, as it's not easy to generalize to all data lengths, conditions, etc. A macro parameter can only take the place of an instruction argument, not an instruction itself. So I'd have to use separate macros for all the possible branch types. Thankfully, addressing modes can be generalized, so I don't have to write separate macros for each.

<lang 68000devpac>macro if2_EQ_DOT_L 1,2,3,4
;input: 1 = first param (can be any addressing mode compatible with CMP)
; 2 = second param (used for condition 1)
; 3 = third param (used for condition 2)
; 4 = output for comparison results (must be a data register, and can't be 1, 2, or 3. The macro will not enforce this!)

; <backslash>@ represents a macro-local label that is scoped for each instance of that macro in your program
; and doesn't cause "label already defined" conflicts if the macro is used multiple times

MOVEQ #0,\4
CMP.L \2,\1
BEQ \@eqCond1
;condition 1 failed.
CMP.L \3,\1
BEQ \@TwoButNotOne
;both failed
clr.b d0
bra \@done
\@eqCond1:
CMP.L \3,\1
BEQ \@Both
move.b #2,d0
bra \@done
\@Both:
move.b #3,d0
bra \@done
\@TwoButNotOne:
move.b #1,d0
\@done:
endm</lang>
=={{header|Ada}}==
=={{header|Ada}}==