Advertisement
Guest User

Untitled

a guest
Aug 13th, 2017
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.84 KB | None | 0 0
  1. address: .EQUATE 6
  2. v: .EQUATE 2
  3. current: .EQUATE 0
  4.  
  5. free: nop0
  6. subsp 4, i
  7.  
  8. lda address, s
  9.  
  10. ;;;; Get the size from the memory to be deallocated
  11. ldx address, s
  12. subx 2, i
  13. stx address, s
  14. ldx address, sf
  15.  
  16. ;;;; Fill the deallocated memory with '??'s
  17. qfill: nop0
  18. sta v, s
  19. lda 0x3F3F, i
  20. sta v, sf
  21. lda v, s
  22. adda 2, i
  23. subx 2, i
  24. brgt qfill
  25.  
  26. ;;;; Traverse the linked list
  27. lda Hhead, d
  28. sta current, s
  29. linkloop: nop0
  30. cpa 0, i
  31. breq mERROR2
  32. sta HEA, d
  33. lda HEA, n ;;;; ...until we find a node with an flink
  34. cpa address, s ;;;; who's higher in memory than our deallocated space is.
  35. brge lldone ;;;; This is the node we're going to link to.
  36. sta current, s
  37. br linkloop
  38. lldone: nop0
  39.  
  40. ;;;; load our deallocated size into X now, because we're going to overwrite it
  41. ldx address, sf
  42. sta address, sf ;;;; put the address to the next link into the flink of our new link
  43.  
  44. ;;;; add 2 to address to point to the size field
  45. lda address, s
  46. adda 2, i
  47. sta address, s
  48.  
  49. ;;;; we have the deallocated amount - 2 space left
  50. ;;;; (since 4 bytes are used by the structure)
  51. subx 2, i
  52. stx address, sf ;;;; and we put that into where the size goes
  53.  
  54. ;;;; lastly, let's put the address of where our new link is into
  55. suba 4, i
  56. sta HEA, n ;;;; into the flink of the previous node
  57.  
  58. mERROR2: ret4 ;;;; On error, just return.
  59. .END
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement