agz80asm.pas 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193
  1. {
  2. Copyright (c) 2003 by Florian Klaempfl
  3. This unit implements an asm for the Z80
  4. This program is free software; you can redistribute it and/or modify
  5. it under the terms of the GNU General Public License as published by
  6. the Free Software Foundation; either version 2 of the License, or
  7. (at your option) any later version.
  8. This program is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. GNU General Public License for more details.
  12. You should have received a copy of the GNU General Public License
  13. along with this program; if not, write to the Free Software
  14. Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  15. ****************************************************************************
  16. }
  17. { This unit implements the assembler writer for the z80asm assembler:
  18. http://savannah.nongnu.org/projects/z80asm
  19. }
  20. unit agz80asm;
  21. {$i fpcdefs.inc}
  22. interface
  23. uses
  24. globtype,systems,
  25. aasmtai,aasmdata,
  26. assemble,
  27. cpubase;
  28. type
  29. TZ80AsmAssembler=class(TExternalAssembler)
  30. procedure WriteTree(p : TAsmList); override;
  31. function MakeCmdLine: TCmdStr; override;
  32. end;
  33. implementation
  34. uses
  35. cutils,globals,verbose,
  36. aasmbase,aasmcpu,
  37. cpuinfo,
  38. cgbase,cgutils;
  39. Procedure TZ80AsmAssembler.WriteTree(p:TAsmList);
  40. function getreferencestring(var ref : treference) : string;
  41. var
  42. s : string;
  43. begin
  44. s:='';
  45. with ref do
  46. begin
  47. {$ifdef extdebug}
  48. // if base=NR_NO then
  49. // internalerror(200308292);
  50. // if ((index<>NR_NO) or (shiftmode<>SM_None)) and ((offset<>0) or (symbol<>nil)) then
  51. // internalerror(200308293);
  52. {$endif extdebug}
  53. if index<>NR_NO then
  54. internalerror(2011021701)
  55. else if base<>NR_NO then
  56. begin
  57. // if addressmode=AM_PREDRECEMENT then
  58. // s:='-';
  59. //case base of
  60. // NR_R26:
  61. // s:=s+'X';
  62. // NR_R28:
  63. // s:=s+'Y';
  64. // NR_R30:
  65. // s:=s+'Z';
  66. // else
  67. // s:=gas_regname(base);
  68. //end;
  69. //if addressmode=AM_POSTINCREMENT then
  70. // s:=s+'+';
  71. //
  72. //if offset>0 then
  73. // s:=s+'+'+tostr(offset)
  74. //else if offset<0 then
  75. // s:=s+tostr(offset)
  76. end
  77. else if assigned(symbol) or (offset<>0) then
  78. begin
  79. //if assigned(symbol) then
  80. // s:=ReplaceForbiddenAsmSymbolChars(symbol.name);
  81. //
  82. //if offset<0 then
  83. // s:=s+tostr(offset)
  84. //else if offset>0 then
  85. // s:=s+'+'+tostr(offset);
  86. //case refaddr of
  87. // addr_hi8:
  88. // s:='hi8('+s+')';
  89. // addr_hi8_gs:
  90. // s:='hi8(gs('+s+'))';
  91. // addr_lo8:
  92. // s:='lo8('+s+')';
  93. // addr_lo8_gs:
  94. // s:='lo8(gs('+s+'))';
  95. // else
  96. // s:='('+s+')';
  97. //end;
  98. end;
  99. end;
  100. getreferencestring:=s;
  101. end;
  102. function getopstr(const o:toper) : string;
  103. var
  104. hs : string;
  105. first : boolean;
  106. r : tsuperregister;
  107. begin
  108. //case o.typ of
  109. // top_reg:
  110. // getopstr:=gas_regname(o.reg);
  111. // top_const:
  112. // getopstr:=tostr(longint(o.val));
  113. // top_ref:
  114. // if o.ref^.refaddr=addr_full then
  115. // begin
  116. // hs:=ReplaceForbiddenAsmSymbolChars(o.ref^.symbol.name);
  117. // if o.ref^.offset>0 then
  118. // hs:=hs+'+'+tostr(o.ref^.offset)
  119. // else
  120. // if o.ref^.offset<0 then
  121. // hs:=hs+tostr(o.ref^.offset);
  122. // getopstr:=hs;
  123. // end
  124. // else
  125. // getopstr:=getreferencestring(o.ref^);
  126. // else
  127. // internalerror(2002070604);
  128. //end;
  129. end;
  130. var op: TAsmOp;
  131. s: string;
  132. i: byte;
  133. sep: string[3];
  134. begin
  135. //op:=taicpu(hp).opcode;
  136. //s:=#9+gas_op2str[op]+cond2str[taicpu(hp).condition];
  137. //if taicpu(hp).ops<>0 then
  138. // begin
  139. // sep:=#9;
  140. // for i:=0 to taicpu(hp).ops-1 do
  141. // begin
  142. // s:=s+sep+getopstr(taicpu(hp).oper[i]^);
  143. // sep:=',';
  144. // end;
  145. // end;
  146. //owner.writer.AsmWriteLn(s);
  147. end;
  148. function TZ80AsmAssembler.MakeCmdLine: TCmdStr;
  149. begin
  150. result := {'-mmcu='+lower(cputypestr[current_settings.cputype])+' '+}inherited MakeCmdLine;
  151. end;
  152. const
  153. as_Z80_asm_info : tasminfo =
  154. (
  155. id : as_z80asm;
  156. idtxt : 'Z80Asm';
  157. asmbin : 'z80asm';
  158. asmcmd : '-o $OBJ $EXTRAOPT $ASM';
  159. supported_targets : [system_Z80_embedded];
  160. flags : [af_needar,af_smartlink_sections];
  161. labelprefix : '.L';
  162. comment : '# ';
  163. dollarsign: 's';
  164. );
  165. begin
  166. RegisterAssembler(as_Z80_asm_info,TZ80AsmAssembler);
  167. end.