Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Registers:
- SP (stack pointer): 16-bit
- FP (frame pointer): 16-bit
- PC (program counter): 16-bit
- A (left reg) 16-bit
- B (right reg) 16-bit
- Addressing modes:
- <fast> = FP + item from lookup table
- <near> = FP + 8-bit sign extended offset
- <far> = FP + 16-bit offset
- <abs> = 16-bit address
- Fast stack reference:
- Code | location | assembler name
- -----+----------+----------------
- 0 | frame-24 | local12
- 1 | frame-22 | local11
- 2 | frame-20 | local10
- 3 | frame-18 | local9
- 4 | frame-16 | local8
- 5 | frame-14 | local7
- 6 | frame-12 | local6
- 7 | frame-10 | local5
- 8 | frame-8 | local4
- 9 | frame-6 | local3
- A | frame-4 | local2
- B | frame-2 | local1
- | frame-0 | old block pointer
- | frame+2 | old program counter
- C | frame+4 | arg1
- D | frame+6 | arg2
- E | frame+8 | arg3
- F | frame+10 | arg4
- Instruction set:
- 0x : lda fast : A = <fast>
- 1x : ldb fast : B = <fast>
- 2x : push fast : push <fast> to the stack
- 3x : sta fast : <fast> = A
- 4x : lda #x : A = #x
- 5x : ldb #x : B = #x
- 6x : push #x : push #x to the stack
- 7x : add #x : A += #x
- 80 xx : lda near : A = <near>
- 81 xx xx : lda far : A = <far>
- 82 xx : ldb near : B = <near>
- 83 xx xx : ldb far : B = <far>
- 84 xx : push near : push <near> to the stack
- 85 xx xx : push far : push <far> to the stack
- 86 xx : sta near : <near> = A
- 87 xx xx : sta far : <far> = A
- 88 xx : lda #xx : A = #xx
- 89 xx xx : lda #xxxx : A = #xxxx
- 8A xx : ldb #xx : B = #xx
- 8B xx xx : ldb #xxxx : B = #xxxx
- 8C xx : push #xx : push #xx to the stack
- 8D xx xx : push #xxxx : push #xxxx to the stack
- 8E xx : add #xx : A += #xx
- 8F xx xx : add #xxxx : A += #xxxx
- 00-3f and 40-7f share logic except for sta/add
- 00-7f and 80-8f share logic
- 90 xx xx : lda xxxx : A = <abs>
- 91 xx xx : ldb xxxx : B = <abs>
- 92 xx xx : push xxxx : push <abs> to the stack
- 93 xx xx : sta xxxx : <abs> = A
- 94 xx xx : blda xxxx : A = <byte abs>
- 95 xx xx : bldb xxxx : B = <byte abs>
- 96 xx xx : bpush xxxx : push <byte abs> to the stack
- 97 xx xx : bsta xxxx : <byte abs> = A
- 98 xx xx : blda far : A = <byte far>
- 99 xx xx : bldb far : B = <byte far>
- 9A xx xx : bpush far : push <byte far> to the stack
- 9B xx xx : bsta far : <byte far> = A
- 9C xx xx : leaa far : A = &<far>
- 9D xx xx : leab far : B = &<far>
- 9E xx xx : pea far : push &<far> to the stack
- 9F xx xx : ?? far : reserved
- A0 : deref : A = *A
- A1 : popstore : pop B, *b = A
- A2 : bderef : A = (byte)*A
- A3 : bpopstore : pop B, (byte)*B = A
- A4 : pha : push A to the stack
- A5 : plb : pop B from the stack
- A6 xx : unstack #xx : sp += #xx (for cleaning up after a function)
- A7 xx xx : unstack #xxxx : sp += #xxxx
- A8 xx xx : call xxxx : call an address (push PC, PC = xxxx, push FP, FP = SP)
- A9 : callptr : call A
- AA xxxxyy: call xxxx, #yy : call an address, decrease the stack pointer by yy
- AB yy : callptr #yy : call A, decrease the stack pointer by yy
- AC xx xx : copy #xxxx : memcpy(b, a, #xxxx)
- AD xx xx : clear #xxxx : memset(b, a, #xxxx) ? maybe it'd be better as memcpy without changing b
- AE : return : return (SP = FP, pop FP, pop PC)
- AF : nop : do nothing
- AF : swap : A = B and B = A
- B0 : ucmplt : A = A < B (unsigned)
- B1 : ucmple : A = A <= B (unsigned)
- B2 : ucmpgt : A = A > B (unsigned)
- B3 : ucmpge : A = A >= B (unsigned)
- B4 : scmplt : A = A < B (signed)
- B5 : scmple : A = A <= B (signed)
- B6 : scmpgt : A = A > B (signed)
- B7 : scmpge : A = A >= B (signed)
- B8 : cmpeq : A = A == B
- B9 : cmpne : A = A != B
- BA : not : A = !A
- BB : neg : A = -A
- BC : compl : A = ~A
- BD : and : A = A & B
- BE : or : A = A | B
- BF : xor : A = A ^ B
- B0-B7 share logic
- entire block sets A
- C0 : inc : A++
- C1 : dec : A--
- C2 : add : A += B
- C3 : sub : A -= B
- C4 : lshift : A <<= B (unsigned)
- C5 : double : A <<= 1
- C6 : rshift : A >>= B (unsigned)
- C7 : rshift : A >>= B (signed)
- C8 : mulu : A *= B (unsigned)
- C9 : muls : A *= B (signed)
- CA : divu : A /= B (unsigned)
- CB : divs : A /= B (signed)
- CC : modu : A %= B (unsigned)
- CD : mods : A %= B (signed)
- CE : :
- CF : :
- C0,C1 share logic with C2,C3
- signed and unsigned opcodes share logic
- entire block sets A
- D0 xx : jumpt xx : PC += xx + 1 IF A==1
- D1 xx : jumpt xx : PC -= xx - 1 IF A==1
- D2 xx xx : jumpt xxxx : PC = <abs> IF A==1
- D3 : :
- D4 xx : jumpf xx : PC += xx + 1 IF A==0
- D5 xx : jumpf xx : PC -= xx - 1 IF A==0
- D6 xx xx : jumpf xxxx : PC = <abs> IF A==0
- D7 : :
- D8 xx : jump xx : PC += xx + 1
- D9 xx : jump xx : PC -= xx - 1
- DA xx xx : jump xxxx : PC = <abs>
- DB : :
- DC ?? : switchrange : switch statement with a range
- DD ?? : switchlist : switch statement with a list of values
- DE : :
- DF : :
- -switch statements-
- switchrange
- .word 1, 5 ; range is 1 to 5
- .word default ; for if outside 1 to 5
- .word was1
- .word was2
- .word was3
- .word was4
- .word was5
- switchlist
- .word 5 ; 5 cases
- .word 1, was1
- .word 2, was2
- .word 3, was3
- .word 4, was4
- .word 5, was5
- .word default
- -array reading-
- lda index
- add #array_address
- deref
- -array writing-
- lda index
- add #array_address
- pha
- lda (whatever value to write)
- popstore
- -loop-
- lda #0
- sta index
- loop:
- ; get place to write
- lda #array
- ldb index
- add
- pha
- ; get index*index
- lda index
- ldb index
- mulu
- popstore
- lda index
- ldb #10
- cmpne
- jumpt loop
- -calling functions-
- push #1
- push #2
- push #3
- push #4
- call sum
- unstack #4*2
- sum:
- lda local1
- ldb local2
- add
- ldb local3
- add
- ldb local4
- add
- return
- -passing -
- pea variable
- call function
- unstack #1*2
- function: ; writes 1 to the passed argument
- push arg1
- lda #1
- popstore
- return
Add Comment
Please, Sign In to add comment