60 likes | 182 Views
Lect 6: Instruction Set. Instruction Set. Logic Instructions AND, OR, XOR, NOT Shift Instructions SAL/SHL, SHR/SAR, SHLD, SHRD: SHL AX, 1; SAR AX, CL Rotate Instructions ROL, ROR, RCL, RCR ROR AX,1; ROL AX, CL Bit Test and Bit Scan Instructions
E N D
Instruction Set • Logic Instructions • AND, OR, XOR, NOT • Shift Instructions • SAL/SHL, SHR/SAR, SHLD, SHRD: • SHL AX, 1; SAR AX, CL • Rotate Instructions • ROL, ROR, RCL, RCR • ROR AX,1; ROL AX, CL • Bit Test and Bit Scan Instructions • BT(Bit Test), BTR(Bit test and reset), BTS(Bit test and set), BTC(Bit test and complement), BSF(Bit scan forward), BSR(Bit scan reverse) • BT D, S ; CF ¬ BIT[D,S]; saves the value of the bit indicated by the first operand and the bit offset into the CF flag • BSF r16,r/m16 or BSF r32, r/m32 ; scans the bits in the second word or double word operand starting with bit 0. The ZF flag is set if all the bits are 0; otherwise, the ZF flag is cleared and the destination register is loaded with the bit index of the first set bit.
Instruction Set • Flag-Control Instructions • LAHF(Load AH from flags), SAHF(Store AH into flags), CLC, STC, CMC, CLI, STI • AH : |SF|ZF| - |AF| - |PF| - |CF| • Compare and Set Instructions • CMP • SETcc r/m8: if condition then r/m8 ¬ 1(not FF) else r/m8 ¬ 0; • SETA, SETAE,..... • Jump Instructions • Unconditional(JMP) and Conditional Jumps(JA, JAE, .... ) • JMP : Intrasegment jump, Intersegment jump • Intrasegment jump : short(8-bit displacement: -126 to +129), direct within segment (16-bit or 32-bit relative), r/m indirect with segment • Intersegment jump : direct intersegment (full offset and selector), indirect intersegment • Jcc : conditional jump; 8-bit or full displacement • JA, JAE, ....
Instruction Set • Subroutines and Subroutine-Handling Instructions • CALL and Return Instructions • CALL : intrasegment and intersegment call; • Intrasegment : CALL rel16, or rel32, CALL indirect within segment • Intersegment : CALL direct intersegment, CALL indirect intersegment • RET • Intrasegment : RET within segment, RET within segment Adding Immediate to SP • Intersegment : RET, RET adding immediate to SP • Stack Frame Instructions: ENTER and LEAVE • to allocate and deallocate a data area called a stack frame • ENTER : make a stack frame • ENTER imm16,0; Make procedure stack frame • ENTER imm16,1; Make stack frame for procedure parameter • ENTER imm16,imm8: Make stack frame for procedure parameter • first operand : the number of bytes to be allocated on the stack for local data storage second operand: lexical nesting level of the routine
Procedure A Procedure B Procedure C Enter 32, 1 Enter 12, 2 Enter 16, 3 Leave Ret Leave Ret Leave Ret Instruction Set Data for Proc. C (16 bytes) BP for Proc. C BP for Proc. B BP for Proc. A BP for Proc. B Ret addr for proc. B Data for Proc. B (12 bytes) BP for Proc. B BP for Proc. A BP for Proc. A Ret addr for proc. A Data for Proc. A (32 bytes) BP for Proc. A Old BP Stack frame for C BP when executing Procedure C Stack frame for B BP when executing Procedure B Stack frame for A BP when executing Procedure A
Instruction Set • Loop and Loop-handling Instructions • LOOP, LOOPE/Z, LOOPNE/NZ: CX must be preloaded with a count • String and String-Handling Instructions • MOVSB/W/D, compare string, scan string, load string, store string • the contents of both SI and DI are automatically incremented or decremented. • REP : repeat string; • Check Array Index Against Bounds • BOUND r16, m16&16 : check if r16 is within bounds • BOUND r32, m32&m32: check if r32 is within bounds operation: if (LeftSRC < [RightSRC] or LeftSRC> [RightSRC+OperandSize/8]) then Interrupt 5;