sbrk.e 664 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. #
  2. #include <em_abs.h>
  3. mes 2,EM_WSIZE,EM_PSIZE
  4. .1
  5. bss EM_PSIZE,0,0
  6. .2
  7. bss EM_WSIZE,0,0
  8. pro $ctch,0
  9. lol 0
  10. loc EHEAP
  11. beq *1
  12. lae .1
  13. loi EM_PSIZE
  14. sig
  15. asp EM_PSIZE
  16. lol 0
  17. trp
  18. rtt
  19. 1
  20. loc 1
  21. ste .2
  22. rtt
  23. end
  24. exp $sbrk
  25. pro $sbrk,0
  26. lor 2
  27. lor 2
  28. lpi $ctch
  29. sig
  30. lae .1
  31. sti EM_PSIZE
  32. loc 0
  33. ste .2
  34. lol 0
  35. ads EM_WSIZE ; this is the new heap pointer, but watch out for overflow!
  36. dup EM_PSIZE
  37. lor 2
  38. cmp ; compare with old heap pointer
  39. zlt *1
  40. str 2 ; The - possibly - occurring trap is caught
  41. lae .1
  42. loi EM_PSIZE
  43. sig
  44. asp EM_PSIZE
  45. loe .2
  46. zgt *1
  47. ret EM_PSIZE
  48. 1
  49. asp EM_PSIZE
  50. loc -1
  51. loc EM_WSIZE
  52. loc EM_PSIZE
  53. cii
  54. ret EM_PSIZE
  55. end