rax86.pas 42 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283
  1. {
  2. Copyright (c) 1998-2002 by Carl Eric Codere and Peter Vreman
  3. Handles the common x86 assembler reader routines
  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. {
  18. Contains the common x86 (i386 and x86-64) assembler reader routines.
  19. }
  20. unit rax86;
  21. {$i fpcdefs.inc}
  22. interface
  23. uses
  24. aasmbase,aasmtai,aasmdata,aasmcpu,
  25. cpubase,rautils,cclasses;
  26. { Parser helpers }
  27. function is_prefix(t:tasmop):boolean;
  28. function is_override(t:tasmop):boolean;
  29. Function CheckPrefix(prefixop,op:tasmop): Boolean;
  30. Function CheckOverride(overrideop,op:tasmop): Boolean;
  31. Procedure FWaitWarning;
  32. type
  33. Tx86Operand=class(TOperand)
  34. opsize : topsize;
  35. Procedure SetSize(_size:longint;force:boolean);override;
  36. Procedure SetCorrectSize(opcode:tasmop);override;
  37. Function CheckOperand: boolean; override;
  38. { handles the @Code symbol }
  39. Procedure SetupCode;
  40. { handles the @Data symbol }
  41. Procedure SetupData;
  42. end;
  43. { Operands are always in AT&T order.
  44. Intel reader attaches them right-to-left, then shifts to start with 1 }
  45. Tx86Instruction=class(TInstruction)
  46. opsize : topsize;
  47. constructor Create(optype : tcoperand);override;
  48. { Operand sizes }
  49. procedure AddReferenceSizes; virtual;
  50. procedure SetInstructionOpsize;
  51. procedure CheckOperandSizes;
  52. procedure CheckNonCommutativeOpcodes;
  53. { Additional actions required by specific reader }
  54. procedure FixupOpcode;virtual;
  55. { opcode adding }
  56. function ConcatInstruction(p : TAsmList) : tai;override;
  57. end;
  58. const
  59. AsmPrefixes = 6;
  60. AsmPrefix : array[0..AsmPrefixes-1] of TasmOP =(
  61. A_LOCK,A_REP,A_REPE,A_REPNE,A_REPNZ,A_REPZ
  62. );
  63. AsmOverrides = 6;
  64. AsmOverride : array[0..AsmOverrides-1] of TasmOP =(
  65. A_SEGCS,A_SEGES,A_SEGDS,A_SEGFS,A_SEGGS,A_SEGSS
  66. );
  67. CondAsmOps=3;
  68. CondAsmOp:array[0..CondAsmOps-1] of TasmOp=(
  69. A_CMOVcc, A_Jcc, A_SETcc
  70. );
  71. CondAsmOpStr:array[0..CondAsmOps-1] of string[4]=(
  72. 'CMOV','J','SET'
  73. );
  74. implementation
  75. uses
  76. globtype,globals,systems,verbose,
  77. procinfo,
  78. cpuinfo,cgbase,cgutils,
  79. itcpugas,cgx86, symsym, cutils;
  80. {*****************************************************************************
  81. Parser Helpers
  82. *****************************************************************************}
  83. function is_prefix(t:tasmop):boolean;
  84. var
  85. i : longint;
  86. Begin
  87. is_prefix:=false;
  88. for i:=1 to AsmPrefixes do
  89. if t=AsmPrefix[i-1] then
  90. begin
  91. is_prefix:=true;
  92. exit;
  93. end;
  94. end;
  95. function is_override(t:tasmop):boolean;
  96. var
  97. i : longint;
  98. Begin
  99. is_override:=false;
  100. for i:=1 to AsmOverrides do
  101. if t=AsmOverride[i-1] then
  102. begin
  103. is_override:=true;
  104. exit;
  105. end;
  106. end;
  107. Function CheckPrefix(prefixop,op:tasmop): Boolean;
  108. { Checks if the prefix is valid with the following opcode }
  109. { return false if not, otherwise true }
  110. Begin
  111. CheckPrefix := TRUE;
  112. (* Case prefix of
  113. A_REP,A_REPNE,A_REPE:
  114. Case opcode Of
  115. A_SCASB,A_SCASW,A_SCASD,
  116. A_INS,A_OUTS,A_MOVS,A_CMPS,A_LODS,A_STOS:;
  117. Else
  118. Begin
  119. CheckPrefix := FALSE;
  120. exit;
  121. end;
  122. end; { case }
  123. A_LOCK:
  124. Case opcode Of
  125. A_BT,A_BTS,A_BTR,A_BTC,A_XCHG,A_ADD,A_OR,A_ADC,A_SBB,A_AND,A_SUB,
  126. A_XOR,A_NOT,A_NEG,A_INC,A_DEC:;
  127. Else
  128. Begin
  129. CheckPrefix := FALSE;
  130. Exit;
  131. end;
  132. end; { case }
  133. A_NONE: exit; { no prefix here }
  134. else
  135. CheckPrefix := FALSE;
  136. end; { end case } *)
  137. end;
  138. Function CheckOverride(overrideop,op:tasmop): Boolean;
  139. { Check if the override is valid, and if so then }
  140. { update the instr variable accordingly. }
  141. Begin
  142. CheckOverride := true;
  143. { Case instr.getinstruction of
  144. A_MOVS,A_XLAT,A_CMPS:
  145. Begin
  146. CheckOverride := TRUE;
  147. Message(assem_e_segment_override_not_supported);
  148. end
  149. end }
  150. end;
  151. Procedure FWaitWarning;
  152. begin
  153. if (target_info.system=system_i386_GO32V2) and (cs_fp_emulation in current_settings.moduleswitches) then
  154. Message(asmr_w_fwait_emu_prob);
  155. end;
  156. {*****************************************************************************
  157. TX86Operand
  158. *****************************************************************************}
  159. Procedure Tx86Operand.SetSize(_size:longint;force:boolean);
  160. begin
  161. inherited SetSize(_size,force);
  162. { OS_64 will be set to S_L and be fixed later
  163. in SetCorrectSize }
  164. // multimedia register
  165. case _size of
  166. 16: size := OS_M128;
  167. 32: size := OS_M256;
  168. end;
  169. {$ifdef i8086}
  170. { allows e.g. using 32-bit registers in i8086 inline asm }
  171. if size in [OS_32,OS_S32] then
  172. opsize:=S_L
  173. else
  174. {$endif i8086}
  175. opsize:=TCGSize2Opsize[size];
  176. end;
  177. Procedure Tx86Operand.SetCorrectSize(opcode:tasmop);
  178. begin
  179. if gas_needsuffix[opcode]=attsufFPU then
  180. begin
  181. case size of
  182. OS_32 : opsize:=S_FS;
  183. OS_64 : opsize:=S_FL;
  184. end;
  185. end
  186. else if gas_needsuffix[opcode]=attsufFPUint then
  187. begin
  188. case size of
  189. OS_16 : opsize:=S_IS;
  190. OS_32 : opsize:=S_IL;
  191. OS_64 : opsize:=S_IQ;
  192. end;
  193. end
  194. else if gas_needsuffix[opcode]=AttSufMM then
  195. begin
  196. if (opr.typ=OPR_Reference) then
  197. begin
  198. case size of
  199. OS_32 : size := OS_M32;
  200. OS_64 : size := OS_M64;
  201. end;
  202. end;
  203. end
  204. else
  205. begin
  206. if size=OS_64 then
  207. opsize:=S_Q;
  208. end;
  209. end;
  210. Function Tx86Operand.CheckOperand: boolean;
  211. begin
  212. result:=true;
  213. if (opr.typ=OPR_Reference) then
  214. begin
  215. if not hasvar then
  216. begin
  217. if (getsupreg(opr.ref.base)=RS_EBP) and (opr.ref.offset>0) then
  218. begin
  219. if current_procinfo.procdef.proccalloption=pocall_register then
  220. message(asmr_w_no_direct_ebp_for_parameter)
  221. else
  222. message(asmr_w_direct_ebp_for_parameter_regcall);
  223. end
  224. else if (getsupreg(opr.ref.base)=RS_EBP) and (opr.ref.offset<0) then
  225. message(asmr_w_direct_ebp_neg_offset)
  226. else if (getsupreg(opr.ref.base)=RS_ESP) and (opr.ref.offset<0) then
  227. message(asmr_w_direct_esp_neg_offset);
  228. end;
  229. if (cs_create_pic in current_settings.moduleswitches) and
  230. assigned(opr.ref.symbol) and
  231. not assigned(opr.ref.relsymbol) then
  232. begin
  233. if not(opr.ref.refaddr in [addr_pic,addr_pic_no_got]) then
  234. begin
  235. if (opr.ref.symbol.name <> '_GLOBAL_OFFSET_TABLE_') then
  236. begin
  237. message(asmr_e_need_pic_ref);
  238. result:=false;
  239. end
  240. else
  241. opr.ref.refaddr:=addr_pic;
  242. end
  243. else
  244. begin
  245. {$ifdef x86_64}
  246. { should probably be extended to i386, but there the situation
  247. is more complex and ELF-style PIC still need to be
  248. tested/debugged }
  249. if (opr.ref.symbol.bind in [AB_LOCAL,AB_PRIVATE_EXTERN]) and
  250. (opr.ref.refaddr=addr_pic) then
  251. message(asmr_w_useless_got_for_local)
  252. else if (opr.ref.symbol.bind in [AB_GLOBAL,AB_EXTERNAL,AB_COMMON,AB_WEAK_EXTERNAL]) and
  253. (opr.ref.refaddr=addr_pic_no_got) then
  254. message(asmr_w_global_access_without_got);
  255. {$endif x86_64}
  256. end;
  257. end;
  258. end;
  259. end;
  260. procedure Tx86Operand.SetupCode;
  261. begin
  262. {$ifdef i8086}
  263. opr.typ:=OPR_SYMBOL;
  264. opr.symofs:=0;
  265. opr.symbol:=current_asmdata.RefAsmSymbol(current_procinfo.procdef.mangledname);
  266. opr.symseg:=true;
  267. opr.sym_farproc_entry:=false;
  268. {$else i8086}
  269. Message(asmr_w_CODE_and_DATA_not_supported);
  270. {$endif i8086}
  271. end;
  272. procedure Tx86Operand.SetupData;
  273. begin
  274. {$ifdef i8086}
  275. InitRef;
  276. if current_settings.x86memorymodel=mm_huge then
  277. opr.ref.refaddr:=addr_fardataseg
  278. else
  279. opr.ref.refaddr:=addr_dgroup;
  280. {$else i8086}
  281. Message(asmr_w_CODE_and_DATA_not_supported);
  282. {$endif i8086}
  283. end;
  284. {*****************************************************************************
  285. T386Instruction
  286. *****************************************************************************}
  287. constructor Tx86Instruction.Create(optype : tcoperand);
  288. begin
  289. inherited Create(optype);
  290. Opsize:=S_NO;
  291. end;
  292. const
  293. {$ifdef x86_64}
  294. topsize2memsize: array[topsize] of integer =
  295. (0, 8,16,32,64,8,8,16,8,16,32,
  296. 16,32,64,
  297. 16,32,64,0,0,
  298. 64,
  299. 0,0,0,
  300. 80,
  301. 128,
  302. 256
  303. );
  304. {$else}
  305. topsize2memsize: array[topsize] of integer =
  306. (0, 8,16,32,64,8,8,16,
  307. 16,32,64,
  308. 16,32,64,0,0,
  309. 64,
  310. 0,0,0,
  311. 80,
  312. 128,
  313. 256
  314. );
  315. {$endif}
  316. procedure Tx86Instruction.AddReferenceSizes;
  317. { this will add the sizes for references like [esi] which do not
  318. have the size set yet, it will take only the size if the other
  319. operand is a register }
  320. var
  321. operand2,i,j : longint;
  322. s : tasmsymbol;
  323. so : aint;
  324. ExistsMemRefNoSize: boolean;
  325. ExistsMemRef: boolean;
  326. ExistsConstNoSize: boolean;
  327. ExistsLocalSymSize: boolean;
  328. memrefsize: integer;
  329. memopsize: integer;
  330. memoffset: asizeint;
  331. begin
  332. ExistsMemRefNoSize := false;
  333. ExistsMemRef := false;
  334. ExistsConstNoSize := false;
  335. ExistsLocalSymSize := false;
  336. // EXIST A MEMORY- OR CONSTANT-OPERAND WITHOUT SIZE ?
  337. for i := 1 to ops do
  338. begin
  339. if operands[i].Opr.Typ in [OPR_REFERENCE, OPR_LOCAL] then
  340. begin
  341. ExistsMemRef := true;
  342. if (tx86operand(operands[i]).opsize = S_NO) then
  343. begin
  344. ExistsMemRefNoSize := true;
  345. case operands[i].opr.Typ of
  346. OPR_LOCAL: ExistsLocalSymSize := tx86operand(operands[i]).opr.localsym.getsize > 0;
  347. OPR_REFERENCE: ExistsLocalSymSize := true;
  348. end;
  349. end;
  350. end
  351. else if operands[i].Opr.Typ in [OPR_CONSTANT] then
  352. begin
  353. ExistsConstNoSize := tx86operand(operands[i]).opsize = S_NO;
  354. end;
  355. end;
  356. // ONLY SUPPORTED OPCODES WITH SSE- OR AVX-REGISTERS
  357. if (ExistsMemRef) and
  358. (MemRefInfo(opcode).ExistsSSEAVX) then
  359. begin
  360. // 1. WE HAVE AN SSE- OR AVX-OPCODE WITH MEMORY OPERAND
  361. if (not(ExistsMemRefNoSize)) or
  362. (ExistsLocalSymSize) then
  363. begin
  364. // 2. WE KNOWN THE MEMORYSIZE OF THE MEMORY-OPERAND OR WE CAN
  365. // CALC THE MEMORYSIZE
  366. // 3. CALC THE SIZE OF THE MEMORYOPERAND BY OPCODE-DEFINITION
  367. // 4. COMPARE THE SIZE FROM OPCODE-DEFINITION AND THE REAL MEMORY-OPERAND-SIZE
  368. // - validate memory-reference-size
  369. for i := 1 to ops do
  370. begin
  371. if (operands[i].Opr.Typ in [OPR_REFERENCE, OPR_LOCAL]) then
  372. begin
  373. memrefsize := -1;
  374. case MemRefInfo(opcode).MemRefSize of
  375. msiMem8: memrefsize := 8;
  376. msiMem16: memrefsize := 16;
  377. msiMem32: memrefsize := 32;
  378. msiMem64: memrefsize := 64;
  379. msiMem128: memrefsize := 128;
  380. msiMem256: memrefsize := 256;
  381. msiMemRegSize
  382. : for j := 1 to ops do
  383. begin
  384. if operands[j].Opr.Typ = OPR_REGISTER then
  385. begin
  386. if (tx86operand(operands[j]).opsize <> S_NO) and
  387. (tx86operand(operands[j]).size <> OS_NO) then
  388. begin
  389. case tx86operand(operands[j]).opsize of
  390. S_B : memrefsize := 8;
  391. S_W : memrefsize := 16;
  392. S_L : memrefsize := 32;
  393. S_Q : memrefsize := 64;
  394. S_XMM : memrefsize := 128;
  395. S_YMM : memrefsize := 256;
  396. else Internalerror(777200);
  397. end;
  398. break;
  399. end;
  400. end;
  401. end;
  402. end;
  403. if memrefsize > -1 then
  404. begin
  405. // CALC REAL-MEMORY-OPERAND-SIZE AND A POSSIBLE OFFSET
  406. // OFFSET:
  407. // e.g. PAND XMM0, [RAX + 16] =>> OFFSET = 16 BYTES
  408. // PAND XMM0, [RAX + a.b + 10] =>> OFFSET = 10 BYTES (a = record-variable)
  409. memopsize := 0;
  410. case operands[i].opr.typ of
  411. OPR_LOCAL: memopsize := operands[i].opr.localvarsize * 8;
  412. OPR_REFERENCE:
  413. if operands[i].opr.ref.refaddr = addr_pic then
  414. memopsize := sizeof(pint) * 8
  415. else
  416. memopsize := operands[i].opr.varsize * 8;
  417. end;
  418. if memopsize = 0 then memopsize := topsize2memsize[tx86operand(operands[i]).opsize];
  419. if (memopsize > 0) and
  420. (memrefsize > 0) then
  421. begin
  422. memoffset := 0;
  423. case operands[i].opr.typ of
  424. OPR_LOCAL:
  425. memoffset := operands[i].opr.localconstoffset;
  426. OPR_REFERENCE:
  427. memoffset := operands[i].opr.constoffset;
  428. end;
  429. if memoffset < 0 then
  430. begin
  431. Message2(asmr_w_check_mem_operand_negative_offset,
  432. std_op2str[opcode],
  433. ToStr(memoffset));
  434. end
  435. else if (memopsize < (memrefsize + memoffset * 8)) then
  436. begin
  437. if memoffset = 0 then
  438. begin
  439. Message3(asmr_w_check_mem_operand_size3,
  440. std_op2str[opcode],
  441. ToStr(memopsize),
  442. ToStr(memrefsize)
  443. );
  444. end
  445. else
  446. begin
  447. Message4(asmr_w_check_mem_operand_size_offset,
  448. std_op2str[opcode],
  449. ToStr(memopsize),
  450. ToStr(memrefsize),
  451. ToStr(memoffset)
  452. );
  453. end;
  454. end;
  455. end;
  456. end;
  457. end;
  458. end;
  459. end;
  460. end;
  461. if (ExistsMemRefNoSize or ExistsConstNoSize) and
  462. (MemRefInfo(opcode).ExistsSSEAVX) then
  463. begin
  464. for i := 1 to ops do
  465. begin
  466. if (tx86operand(operands[i]).opsize = S_NO) then
  467. begin
  468. case operands[i].Opr.Typ of
  469. OPR_REFERENCE:
  470. case MemRefInfo(opcode).MemRefSize of
  471. msiMem8:
  472. begin
  473. tx86operand(operands[i]).opsize := S_B;
  474. tx86operand(operands[i]).size := OS_8;
  475. end;
  476. msiMultiple8:
  477. begin
  478. tx86operand(operands[i]).opsize := S_B;
  479. tx86operand(operands[i]).size := OS_8;
  480. Message2(asmr_w_check_mem_operand_automap_multiple_size, std_op2str[opcode], '"8 bit memory operand"');
  481. end;
  482. msiMem16:
  483. begin
  484. tx86operand(operands[i]).opsize := S_W;
  485. tx86operand(operands[i]).size := OS_16;
  486. end;
  487. msiMultiple16:
  488. begin
  489. tx86operand(operands[i]).opsize := S_W;
  490. tx86operand(operands[i]).size := OS_16;
  491. Message2(asmr_w_check_mem_operand_automap_multiple_size, std_op2str[opcode], '"16 bit memory operand"');
  492. end;
  493. msiMem32:
  494. begin
  495. tx86operand(operands[i]).opsize := S_L;
  496. tx86operand(operands[i]).size := OS_32;
  497. end;
  498. msiMultiple32:
  499. begin
  500. tx86operand(operands[i]).opsize := S_L;
  501. tx86operand(operands[i]).size := OS_32;
  502. Message2(asmr_w_check_mem_operand_automap_multiple_size, std_op2str[opcode], '"32 bit memory operand"');
  503. end;
  504. msiMem64:
  505. begin
  506. tx86operand(operands[i]).opsize := S_Q;
  507. tx86operand(operands[i]).size := OS_M64;
  508. end;
  509. msiMultiple64:
  510. begin
  511. tx86operand(operands[i]).opsize := S_Q;
  512. tx86operand(operands[i]).size := OS_M64;
  513. Message2(asmr_w_check_mem_operand_automap_multiple_size, std_op2str[opcode], '"64 bit memory operand"');
  514. end;
  515. msiMem128:
  516. begin
  517. tx86operand(operands[i]).opsize := S_XMM;
  518. tx86operand(operands[i]).size := OS_M128;
  519. end;
  520. msiMultiple128:
  521. begin
  522. tx86operand(operands[i]).opsize := S_XMM;
  523. tx86operand(operands[i]).size := OS_M128;
  524. Message2(asmr_w_check_mem_operand_automap_multiple_size, std_op2str[opcode], '"128 bit memory operand"');
  525. end;
  526. msiMem256:
  527. begin
  528. tx86operand(operands[i]).opsize := S_YMM;
  529. tx86operand(operands[i]).size := OS_M256;
  530. opsize := S_YMM;
  531. end;
  532. msiMultiple256:
  533. begin
  534. tx86operand(operands[i]).opsize := S_YMM;
  535. tx86operand(operands[i]).size := OS_M256;
  536. opsize := S_YMM;
  537. Message2(asmr_w_check_mem_operand_automap_multiple_size, std_op2str[opcode], '"256 bit memory operand"');
  538. end;
  539. msiMemRegSize:
  540. begin
  541. // mem-ref-size = register size
  542. for j := 1 to ops do
  543. begin
  544. if operands[j].Opr.Typ = OPR_REGISTER then
  545. begin
  546. if (tx86operand(operands[j]).opsize <> S_NO) and
  547. (tx86operand(operands[j]).size <> OS_NO) then
  548. begin
  549. tx86operand(operands[i]).opsize := tx86operand(operands[j]).opsize;
  550. tx86operand(operands[i]).size := tx86operand(operands[j]).size;
  551. break;
  552. end
  553. else Message(asmr_e_unable_to_determine_reference_size);
  554. end;
  555. end;
  556. end;
  557. msiMemRegx16y32:
  558. begin
  559. for j := 1 to ops do
  560. begin
  561. if operands[j].Opr.Typ = OPR_REGISTER then
  562. begin
  563. case getsubreg(operands[j].opr.reg) of
  564. R_SUBMMX: begin
  565. tx86operand(operands[i]).opsize := S_L;
  566. tx86operand(operands[i]).size := OS_M16;
  567. break;
  568. end;
  569. R_SUBMMY: begin
  570. tx86operand(operands[i]).opsize := S_Q;
  571. tx86operand(operands[i]).size := OS_M32;
  572. break;
  573. end;
  574. else Message(asmr_e_unable_to_determine_reference_size);
  575. end;
  576. end;
  577. end;
  578. end;
  579. msiMemRegx32y64:
  580. begin
  581. for j := 1 to ops do
  582. begin
  583. if operands[j].Opr.Typ = OPR_REGISTER then
  584. begin
  585. case getsubreg(operands[j].opr.reg) of
  586. R_SUBMMX: begin
  587. tx86operand(operands[i]).opsize := S_L;
  588. tx86operand(operands[i]).size := OS_M32;
  589. break;
  590. end;
  591. R_SUBMMY: begin
  592. tx86operand(operands[i]).opsize := S_Q;
  593. tx86operand(operands[i]).size := OS_M64;
  594. break;
  595. end;
  596. else Message(asmr_e_unable_to_determine_reference_size);
  597. end;
  598. end;
  599. end;
  600. end;
  601. msiMemRegx64y128:
  602. begin
  603. for j := 1 to ops do
  604. begin
  605. if operands[j].Opr.Typ = OPR_REGISTER then
  606. begin
  607. case getsubreg(operands[j].opr.reg) of
  608. R_SUBMMX: begin
  609. tx86operand(operands[i]).opsize := S_Q;
  610. tx86operand(operands[i]).size := OS_M64;
  611. break;
  612. end;
  613. R_SUBMMY: begin
  614. tx86operand(operands[i]).opsize := S_XMM;
  615. tx86operand(operands[i]).size := OS_M128;
  616. break;
  617. end;
  618. else Message(asmr_e_unable_to_determine_reference_size);
  619. end;
  620. end;
  621. end;
  622. end;
  623. msiMemRegx64y256:
  624. begin
  625. for j := 1 to ops do
  626. begin
  627. if operands[j].Opr.Typ = OPR_REGISTER then
  628. begin
  629. case getsubreg(operands[j].opr.reg) of
  630. R_SUBMMX: begin
  631. tx86operand(operands[i]).opsize := S_Q;
  632. tx86operand(operands[i]).size := OS_M64;
  633. break;
  634. end;
  635. R_SUBMMY: begin
  636. tx86operand(operands[i]).opsize := S_YMM;
  637. tx86operand(operands[i]).size := OS_M256;
  638. break;
  639. end;
  640. else Message(asmr_e_unable_to_determine_reference_size);
  641. end;
  642. end;
  643. end;
  644. end;
  645. msiNoSize: ; // all memory-sizes are ok
  646. msiMultiple: Message(asmr_e_unable_to_determine_reference_size); // TODO individual message
  647. end;
  648. OPR_CONSTANT:
  649. case MemRefInfo(opcode).ConstSize of
  650. csiMem8: begin
  651. tx86operand(operands[i]).opsize := S_B;
  652. tx86operand(operands[i]).size := OS_8;
  653. end;
  654. csiMem16: begin
  655. tx86operand(operands[i]).opsize := S_W;
  656. tx86operand(operands[i]).size := OS_16;
  657. end;
  658. csiMem32: begin
  659. tx86operand(operands[i]).opsize := S_L;
  660. tx86operand(operands[i]).size := OS_32;
  661. end;
  662. end;
  663. end;
  664. end;
  665. end;
  666. end;
  667. for i:=1 to ops do
  668. begin
  669. operands[i].SetCorrectSize(opcode);
  670. if tx86operand(operands[i]).opsize=S_NO then
  671. begin
  672. {$ifdef x86_64}
  673. if (opcode=A_MOVQ) and
  674. (ops=2) and
  675. (operands[1].opr.typ=OPR_CONSTANT) then
  676. opsize:=S_Q
  677. else
  678. {$endif x86_64}
  679. case operands[i].Opr.Typ of
  680. OPR_LOCAL,
  681. OPR_REFERENCE :
  682. begin
  683. { for 3-operand opcodes, operand #1 (in ATT order) is always an immediate,
  684. don't consider it. }
  685. if i=ops then
  686. operand2:=i-1
  687. else
  688. operand2:=i+1;
  689. if operand2>0 then
  690. begin
  691. { Only allow register as operand to take the size from }
  692. if operands[operand2].opr.typ=OPR_REGISTER then
  693. begin
  694. if ((opcode<>A_MOVD) and
  695. (opcode<>A_CVTSI2SS)) then
  696. begin
  697. //tx86operand(operands[i]).opsize:=tx86operand(operands[operand2]).opsize;
  698. // torsten - 31.01.2012
  699. // old: xmm/ymm-register operands have a opsize = "S_NO"
  700. // new: xmm/ymm-register operands have a opsize = "S_XMM/S_YMM"
  701. // any SSE- and AVX-opcodes have mixed operand sizes (e.g. cvtsd2ss xmmreg, xmmreg/m32)
  702. // in this case is we need the old handling ("S_NO")
  703. // =>> ignore
  704. if (tx86operand(operands[operand2]).opsize <> S_XMM) and
  705. (tx86operand(operands[operand2]).opsize <> S_YMM) then
  706. tx86operand(operands[i]).opsize:=tx86operand(operands[operand2]).opsize
  707. else tx86operand(operands[operand2]).opsize := S_NO;
  708. end;
  709. end
  710. else
  711. begin
  712. { if no register then take the opsize (which is available with ATT),
  713. if not availble then give an error }
  714. if opsize<>S_NO then
  715. tx86operand(operands[i]).opsize:=opsize
  716. else
  717. begin
  718. if (m_delphi in current_settings.modeswitches) then
  719. Message(asmr_w_unable_to_determine_reference_size_using_dword)
  720. else
  721. Message(asmr_e_unable_to_determine_reference_size);
  722. { recovery }
  723. tx86operand(operands[i]).opsize:=S_L;
  724. end;
  725. end;
  726. end
  727. else
  728. begin
  729. if opsize<>S_NO then
  730. tx86operand(operands[i]).opsize:=opsize
  731. end;
  732. end;
  733. OPR_SYMBOL :
  734. begin
  735. { Fix lea which need a reference }
  736. if opcode=A_LEA then
  737. begin
  738. s:=operands[i].opr.symbol;
  739. so:=operands[i].opr.symofs;
  740. operands[i].opr.typ:=OPR_REFERENCE;
  741. Fillchar(operands[i].opr.ref,sizeof(treference),0);
  742. operands[i].opr.ref.symbol:=s;
  743. operands[i].opr.ref.offset:=so;
  744. end;
  745. {$if defined(x86_64)}
  746. tx86operand(operands[i]).opsize:=S_Q;
  747. {$elseif defined(i386)}
  748. tx86operand(operands[i]).opsize:=S_L;
  749. {$elseif defined(i8086)}
  750. tx86operand(operands[i]).opsize:=S_W;
  751. {$endif}
  752. end;
  753. end;
  754. end;
  755. end;
  756. end;
  757. procedure Tx86Instruction.SetInstructionOpsize;
  758. begin
  759. if opsize<>S_NO then
  760. exit;
  761. case ops of
  762. 0 : ;
  763. 1 :
  764. begin
  765. { "push es" must be stored as a long PM }
  766. if ((opcode=A_PUSH) or
  767. (opcode=A_POP)) and
  768. (operands[1].opr.typ=OPR_REGISTER) and
  769. is_segment_reg(operands[1].opr.reg) then
  770. {$ifdef i8086}
  771. opsize:=S_W
  772. {$else i8086}
  773. opsize:=S_L
  774. {$endif i8086}
  775. else
  776. opsize:=tx86operand(operands[1]).opsize;
  777. end;
  778. 2 :
  779. begin
  780. case opcode of
  781. A_MOVZX,A_MOVSX :
  782. begin
  783. if tx86operand(operands[1]).opsize=S_NO then
  784. begin
  785. tx86operand(operands[1]).opsize:=S_B;
  786. if (m_delphi in current_settings.modeswitches) then
  787. Message(asmr_w_unable_to_determine_reference_size_using_byte)
  788. else
  789. Message(asmr_e_unable_to_determine_reference_size);
  790. end;
  791. case tx86operand(operands[1]).opsize of
  792. S_W :
  793. case tx86operand(operands[2]).opsize of
  794. S_L :
  795. opsize:=S_WL;
  796. {$ifdef x86_64}
  797. S_Q :
  798. opsize:=S_WQ;
  799. {$endif}
  800. end;
  801. S_B :
  802. begin
  803. case tx86operand(operands[2]).opsize of
  804. S_W :
  805. opsize:=S_BW;
  806. S_L :
  807. opsize:=S_BL;
  808. {$ifdef x86_64}
  809. S_Q :
  810. opsize:=S_BQ;
  811. {$endif}
  812. end;
  813. end;
  814. end;
  815. end;
  816. A_MOVD : { movd is a move from a mmx register to a
  817. 32 bit register or memory, so no opsize is correct here PM }
  818. exit;
  819. A_MOVQ :
  820. opsize:=S_IQ;
  821. A_OUT :
  822. opsize:=tx86operand(operands[1]).opsize;
  823. else
  824. opsize:=tx86operand(operands[2]).opsize;
  825. end;
  826. end;
  827. 3,4 :
  828. opsize:=tx86operand(operands[ops]).opsize;
  829. end;
  830. end;
  831. procedure Tx86Instruction.CheckOperandSizes;
  832. var
  833. sizeerr : boolean;
  834. i : longint;
  835. begin
  836. { Check only the most common opcodes here, the others are done in
  837. the assembler pass }
  838. case opcode of
  839. A_PUSH,A_POP,A_DEC,A_INC,A_NOT,A_NEG,
  840. A_CMP,A_MOV,
  841. A_ADD,A_SUB,A_ADC,A_SBB,
  842. A_AND,A_OR,A_TEST,A_XOR: ;
  843. else
  844. exit;
  845. end;
  846. { Handle the BW,BL,WL separatly }
  847. sizeerr:=false;
  848. { special push/pop selector case }
  849. if ((opcode=A_PUSH) or
  850. (opcode=A_POP)) and
  851. (operands[1].opr.typ=OPR_REGISTER) and
  852. is_segment_reg(operands[1].opr.reg) then
  853. exit;
  854. if opsize in [S_BW,S_BL,S_WL] then
  855. begin
  856. if ops<>2 then
  857. sizeerr:=true
  858. else
  859. begin
  860. case opsize of
  861. S_BW :
  862. sizeerr:=(tx86operand(operands[1]).opsize<>S_B) or (tx86operand(operands[2]).opsize<>S_W);
  863. S_BL :
  864. sizeerr:=(tx86operand(operands[1]).opsize<>S_B) or (tx86operand(operands[2]).opsize<>S_L);
  865. S_WL :
  866. sizeerr:=(tx86operand(operands[1]).opsize<>S_W) or (tx86operand(operands[2]).opsize<>S_L);
  867. end;
  868. end;
  869. end
  870. else
  871. begin
  872. for i:=1 to ops do
  873. begin
  874. if (operands[i].opr.typ<>OPR_CONSTANT) and
  875. (tx86operand(operands[i]).opsize in [S_B,S_W,S_L]) and
  876. (tx86operand(operands[i]).opsize<>opsize) then
  877. sizeerr:=true;
  878. end;
  879. end;
  880. if sizeerr then
  881. begin
  882. { if range checks are on then generate an error }
  883. if (cs_compilesystem in current_settings.moduleswitches) or
  884. not (cs_check_range in current_settings.localswitches) then
  885. Message(asmr_w_size_suffix_and_dest_dont_match)
  886. else
  887. Message(asmr_e_size_suffix_and_dest_dont_match);
  888. end;
  889. end;
  890. { This check must be done with the operand in ATT order
  891. i.e.after swapping in the intel reader
  892. but before swapping in the NASM and TASM writers PM }
  893. procedure Tx86Instruction.CheckNonCommutativeOpcodes;
  894. begin
  895. if (
  896. (ops=2) and
  897. (operands[1].opr.typ=OPR_REGISTER) and
  898. (operands[2].opr.typ=OPR_REGISTER) and
  899. { if the first is ST and the second is also a register
  900. it is necessarily ST1 .. ST7 }
  901. ((operands[1].opr.reg=NR_ST) or
  902. (operands[1].opr.reg=NR_ST0))
  903. ) or
  904. (ops=0) then
  905. if opcode=A_FSUBR then
  906. opcode:=A_FSUB
  907. else if opcode=A_FSUB then
  908. opcode:=A_FSUBR
  909. else if opcode=A_FDIVR then
  910. opcode:=A_FDIV
  911. else if opcode=A_FDIV then
  912. opcode:=A_FDIVR
  913. else if opcode=A_FSUBRP then
  914. opcode:=A_FSUBP
  915. else if opcode=A_FSUBP then
  916. opcode:=A_FSUBRP
  917. else if opcode=A_FDIVRP then
  918. opcode:=A_FDIVP
  919. else if opcode=A_FDIVP then
  920. opcode:=A_FDIVRP;
  921. if (
  922. (ops=1) and
  923. (operands[1].opr.typ=OPR_REGISTER) and
  924. (getregtype(operands[1].opr.reg)=R_FPUREGISTER) and
  925. (operands[1].opr.reg<>NR_ST) and
  926. (operands[1].opr.reg<>NR_ST0)
  927. ) then
  928. if opcode=A_FSUBRP then
  929. opcode:=A_FSUBP
  930. else if opcode=A_FSUBP then
  931. opcode:=A_FSUBRP
  932. else if opcode=A_FDIVRP then
  933. opcode:=A_FDIVP
  934. else if opcode=A_FDIVP then
  935. opcode:=A_FDIVRP;
  936. end;
  937. procedure Tx86Instruction.FixupOpcode;
  938. begin
  939. { does nothing by default }
  940. end;
  941. {*****************************************************************************
  942. opcode Adding
  943. *****************************************************************************}
  944. function Tx86Instruction.ConcatInstruction(p : TAsmList) : tai;
  945. var
  946. siz : topsize;
  947. i,asize : longint;
  948. ai : taicpu;
  949. begin
  950. ConcatInstruction:=nil;
  951. ai:=nil;
  952. for i:=1 to Ops do
  953. if not operands[i].CheckOperand then
  954. exit;
  955. { Get Opsize }
  956. if (opsize<>S_NO) or (Ops=0) then
  957. siz:=opsize
  958. else
  959. begin
  960. if (Ops=2) and (operands[1].opr.typ=OPR_REGISTER) then
  961. siz:=tx86operand(operands[1]).opsize
  962. else
  963. siz:=tx86operand(operands[Ops]).opsize;
  964. { MOVD should be of size S_LQ or S_QL, but these do not exist PM }
  965. if (ops=2) and
  966. (tx86operand(operands[1]).opsize<>S_NO) and
  967. (tx86operand(operands[2]).opsize<>S_NO) and
  968. (tx86operand(operands[1]).opsize<>tx86operand(operands[2]).opsize) then
  969. siz:=S_NO;
  970. end;
  971. if ((opcode=A_MOVD)or
  972. (opcode=A_CVTSI2SS)) and
  973. ((tx86operand(operands[1]).opsize=S_NO) or
  974. (tx86operand(operands[2]).opsize=S_NO)) then
  975. siz:=S_NO;
  976. { NASM does not support FADD without args
  977. as alias of FADDP
  978. and GNU AS interprets FADD without operand differently
  979. for version 2.9.1 and 2.9.5 !! }
  980. if (ops=0) and
  981. ((opcode=A_FADD) or
  982. (opcode=A_FMUL) or
  983. (opcode=A_FSUB) or
  984. (opcode=A_FSUBR) or
  985. (opcode=A_FDIV) or
  986. (opcode=A_FDIVR)) then
  987. begin
  988. if opcode=A_FADD then
  989. opcode:=A_FADDP
  990. else if opcode=A_FMUL then
  991. opcode:=A_FMULP
  992. else if opcode=A_FSUB then
  993. opcode:=A_FSUBP
  994. else if opcode=A_FSUBR then
  995. opcode:=A_FSUBRP
  996. else if opcode=A_FDIV then
  997. opcode:=A_FDIVP
  998. else if opcode=A_FDIVR then
  999. opcode:=A_FDIVRP;
  1000. message1(asmr_w_fadd_to_faddp,std_op2str[opcode]);
  1001. end;
  1002. {It is valid to specify some instructions without operand size.}
  1003. if siz=S_NO then
  1004. begin
  1005. if (ops=1) and (opcode=A_INT) then
  1006. siz:=S_B;
  1007. if (ops=1) and (opcode=A_RET) or (opcode=A_RETN) or (opcode=A_RETF) then
  1008. siz:=S_W;
  1009. if (ops=1) and (opcode=A_PUSH) then
  1010. begin
  1011. {We are a 32 compiler, assume 32-bit by default. This is Delphi
  1012. compatible but bad coding practise.}
  1013. siz:=S_L;
  1014. message(asmr_w_unable_to_determine_reference_size_using_dword);
  1015. end;
  1016. if (opcode=A_JMP) or (opcode=A_JCC) or (opcode=A_CALL) then
  1017. if ops=1 then
  1018. siz:=S_NEAR
  1019. else
  1020. siz:=S_FAR;
  1021. end;
  1022. { GNU AS interprets FDIV without operand differently
  1023. for version 2.9.1 and 2.10
  1024. we add explicit args to it !! }
  1025. if (ops=0) and
  1026. ((opcode=A_FSUBP) or
  1027. (opcode=A_FSUBRP) or
  1028. (opcode=A_FDIVP) or
  1029. (opcode=A_FDIVRP) or
  1030. (opcode=A_FSUB) or
  1031. (opcode=A_FSUBR) or
  1032. (opcode=A_FADD) or
  1033. (opcode=A_FADDP) or
  1034. (opcode=A_FDIV) or
  1035. (opcode=A_FDIVR)) then
  1036. begin
  1037. message1(asmr_w_adding_explicit_args_fXX,std_op2str[opcode]);
  1038. ops:=2;
  1039. operands[1].opr.typ:=OPR_REGISTER;
  1040. operands[2].opr.typ:=OPR_REGISTER;
  1041. operands[1].opr.reg:=NR_ST0;
  1042. operands[2].opr.reg:=NR_ST1;
  1043. end;
  1044. if (ops=1) and
  1045. (
  1046. (operands[1].opr.typ=OPR_REGISTER) and
  1047. (getregtype(operands[1].opr.reg)=R_FPUREGISTER) and
  1048. (operands[1].opr.reg<>NR_ST) and
  1049. (operands[1].opr.reg<>NR_ST0)
  1050. ) and
  1051. (
  1052. (opcode=A_FSUBP) or
  1053. (opcode=A_FSUBRP) or
  1054. (opcode=A_FDIVP) or
  1055. (opcode=A_FDIVRP) or
  1056. (opcode=A_FADDP) or
  1057. (opcode=A_FMULP)
  1058. ) then
  1059. begin
  1060. message1(asmr_w_adding_explicit_first_arg_fXX,std_op2str[opcode]);
  1061. ops:=2;
  1062. operands[2].opr.typ:=OPR_REGISTER;
  1063. operands[2].opr.reg:=operands[1].opr.reg;
  1064. operands[1].opr.reg:=NR_ST0;
  1065. end;
  1066. if (ops=1) and
  1067. (
  1068. (operands[1].opr.typ=OPR_REGISTER) and
  1069. (getregtype(operands[1].opr.reg)=R_FPUREGISTER) and
  1070. (operands[1].opr.reg<>NR_ST) and
  1071. (operands[1].opr.reg<>NR_ST0)
  1072. ) and
  1073. (
  1074. (opcode=A_FSUB) or
  1075. (opcode=A_FSUBR) or
  1076. (opcode=A_FDIV) or
  1077. (opcode=A_FDIVR) or
  1078. (opcode=A_FADD) or
  1079. (opcode=A_FMUL)
  1080. ) then
  1081. begin
  1082. message1(asmr_w_adding_explicit_second_arg_fXX,std_op2str[opcode]);
  1083. ops:=2;
  1084. operands[2].opr.typ:=OPR_REGISTER;
  1085. operands[2].opr.reg:=NR_ST0;
  1086. end;
  1087. { I tried to convince Linus Torvalds to add
  1088. code to support ENTER instruction
  1089. (when raising a stack page fault)
  1090. but he replied that ENTER is a bad instruction and
  1091. Linux does not need to support it
  1092. So I think its at least a good idea to add a warning
  1093. if someone uses this in assembler code
  1094. FPC itself does not use it at all PM }
  1095. if (opcode=A_ENTER) and
  1096. (target_info.system in [system_i386_linux,system_i386_FreeBSD,system_i386_android]) then
  1097. Message(asmr_w_enter_not_supported_by_linux);
  1098. ai:=taicpu.op_none(opcode,siz);
  1099. ai.fileinfo:=filepos;
  1100. ai.SetOperandOrder(op_att);
  1101. ai.Ops:=Ops;
  1102. ai.Allocate_oper(Ops);
  1103. for i:=1 to Ops do
  1104. case operands[i].opr.typ of
  1105. OPR_CONSTANT :
  1106. ai.loadconst(i-1,operands[i].opr.val);
  1107. OPR_REGISTER:
  1108. ai.loadreg(i-1,operands[i].opr.reg);
  1109. OPR_SYMBOL:
  1110. {$ifdef i8086}
  1111. if operands[i].opr.symseg then
  1112. taicpu(ai).loadsegsymbol(i-1,operands[i].opr.symbol)
  1113. else
  1114. {$endif i8086}
  1115. ai.loadsymbol(i-1,operands[i].opr.symbol,operands[i].opr.symofs);
  1116. OPR_LOCAL :
  1117. with operands[i].opr do
  1118. ai.loadlocal(i-1,localsym,localsymofs,localindexreg,
  1119. localscale,localgetoffset,localforceref);
  1120. OPR_REFERENCE:
  1121. begin
  1122. ai.loadref(i-1,operands[i].opr.ref);
  1123. if operands[i].size<>OS_NO then
  1124. begin
  1125. asize:=0;
  1126. case operands[i].size of
  1127. OS_8,OS_S8 :
  1128. asize:=OT_BITS8;
  1129. OS_16,OS_S16, OS_M16:
  1130. asize:=OT_BITS16;
  1131. OS_32,OS_S32 :
  1132. {$ifdef i8086}
  1133. if siz=S_FAR then
  1134. asize:=OT_FAR
  1135. else
  1136. asize:=OT_BITS16;
  1137. {$else i8086}
  1138. asize:=OT_BITS32;
  1139. {$endif i8086}
  1140. OS_F32,OS_M32 :
  1141. asize:=OT_BITS32;
  1142. OS_64,OS_S64:
  1143. begin
  1144. { Only FPU operations know about 64bit values, for all
  1145. integer operations it is seen as 32bit
  1146. this applies only to i386, see tw16622}
  1147. if gas_needsuffix[opcode] in [attsufFPU,attsufFPUint] then
  1148. asize:=OT_BITS64
  1149. {$ifdef i386}
  1150. else
  1151. asize:=OT_BITS32
  1152. {$endif i386}
  1153. ;
  1154. end;
  1155. OS_F64,OS_C64, OS_M64 :
  1156. asize:=OT_BITS64;
  1157. OS_F80 :
  1158. asize:=OT_BITS80;
  1159. OS_128,OS_M128,OS_MS128:
  1160. asize := OT_BITS128;
  1161. OS_M256,OS_MS256:
  1162. asize := OT_BITS256;
  1163. end;
  1164. if asize<>0 then
  1165. ai.oper[i-1]^.ot:=(ai.oper[i-1]^.ot and not OT_SIZE_MASK) or asize;
  1166. end;
  1167. end;
  1168. end;
  1169. { Condition ? }
  1170. if condition<>C_None then
  1171. ai.SetCondition(condition);
  1172. { Set is_jmp, it enables asmwriter to emit short jumps if appropriate }
  1173. if (opcode=A_JMP) or (opcode=A_JCC) then
  1174. ai.is_jmp := True;
  1175. { Concat the opcode or give an error }
  1176. if assigned(ai) then
  1177. p.concat(ai)
  1178. else
  1179. Message(asmr_e_invalid_opcode_and_operand);
  1180. result:=ai;
  1181. end;
  1182. end.