agz80asm.pas 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192
  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 GNU Assembler writer for the ARM
  18. }
  19. unit agz80asm;
  20. {$i fpcdefs.inc}
  21. interface
  22. uses
  23. globtype,systems,
  24. aasmtai,aasmdata,
  25. assemble,
  26. cpubase;
  27. type
  28. TZ80GNUAssembler=class(TExternalAssembler)
  29. procedure WriteTree(p : TAsmList); override;
  30. function MakeCmdLine: TCmdStr; override;
  31. end;
  32. implementation
  33. uses
  34. cutils,globals,verbose,
  35. aasmbase,aasmcpu,
  36. cpuinfo,
  37. cgbase,cgutils;
  38. Procedure TZ80GNUAssembler.WriteTree(p:TAsmList);
  39. function getreferencestring(var ref : treference) : string;
  40. var
  41. s : string;
  42. begin
  43. s:='';
  44. with ref do
  45. begin
  46. {$ifdef extdebug}
  47. // if base=NR_NO then
  48. // internalerror(200308292);
  49. // if ((index<>NR_NO) or (shiftmode<>SM_None)) and ((offset<>0) or (symbol<>nil)) then
  50. // internalerror(200308293);
  51. {$endif extdebug}
  52. if index<>NR_NO then
  53. internalerror(2011021701)
  54. else if base<>NR_NO then
  55. begin
  56. // if addressmode=AM_PREDRECEMENT then
  57. // s:='-';
  58. //case base of
  59. // NR_R26:
  60. // s:=s+'X';
  61. // NR_R28:
  62. // s:=s+'Y';
  63. // NR_R30:
  64. // s:=s+'Z';
  65. // else
  66. // s:=gas_regname(base);
  67. //end;
  68. //if addressmode=AM_POSTINCREMENT then
  69. // s:=s+'+';
  70. //
  71. //if offset>0 then
  72. // s:=s+'+'+tostr(offset)
  73. //else if offset<0 then
  74. // s:=s+tostr(offset)
  75. end
  76. else if assigned(symbol) or (offset<>0) then
  77. begin
  78. //if assigned(symbol) then
  79. // s:=ReplaceForbiddenAsmSymbolChars(symbol.name);
  80. //
  81. //if offset<0 then
  82. // s:=s+tostr(offset)
  83. //else if offset>0 then
  84. // s:=s+'+'+tostr(offset);
  85. //case refaddr of
  86. // addr_hi8:
  87. // s:='hi8('+s+')';
  88. // addr_hi8_gs:
  89. // s:='hi8(gs('+s+'))';
  90. // addr_lo8:
  91. // s:='lo8('+s+')';
  92. // addr_lo8_gs:
  93. // s:='lo8(gs('+s+'))';
  94. // else
  95. // s:='('+s+')';
  96. //end;
  97. end;
  98. end;
  99. getreferencestring:=s;
  100. end;
  101. function getopstr(const o:toper) : string;
  102. var
  103. hs : string;
  104. first : boolean;
  105. r : tsuperregister;
  106. begin
  107. //case o.typ of
  108. // top_reg:
  109. // getopstr:=gas_regname(o.reg);
  110. // top_const:
  111. // getopstr:=tostr(longint(o.val));
  112. // top_ref:
  113. // if o.ref^.refaddr=addr_full then
  114. // begin
  115. // hs:=ReplaceForbiddenAsmSymbolChars(o.ref^.symbol.name);
  116. // if o.ref^.offset>0 then
  117. // hs:=hs+'+'+tostr(o.ref^.offset)
  118. // else
  119. // if o.ref^.offset<0 then
  120. // hs:=hs+tostr(o.ref^.offset);
  121. // getopstr:=hs;
  122. // end
  123. // else
  124. // getopstr:=getreferencestring(o.ref^);
  125. // else
  126. // internalerror(2002070604);
  127. //end;
  128. end;
  129. var op: TAsmOp;
  130. s: string;
  131. i: byte;
  132. sep: string[3];
  133. begin
  134. //op:=taicpu(hp).opcode;
  135. //s:=#9+gas_op2str[op]+cond2str[taicpu(hp).condition];
  136. //if taicpu(hp).ops<>0 then
  137. // begin
  138. // sep:=#9;
  139. // for i:=0 to taicpu(hp).ops-1 do
  140. // begin
  141. // s:=s+sep+getopstr(taicpu(hp).oper[i]^);
  142. // sep:=',';
  143. // end;
  144. // end;
  145. //owner.writer.AsmWriteLn(s);
  146. end;
  147. function TZ80GNUAssembler.MakeCmdLine: TCmdStr;
  148. begin
  149. result := '-mmcu='+lower(cputypestr[current_settings.cputype])+' '+inherited MakeCmdLine;
  150. end;
  151. const
  152. as_Z80_asm_info : tasminfo =
  153. (
  154. id : as_z80asm;
  155. idtxt : 'Z80Asm';
  156. asmbin : 'z80asm';
  157. asmcmd : '-o $OBJ $EXTRAOPT $ASM';
  158. supported_targets : [system_Z80_embedded];
  159. flags : [af_needar,af_smartlink_sections];
  160. labelprefix : '.L';
  161. comment : '# ';
  162. dollarsign: 's';
  163. );
  164. begin
  165. RegisterAssembler(as_Z80_asm_info,TZ80GNUAssembler);
  166. end.