tailieunhanh - Lecture Computer organization and assembly language - Lecture 22: Arithmetic Instructions: Shift, Rotate, Multi and Division

In this lecture, students will be able to understand: In this lecture, students will be able to understand: Computer organization, data representation, integer arithmetic, binary representation, floating point representation, machine instruction characteristics, instruction cycles, types of operands, pentium and power PC data types, microporessor bus structure, address, data, control buses and registers. | CSC 221 Computer Organization and Assembly Language Lecture 22: Arithmetic Instructions: Shift, Rotate, Multi. and Division Lecture 21: Review ASSEMBLY IMPLEMENTATION OF: Bit Test Instruction Copies bit n from an operand into the Carry flag Syntax: BT bitBase, n Conditional LOOP Instructions LOOPZ and LOOPE LOOPZ/LOOPE destination Logic: ECX ECX – 1 if ECX > 0 and ZF=1, jump to destination LOOPNZ and LOOPNE LOOPZ/LOOPE destination Logic: ECX ECX – 1 if ECX > 0 and ZF=0, jump to destination Lecture 21: Review ASSEMBLY IMPLEMENTATION OF: Block Structures Block-Structured IF Statements Compound Expressions with AND Compound Expressions with OR WHILE Loops REPEAT Loops (cont.) Lecture Outline Shift and Rotate Instructions Logical Shifts and Arithmetic Shifts SHL and SHR Instruction SAL and SAR Instructions ROL and ROR Instruction RCL and RCR Instructions Signed Overflow SHLD/SHRD Instructions Shift and Rotate Applications Lecture Outline Multiplication and Division Instructions MUL . | CSC 221 Computer Organization and Assembly Language Lecture 22: Arithmetic Instructions: Shift, Rotate, Multi. and Division Lecture 21: Review ASSEMBLY IMPLEMENTATION OF: Bit Test Instruction Copies bit n from an operand into the Carry flag Syntax: BT bitBase, n Conditional LOOP Instructions LOOPZ and LOOPE LOOPZ/LOOPE destination Logic: ECX ECX – 1 if ECX > 0 and ZF=1, jump to destination LOOPNZ and LOOPNE LOOPZ/LOOPE destination Logic: ECX ECX – 1 if ECX > 0 and ZF=0, jump to destination Lecture 21: Review ASSEMBLY IMPLEMENTATION OF: Block Structures Block-Structured IF Statements Compound Expressions with AND Compound Expressions with OR WHILE Loops REPEAT Loops (cont.) Lecture Outline Shift and Rotate Instructions Logical Shifts and Arithmetic Shifts SHL and SHR Instruction SAL and SAR Instructions ROL and ROR Instruction RCL and RCR Instructions Signed Overflow SHLD/SHRD Instructions Shift and Rotate Applications Lecture Outline Multiplication and Division Instructions MUL Instruction IMUL Instruction DIV Instruction Signed Integer Division Implementing Arithmetic Expresisons Logical vs Arithmetic Shifts A logical shift fills the newly created bit position with zero: An arithmetic shift fills the newly created bit position with a copy of the number’s sign bit: SHL Instruction The SHL (shift left) instruction performs a logical left shift on the destination operand, filling the lowest bit with 0. Operand types for SHL: SHL reg,imm8 SHL mem,imm8 SHL reg,CL SHL mem,CL (Same for all shift and rotate instructions) Fast Multiplication mov dl,5 shl dl,1 Shifting left 1 bit multiplies a number by 2 mov dl,5 shl dl,2 ; DL = 20 Shifting left n bits multiplies the operand by 2n For example, 5 * 22 = 20 SHR Instruction The SHR (shift right) instruction performs a logical right shift on the destination operand. The highest bit position is filled with a zero. mov dl,80 shr dl,1 ; DL = 40 shr dl,2 ; DL = 10 Shifting right n bits divides the operand by 2n SAL and SAR .

crossorigin="anonymous">
Đã phát hiện trình chặn quảng cáo AdBlock
Trang web này phụ thuộc vào doanh thu từ số lần hiển thị quảng cáo để tồn tại. Vui lòng tắt trình chặn quảng cáo của bạn hoặc tạm dừng tính năng chặn quảng cáo cho trang web này.