Skip to content

Instantly share code, notes, and snippets.

@Jarvix
Created April 8, 2012 14:06
Show Gist options
  • Save Jarvix/2337487 to your computer and use it in GitHub Desktop.
Save Jarvix/2337487 to your computer and use it in GitHub Desktop.
;There was an interrupt by the timer!
;;;VM
PUSH PC ; is current PC
PUSH 0 ; timer has no second argument
PUSH 1 ; timer interrupt is 1
; vm does the lookup job
; jumps to the handler
;;;HANDLER
:interruptHandler
; interrupt is in [SP]
; arg is in [SP+1]
; PC is in [SP+2]
; Turn off interrupts
XOR CR, 1
; Save all registers
PUSH A
PUSH B
PUSH C
PUSH X
PUSH Y
PUSH I
PUSH J
; Get new stack address somehow
; Set new stack address
SET SP, newStack
; We now are on the new stack of another task,
; that also pushed their registers
POP J
POP I
POP Y
POP X
POP C
POP B
POP A
; We restores the program
; Remove the interrupt info without clobbering
SUB SP,2
; Turn on interrupts
XOR CR, 1
; notch-code this is SET PC,POP
POP PC
; We now run not in the VM but the actual code again
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment