home *** CD-ROM | disk | FTP | other *** search
/ ARM Club 3 / TheARMClub_PDCD3.iso / hensa / programming / extasm_1 / !extAOF / Examples / C / ScrapFile < prev   
Text File  |  1995-07-08  |  6KB  |  271 lines

  1.  
  2. #type &FFD
  3. ; -------------------------------------------
  4. ; The following is the ARM Object Format file
  5. ; -------------------------------------------
  6. ;
  7. .AOF_objfilestart
  8. ;
  9. ; File header
  10. ; -----------
  11. ;
  12. DCD   &C3CBC6C5 ; chunkfileid
  13. DCD   5         ; maxchunks
  14. DCD   5         ; numchunks
  15. ;
  16. ; Chunks
  17. ; ------
  18. ;
  19. ; Header chunk
  20. ;
  21. DCB   "OBJ_HEAD"
  22. DCD   AOF_headerstart-AOF_objfilestart   ; header offset
  23. DCD   AOF_headerend-AOF_headerstart      ; header size
  24. ; Area chunk
  25. ;
  26. DCB   "OBJ_AREA"
  27. DCD   AOF_areastart-AOF_objfilestart     ; area offset
  28. DCD   AOF_areaend-AOF_areastart          ; area size
  29. ; Identification chunk
  30. ;
  31. DCB   "OBJ_IDFN"
  32. DCD   AOF_idstart-AOF_objfilestart       ; id offset
  33. DCD   AOF_idend-AOF_idstart              ; id size
  34. ; Symbol table
  35. ;
  36. DCB   "OBJ_SYMT"
  37. DCD   AOF_symboltablestart-AOF_objfilestart   ; symbol table offset
  38. DCD   AOF_symboltableend-AOF_symboltablestart ; symbol table size
  39. ; String table
  40. ;
  41. DCB   "OBJ_STRT"
  42. DCD   AOF_strtablestart-AOF_objfilestart ; string table offset
  43. DCD   AOF_strtableend-AOF_strtablestart  ; string table size
  44. ;
  45. ; Chunk data
  46. ; ----------
  47. ;
  48. ; ----------
  49. ; Area chunk
  50. ; ----------
  51. ;
  52. .AOF_areastart
  53. ; extAOF example
  54. ;
  55. ; © Terje Slettebø
  56. ;
  57. ;
  58. ; These example files ('AOFTestA' and 'AOFTestC') demonstrates how you can
  59. ; reference functions or global variables in AOF files. It shows:
  60. ;
  61. ; - Referencing an external function                   (#import printf)
  62. ; - Referencing an external global variable            (#import globalcvar)
  63. ; - Defining a function which can be referenced        (#export testproc)
  64. ; - Defining a global variable which can be referenced (#export globalvar)
  65. ;
  66. ; It also sets up a zero-initialised area.
  67. ;
  68. ;
  69. ; To assemble this source file to an AOF file, you can either:
  70. ;
  71. ; - Drag this source file to the extAOF icon, and then drag the new file to
  72. ;   the extASM assembler. Then it will be assembled to AOF format.
  73. ;
  74. ; - Use the 'extASM' mode file for StrongED, in this application directory,
  75. ;   and press shift-F10. The source will then be saved, and it will be sent
  76. ;   to extAOF.
  77. ;
  78. ; If you choose the 'Autostart' in the option in the extAOF menu, then
  79. ; extAOF will automatically send the new file to extASM.
  80. ;
  81. ;
  82. ; When this source is assembled, using the methods described above, you must
  83. ; then put the filename for the object file (<filepath>.Procedure) in the
  84. ; "Library" menu entry for the C compiler (for the ANSI C compiler).
  85. ;
  86. ; Then you can compile the C source 'AOFTestC'. And then you can run the
  87. ; executable object file.
  88. ;
  89. #name Procedure
  90.  
  91. .AOF_testareastart
  92.  
  93.  
  94. .testproc
  95. STMFD R13!,{R14}
  96. ADR   R0,str
  97. SWI   OS_Write0
  98. LDR   R0,globalcvaradr      ; read 'globalcvar' address
  99. LDR   R0,[R0]               ; read 'globalcvar'
  100. ADR   R1,numbuffer
  101. MOV   R2,#16
  102. SWI   OS_ConvertInteger4
  103. SWI   OS_Write0             ; print number
  104. SWI   OS_NewLine
  105. ADR   R0,str2
  106. .AOF_printf_I_0
  107. BL    AOF_printf_I_0+8
  108. LDMFD R13!,{R15}^
  109. .str
  110. DCB   "In assembly program, globalcvar (in C)=",0
  111. ALIGN
  112. .str2
  113. DCB   "Returning, using printf (in C)",10,13,0 ; '\n' can not be used,
  114. ALIGN                                          ; it is substituted by the
  115. .numbuffer                                     ; compiler
  116. DBB   16
  117. .globalcvaradr
  118. .AOF_globalcvar_I_0
  119. DCD   0
  120. .globalvar
  121. DCD   234
  122. ;
  123. ; The following sets up a 1024 bytes zero-initialised area. This is only
  124. ; made when the AOF file is linked, or it is set up at run-time by the
  125. ; executable file (this is up to the linker). It seems the linker with
  126. ; ANSI C does the latter. In this way, the AOF file can be smaller, as it
  127. ; doesn't have to include the zero-initialised data.
  128. ;
  129. .AOF_testareaend
  130. ; Relocation directive table
  131. ;
  132. DCD   AOF_printf_I_0-AOF_testareastart
  133. DCD   (AOF_printf_Isymbol-AOF_symboltablestart)/16+&60000
  134. DCD   AOF_globalcvar_I_0-AOF_testareastart
  135. DCD   (AOF_globalcvar_Isymbol-AOF_symboltablestart)/16+&a0000
  136. .AOF_zeroinitstart
  137.  
  138.  
  139. .datastart
  140. #set AOF_zeroinitend=AOF_zeroinitstart+1024
  141.  
  142. .AOF_areaend
  143. ;
  144. ; ------------
  145. ; Header chunk
  146. ; ------------
  147. ;
  148. .AOF_headerstart
  149. DCD   &C5E2D080  ; relocatable object file
  150. DCD   150        ; version ID
  151. DCD   2          ; number of areas
  152. DCD   5          ; number of symbols
  153. DCD   0          ; entry adr area
  154. DCD   0          ; entry adr offset
  155. ;
  156. ; area name
  157. DCD   AOF_testareastr-AOF_strtablestart
  158. ; area flags
  159. DCD   &202
  160. ; area size
  161. DCD   AOF_testareaend-AOF_testareastart
  162. ; number of relocations
  163. DCD   2
  164. ; unused
  165. DCD   0
  166. ;
  167. ; area name
  168. DCD   AOF_zeroinitstr-AOF_strtablestart
  169. ; area flags
  170. DCD   &1002
  171. ; area size
  172. DCD   AOF_zeroinitend-AOF_zeroinitstart
  173. ; number of relocations
  174. DCD   0
  175. ; unused
  176. DCD   0
  177. ;
  178. .AOF_headerend
  179. ; --------------------
  180. ; Identification chunk
  181. ; --------------------
  182. ;
  183. .AOF_idstart
  184. DCB   "Made by extAOF and extASM",0
  185. ALIGN
  186. .AOF_idend
  187. ;
  188. ; ------------------
  189. ; Symbol table chunk
  190. ; ------------------
  191. ;
  192. .AOF_symboltablestart
  193. ;
  194. .AOF_globalcvar_Isymbol
  195. ; symbol name
  196. DCD   AOF_globalcvar_Istr-AOF_strtablestart
  197. ; symbol flags
  198. DCD   2        
  199. ; symbol value
  200. DCD   0
  201. ; symbol area
  202. DCD   0
  203. ;
  204. .AOF_printf_Isymbol
  205. ; symbol name
  206. DCD   AOF_printf_Istr-AOF_strtablestart
  207. ; symbol flags
  208. DCD   2        
  209. ; symbol value
  210. DCD   0
  211. ; symbol area
  212. DCD   0
  213. ;
  214. .AOF_globalvarsymbol
  215. ; symbol name
  216. DCD   AOF_globalvarstr-AOF_strtablestart
  217. ; symbol flags
  218. DCD   3        
  219. ; symbol value
  220. DCD   globalvar-AOF_testareastart
  221. ; symbol area
  222. DCD   AOF_testareastr-AOF_strtablestart
  223. ;
  224. .AOF_testprocsymbol
  225. ; symbol name
  226. DCD   AOF_testprocstr-AOF_strtablestart
  227. ; symbol flags
  228. DCD   3        
  229. ; symbol value
  230. DCD   testproc-AOF_testareastart
  231. ; symbol area
  232. DCD   AOF_testareastr-AOF_strtablestart
  233. ;
  234. .AOF_datastartsymbol
  235. ; symbol name
  236. DCD   AOF_datastartstr-AOF_strtablestart
  237. ; symbol flags
  238. DCD   3        
  239. ; symbol value
  240. DCD   datastart-AOF_zeroinitstart
  241. ; symbol area
  242. DCD   AOF_zeroinitstr-AOF_strtablestart
  243. ;
  244. .AOF_symboltableend
  245. ; ------------------
  246. ; String table chunk
  247. ; ------------------
  248. ;
  249. .AOF_strtablestart
  250. DCD   AOF_strtableend-AOF_strtablestart
  251. ; symbol strings
  252. ;
  253. .AOF_globalcvar_Istr
  254. DCB   "globalcvar",0
  255. .AOF_printf_Istr
  256. DCB   "printf",0
  257. .AOF_globalvarstr
  258. DCB   "globalvar",0
  259. .AOF_testprocstr
  260. DCB   "testproc",0
  261. .AOF_datastartstr
  262. DCB   "datastart",0
  263. ;
  264. ; area strings
  265. .AOF_testareastr
  266. DCB   "AOF_testarea",0
  267. .AOF_zeroinitstr
  268. DCB   "AOF_zeroinit",0
  269. ALIGN
  270. .AOF_strtableend
  271.