assembler (m1_as) - retrotruestory/M1DEV GitHub Wiki
Here are all available Magic-1 commands and instructions:
Load/Store Instructions
ld.8/16 - Load 8/16-bit value
st.8/16 - Store 8/16-bit value
ldclr - Load and clear (for semaphores)
push - Push to stack
pop - Pop from stack
memcopy - Block copy
tosys - Copy from user to system space
fromsys - Copy from system to user space
ldcode - Load from code space
stcode - Store to code space
Address/Register Operations
lea - Load effective address
copy - Copy between registers
sex - Sign extend
PTB - Page Table Base operations
MSW - Machine Status Word operations
Arithmetic Operations
add.8/16 - Add 8/16-bit
sub.8/16 - Subtract 8/16-bit
and.8/16 - Logical AND 8/16-bit
or.8/16 - Logical OR 8/16-bit
xor.16 - Logical XOR 16-bit
shl.16 - Shift left
shr.16 - Shift right
vshl.16 - Variable shift left
vshr.16 - Variable shift right
adc.16 - Add with carry
sbc.16 - Subtract with carry
Control Flow
br - Branch unconditional
br.eq - Branch if equal
br.ne - Branch if not equal
br.lt - Branch if less than
br.le - Branch if less/equal
br.gt - Branch if greater than
br.ge - Branch if greater/equal
br.ltu - Branch if less than (unsigned)
br.leu - Branch if less/equal (unsigned)
call - Call subroutine
ret - Return from subroutine
reti - Return from interrupt
System Operations
halt - Halt processor
syscall - System call
bkpt - Breakpoint
trapo - Trap on overflow
wcpte - Write code page table entry
wdpte - Write data page table entry
enter - Function prologue
leave - Function epilogue
Comparison Instructions
cmp.8/16 - Compare 8/16-bit
cmpb.eq - Compare and branch if equal
cmpb.ne - Compare and branch if not equal
cmpb.lt - Compare and branch if less than
cmpb.le - Compare and branch if less/equal
Bit Operations
bset - Set bit
bclr - Clear bit
test - Test bit
This instruction set provides a complete environment for systems programming, with support for:
- Memory management
- Stack operations
- Arithmetic/logic operations
- Control flow
- System calls/privileged operations
- Bit manipulation
Here's a detailed overview of how M1 assembly code works:
Basic M1 Assembly Syntax
// Basic instruction format
label: instruction operands ; comment
// Example with data definition
.cseg ; Code segment
.global _main ; Global label declaration
_main:
enter 4 ; Function prologue
ld.16 a,#1234 ; Load immediate value
Key Assembler Directives
.cseg # Start code segment
.dseg # Start data segment
.global # Declare global symbol
.defb # Define byte
.defw # Define word
.equ # Define constant
Common Address Modes
ld.8 a,#42 # Immediate value
ld.16 a,(dp) # Direct addressing
ld.8 a,(b) # Register indirect
ld.16 a,4(sp) # Base + displacement
Example Function
.global _example
_example:
enter 8 ; Setup stack frame
push a ; Save register
ld.16 a,6(sp) ; Load parameter
add.16 a,#1 ; Add 1
pop a ; Restore register
leave ; Restore stack frame
ret ; Return
The assembler supports:
- Labels and symbols
- Multiple segments (code, data)
- Local and global scope
- Expressions in operands
- Relocatable code generation
- Symbol table generation