Magic‐1 instruction set - retrotruestory/M1DEV GitHub Wiki
Instruction Set
Magic feature a one-bye opcode followed by up to 3 bytes of immediate operands. There are 256 possible instructions, and the full list may be found in the microcode listings starting here.
Load/Store
- ld.8/16 [a|b],[imm8|0|i16|exti8|([a|b|sp+u8])|(sp|dp+u16)
- st.8/16 ([a|b|sp+u8])|(sp|dp+u16),[a|b]
- ldclr a,(b) // Load & clear for semaphore implementation
- push [a|msw|b|c|dp|pc|sp)
- pop [a|msw|b|c|dp|pc|sp)
- memcopy // Block copy, count in C
- tosys // Block copy from user to system space, count in C
- fromsys // Block copy from system to user space, count in C
- ldcode.8/16 a,(b) // Load from code space
- stcode.8/16 (b),a // Store to code space
Address Manipulation
- lea [a|b],([a|b|sp|dp|pc]+u16)
Special Register Access
- ld a,msw
- ld msw,a
- ld ptb,a
- ld ssp,a
- ld dp,a
- ld sp,a
- ld c,a
Arithmetic Ops
- sub.8/16 a,[imm8|1|i16|exti8|b|([a|b|sp]+u8])|(dp+u16)
- add.8/16 a,[imm8|1|i16|exti8|b|([a|b|sp]+u8])|(dp+u16)
- and.8/16 a,[imm8|255|i16|extib|8|([a|b|sp]+u8])|(dp+u16)
- or.8/16 a,[imm8|1|i16|exti8|b|([a|b|sp]+u8])|(dp+u16)
- cmp.8/16 a,[imm8|0|i16|exti8|b|([a|b|sp]+u8])|(dp+u16)
- sbc.16 a,b
- adc.16 a,b
- xor.16 a,b
- vshl.16 a // shift count in C
- vshr.16 a // shift count in C
- shl.16 a
- shr.16 a
- sex [a|b] // Sign extend
Control Flow
- cmpb.[ne|eq|lt|le].8/16 a,[imm8|i16|exti8|b|([a|b|sp]+u8])|(dp+u16),d8
- br.[eq|ne|lt|le|gt|ge|ltu|leu|gtu|geu] d16
- b[set|clr] a,mask8/16,d8
- sbr d8 // Short displacement branch
- br [d16|a]
- call [d16|a]
- enter i8/i16
- leave // Pseudo-op for "pop sp"
- ret // Pseudo-op for "pop pc"
- reti // Return from interrupt
System Ops
- halt
- trapo // Trap on overflow
- syscall u8 // System call trap
- bpt // Breakpoint trap
- wcpte a,(b) // Write code page table entry for address in B
- wdpte a,(b) // Write data page table entry for address in B