Advertisement
Guest User

Untitled

a guest
Apr 7th, 2012
1,124
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.47 KB | None | 0 0
  1. ;Notch's examples
  2. ;Should compile fine, by default
  3.  
  4. ;Try some basic stuff
  5. SET A, 0x30 ; 7c01 0030
  6. SET [0x1000], 0x20 ; 7de1 1000 0020
  7. SUB A, [0x1000] ; 7803 1000
  8. IFN A, 0x10 ; c00d
  9. SET PC, crash ; 7dc1 001a [*]
  10.  
  11. ;Do a loopy thing
  12. SET I, 10 ; a861
  13. SET A, 0x2000 ; 7c01 2000
  14. :loop SET [0x2000+I], [A] ; 2161 2000
  15. SUB I, 1 ; 8463
  16. IFN I, 0 ; 806d
  17. SET PC, loop ; 7dc1 000d [*]
  18.  
  19. ;Call a subroutine
  20. SET X, 0x4 ; 9031
  21. JSR testsub ; 7c10 0018 [*]
  22. SET PC, crash ; 7dc1 001a [*]
  23.  
  24. :testsub
  25. SHL X, 4 ; 9037
  26. SET PC, POP ; 61c1
  27.  
  28.  
  29. ;Hang forever. X should now be 0x40 if everything went right.
  30. :crash SET PC, crash ; 7dc1 001a [*]
  31.  
  32. ; Assembler test for DCPU
  33. ; by Markus Persson
  34.  
  35. set a, 0xbeef ; Assign 0xbeef to register a
  36. set [0x1000], a ; Assign memory at 0x1000 to value of register a
  37. ifn a, [0x1000] ; Compare value of register a to memory at 0x1000 ..
  38. set PC, end ; .. and jump to end if they don't match
  39.  
  40. set i, 0; Init loop counter, for clarity
  41. :nextchar
  42. ife [data+i] , 0; If the character is 0 ..
  43. set PC, end ; .. jump to the end
  44. set [0x8000+i], [data+i] ; Video ram starts at 0x8000, copy char there
  45. add i, 1 ; Increase loop counter
  46. set PC, nextchar ; Loop
  47.  
  48. :data dat "Hello world!", 0; Zero terminated string
  49.  
  50. :end sub PC, 1; Freeze the CPU forever
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement