Purpose |
Identify an assembly-language statement. PowerBASIC's Inline Assembler supports 8086/8088, 80286, 80386, 80486, Pentium, Floating-Point and MMX instructions. | |||||||||||||||||||||||||||||||||||||||
Syntax |
{! | ASM} opcode | |||||||||||||||||||||||||||||||||||||||
Remarks |
This statement allows you to place assembly-language code within your PowerBASIC source code. An exclamation mark (!) serves as a shortcut for the ASM keyword. Each group of ASM statements must preserve the following CPU registers if the assembler code causes them to change: ESI, EDI, ESP, EBP, and all segment registers. No other statements may appear on the same line as an ASM statement; however, comments are acceptable. ! DB 1, 2, 3, 4, 5 ! DD &H45001222, &HFFFF4327 Any variable referenced in an assembly-language statement must be defined prior to use. For example: x% = 10 ! MOV AX, x% You cannot access the target of a pointer with a single ASM statement as you might do in BASIC source code. Instead, you must use the pointer address indirectly. To simulate the BASIC statement INCR @x, you would write: DIM x AS INTEGER PTR ASM MOV EAX, x ; EAX holds a pointer to ; an Integer ASM INC WORD PTR [EAX] ; Add one to target value String literals
of up to four characters may be used in Inline Assembler code: ! MOV AX, "ab" ; move chars ab into reg AX ! ; "a" into AL, "b" into AH ! MOV EAX, "abcd" ; move chars abcd into reg EAX PowerBASIC recognizes either an apostrophe ( ' ) or a semi-colon ( ; ) to specify a comment after a line of assembler code: ! PUSH EAX ; save the EAX register ! PUSH EBX ' save the EBX register | |||||||||||||||||||||||||||||||||||||||
Restrictions |
Care should be exercised to ensure registers are appropriately preserved when Inline Assembler code is intermixed with BASIC statements. See Saving Registers for more information. | |||||||||||||||||||||||||||||||||||||||
See also |
||||||||||||||||||||||||||||||||||||||||
Example |
To add the values a&, b&, and c&, you would write: LOCAL a&, b&, c&, z& ! MOV EAX, a& ! ADD EAX, b& ! ADD EAX, c& ! MOV z&, EAX | |||||||||||||||||||||||||||||||||||||||
Notes |
The follow lists outline the supported mnemonics, data types, operators, and registers that can be used with the ASM statement.
AAA, AAD, AAM, AAS, ADC, ADD, AND BOUND, BSF, BSR, BSWAP, BT, BTC, BTR, BTS CALL, CBW, CCWD, CDQ, CLC, CLD, CLI, CMC, CMP, CMPSB, CMPSD, CMPSW, CMPXCHG, CPUID, CWDE DAA, DAS, DEC, DIV EMMS F2XM1, FABS, FADD, FADDP, FCHS, FCLEX, FCOM, FCOMP, FCOMPP, FCOS, FDECSTP, FDIV, FDIVP, FDIVR, FDIVRP, FFREE, FIADD, FICOM, FICOMP, FIDIV, FIDIVR, FILD, FIMUL, FINCSTP, FINIT, FIST, FISTP, FISUB, FISUBR, FLD, FLD1, FLDCW, FLDENV, FLDL2E, FLDL2T, FLDLG2, FLDLN2, FLDPI, FLDZ, FMUL, FMULP, FNCLEX, FNINIT, FNLDCW, FNOP, FNSAVE, FNSTCW, FNSTENV, FNSTSW, FPATAN, FPREM, FPREM1, FPTAN, FRNDINT, FRSTOR, FSAVE, FSCALE, FSIN, FSINCOS, FSQRT, FST, FSTCW, FSTENV, FSTP, FSTSW, FSUB, FSUBP, FSUBR, FSUBRP, FTST, FUCOM, FUCOMP, FUCOMPP, FWAIT, FXAM, FXCH, FXTRACT, FYL2X, FYL2XP1 HLT IDIV, IMUL, IN, INC, INSB, INSD, INSW, INT, INTO, IRET, IRETD JA, JAE, JB, JBE, JC, JE, JECXZ, JG, JGE, JL, JLE, JMP, JNA, JNAE, JNB, JNBE, JNC, JNE, JNG, JNGE, JNL, JNLE, JNO, JNP, JNS, JNZ, JO, JP, JPE, JPO, JS, JZ LAHF, LAR, LDS, LEA, LEAVE, LES, LFS, LGS, LOCK, LODSB, LODSD, LODSW, LOOP, LOOPE, LOOPNE, LOOPNZ, LOOPZ, LSL, LSS MOV, MOVD, MOVQ, MOVSB, MOVSD, MOVSW, MOVSX, MOVZX, MUL NEG, NOP, NOT OR, OUT, OUTSB, OUTSD, OUTSW PACKSSDW, PACKSSWB, PACKUSWB, PADDB, PADDD, PADDSB, PADDSW, PADDUSB, PADDUSW, PADDW, PAND, PANDN, PCMPEQB, PCMPEQD, PCMPEQW, PCMPGTB, PCMPGTD, PCMPGTW, PMADDWD, PMULHW, PMULLW, POP, POPA, POPAD, POPF, POPFD, POR, PSLLD, PSLLQ, PSLLW, PSRAD, PSRAW, PSRLD, PSRLQ, PSRLW, PSUBB, PSUBD, PSUBSB, PSUBSW, PSUBUSB, PSUBUSW, PSUBW, PUNPCKHBW, PUNPCKHDQ, PUNPCKHWD, PUNPCKLBW, PUNPCKLDQ, PUNPCKLWD, PUSH, PUSHA, PUSHAD, PUSHF, PUSHFD, PXOR RCL, RCR, REP, REPE, REPNE, REPNZ, REPZ, RET, RETF, RETN, ROL, ROR SAHF, SAL, SAR, SBB, SCASB, SCASD, SCASW, SETA, SETAE, SETB, SETBE, SETC, SETE, SETG, SETGE, SETL, SETLE, SETNA, SETNAE, SETNB, SETNBE, SETNC, SETNE, SETNG, SETNGE, SETNL, SETNLE, SETNO, SETNP, SETNS, SETNZ, SETO, SETP, SETPE, SETPO, SETS, SETZ, SHL, SHLD, SHR, SHRD, STC, STD, STI, STOSB, STOSD, STOSW, SUB TEST VERR, VERW WAIT XCHG, XLAT, XLATB, XOR
BYTE DB, DD, DW, DWD, DWORD FAR NEAR POINTER, PTR QWD, QWORD SHORT TBY, TBYTE WORD, WRD
Integer
Segments CS, DS, ES, SS, FS, GS MMX Registers MM(0), MM(1), MM(2), MM(3), MM(4), MM(5), MM(6), MM(7) MM0, MM1, MM2, MM3, MM4, MM5, MM6, MM7 Floating Point registers ST(0), ST(1), ST(2), ST(3), ST(4), ST(5), ST(6), ST(7) |