Advertisement
KipIngram

Nasm macros for Forth dictionary creation

Nov 28th, 2022
41
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.24 KB | None | 0 0
  1. ;;; Header / dictionary construction macros (not portable)
  2. ;;
  3. ;; Header layout:
  4. ;; [ pfa ] 0x04 Optional PFA pointers (primitives don't have this)
  5. ;; cfa 0x04 CFA - code pointer
  6. ;; link 0x02 16-bit offset back to previous word
  7. ;; count 0x01 8-bit word length count
  8. ;; name 0x?? name string (count bytes)
  9. ;; pad 0x?? inserted as required for 32-bit alignment
  10. ;;
  11. ;; Note that words with count = 1, 5, 9, ... are
  12. ;; perfect fits (no padding)
  13.  
  14. %macro symbol 2 ; create link, name, pad
  15. %2_n: dw %2_n-NFA
  16. %define NFA %2_n
  17. %strlen count %1
  18. db count
  19. db %1
  20. align 0x04, db 0x00
  21. %endmacro
  22.  
  23. %macro symbol 3 ; create link, name, pad w/ tags
  24. ; %if %3-COVERT ; o 0x8000 : inline argument cell
  25. %2_n: dw %2_n-NFA+%3 ; o 0x0002 : covert word
  26. %define NFA %2_n ; o 0x0001 : immediate word
  27. %strlen count %1
  28. db count
  29. db %1
  30. align 0x04, db 0x00
  31. ; %endif
  32. %endmacro
  33.  
  34. %macro code 2 ; machine code primitives
  35. section .data
  36. %2: dd %2_p-o
  37. symbol %1, %2
  38. section .text
  39. %2_p:
  40. %endmacro
  41.  
  42. %macro code 3 ; machine code primitives
  43. section .data
  44. %2: dd %2_p-o
  45. symbol %1, %2, %3
  46. section .text
  47. %2_p:
  48. %endmacro
  49.  
  50. %macro def 2 ; Standard Forth definitions
  51. section .data
  52. dd %2_p-o
  53. %2: dd docol_c-o
  54. symbol %1, %2
  55. section .text
  56. align 0x04
  57. %2_p:
  58. %endmacro
  59.  
  60. %macro def 3 ; Tagged Forth definitions
  61. section .data
  62. dd %2_p-o
  63. %2: dd docol_c-o
  64. symbol %1, %2, %3
  65. section .text
  66. align 0x04
  67. %2_p:
  68. %endmacro
  69.  
  70. %macro var 2 ; System global Variables
  71. section .data
  72. dd %2_p-o
  73. %2: dd dovar_c-o
  74. symbol %1, %2
  75. section .text
  76. align 0x04
  77. %2_p:
  78. %endmacro
  79.  
  80. %macro var 3 ; System global Variables
  81. section .data
  82. dd %2_p-o
  83. %2: dd dovar_c-o
  84. symbol %1, %2, %3
  85. section .text
  86. align 0x04
  87. %2_p:
  88. %endmacro
  89.  
  90. %macro const 2
  91. section .data
  92. dd %2_p-o
  93. %2: dd docon_c-o
  94. symbol %1, %2
  95. section .text
  96. align 0x04
  97. %2_p:
  98. %endmacro
  99.  
  100. %macro run 1-*
  101. %rep %0
  102. dd %1-do
  103. %rotate 1
  104. %endrep
  105. %endmacro
  106.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement