Chapter 3-02
2015-10-10 00:32
281 查看
Please indicate the source if you want to reprint: http://blog.csdn.net/gaoxiangnumber1.
3.5 Arithmetic and Logical Operations
Each of the instruction classes shown has instructions for operating on byte, word, and double-word data except leal has no other size variants.
The operations are divided into four groups: load effective address, unary, binary, and shifts.
3.5.1 Load Effective Address
leal has the form of an instruction that reads from memory to a register, but it does not reference memory at all. It copies the effective address to the destination. This instruction can be used to generate pointers for later memory references.
For example, if register %edx contains value x, then the instruction “ leal 7(%edx,%edx,4), %eax” will set register %eax to 5x + 7.
The destination operand must be a register.
3.5.2 Unary and Binary Operations
Unary operand can be either a register or a memory location. For example, the instruction incl (%esp) causes the 4-byte element on the top of the stack to be incremented.
Binary operations: the second operand is used as both a source and a destination. The first operand can be either an immediate value, a register, or a memory location. The second can be either a register or a memory location. The two operands cannot both be memory locations.
3.5.3 Shift Operations
The shift amount is encoded as a single byte, because only shift amounts between 0 and 31 are possible, so only the low-order 5 bits of the shift amount are considered. The shift amount is given either as an immediate or in the single-byte register element %cl.
The destination operand of a shift operation can be either a register or a memory location.
3.5.4 Discussion
The assembly code instructions occur in a different order than in the C source code. Instructions 2 and 3 compute the expression z*48 by a combination of leal and shift instructions.
3.5.5 Special Arithmetic Operations
The imull instruction generates a 32-bit product from two 32-bit operands.
IA32 provides two different “one-operand” multiply instructions to compute the full 64-bit product of two 32-bit values—one for unsigned (mull), and one for two’s-complement (imull) multiplication. For both of these, one argument must be in register %eax, and the other is given as the instruction source operand. The product is then stored in registers %edx (high-order 32 bits) and %eax (low-order 32 bits). Although the name imull is used for two distinct multiplication operations, the assembler can tell which one is intended by counting the number of operands.
Suppose we have signed numbers x and y stored at positions 8 and 12 relative to %ebp, and we want to store their full 64-bit product as 8 bytes on top of the stack.
idivl takes as dividend the 64-bit quantity in registers %edx (high-order 32 bits) and %eax (low-order 32 bits). The divisor is given as the instruction operand. The instruction stores the quotient in register %eax and the remainder in register %edx.
Suppose we have signed numbers x and y stored at positions 8 and 12 relative to %ebp, and we want to store values x/y and x mod y on the stack.
The move instruction on line 1 and the arithmetic shift on line 3 have the combined effect of setting register %edx to either all zeros or all ones depending on the sign of x, while the move instruction on line 2 copies x into %eax. Thus, we have the combined registers %edx and %eax storing a 64-bit, sign-extended version of x.
cltd instruction sign extends %eax into %edx. With this instruction, the code sequence shown above becomes
Please indicate the source if you want to reprint: http://blog.csdn.net/gaoxiangnumber1.
3.5 Arithmetic and Logical Operations
Each of the instruction classes shown has instructions for operating on byte, word, and double-word data except leal has no other size variants.
The operations are divided into four groups: load effective address, unary, binary, and shifts.
3.5.1 Load Effective Address
leal has the form of an instruction that reads from memory to a register, but it does not reference memory at all. It copies the effective address to the destination. This instruction can be used to generate pointers for later memory references.
For example, if register %edx contains value x, then the instruction “ leal 7(%edx,%edx,4), %eax” will set register %eax to 5x + 7.
The destination operand must be a register.
3.5.2 Unary and Binary Operations
Unary operand can be either a register or a memory location. For example, the instruction incl (%esp) causes the 4-byte element on the top of the stack to be incremented.
Binary operations: the second operand is used as both a source and a destination. The first operand can be either an immediate value, a register, or a memory location. The second can be either a register or a memory location. The two operands cannot both be memory locations.
3.5.3 Shift Operations
The shift amount is encoded as a single byte, because only shift amounts between 0 and 31 are possible, so only the low-order 5 bits of the shift amount are considered. The shift amount is given either as an immediate or in the single-byte register element %cl.
The destination operand of a shift operation can be either a register or a memory location.
3.5.4 Discussion
The assembly code instructions occur in a different order than in the C source code. Instructions 2 and 3 compute the expression z*48 by a combination of leal and shift instructions.
3.5.5 Special Arithmetic Operations
The imull instruction generates a 32-bit product from two 32-bit operands.
IA32 provides two different “one-operand” multiply instructions to compute the full 64-bit product of two 32-bit values—one for unsigned (mull), and one for two’s-complement (imull) multiplication. For both of these, one argument must be in register %eax, and the other is given as the instruction source operand. The product is then stored in registers %edx (high-order 32 bits) and %eax (low-order 32 bits). Although the name imull is used for two distinct multiplication operations, the assembler can tell which one is intended by counting the number of operands.
Suppose we have signed numbers x and y stored at positions 8 and 12 relative to %ebp, and we want to store their full 64-bit product as 8 bytes on top of the stack.
idivl takes as dividend the 64-bit quantity in registers %edx (high-order 32 bits) and %eax (low-order 32 bits). The divisor is given as the instruction operand. The instruction stores the quotient in register %eax and the remainder in register %edx.
Suppose we have signed numbers x and y stored at positions 8 and 12 relative to %ebp, and we want to store values x/y and x mod y on the stack.
The move instruction on line 1 and the arithmetic shift on line 3 have the combined effect of setting register %edx to either all zeros or all ones depending on the sign of x, while the move instruction on line 2 copies x into %eax. Thus, we have the combined registers %edx and %eax storing a 64-bit, sign-extended version of x.
cltd instruction sign extends %eax into %edx. With this instruction, the code sequence shown above becomes
Please indicate the source if you want to reprint: http://blog.csdn.net/gaoxiangnumber1.
相关文章推荐
- Game of Life
- LeetCode #22 Generate Parentheses (M)
- 基于HTML5 Canvas实现工控2D叶轮旋转
- Randomized QuickSelect
- IIFE-js中(function(){…})()立即执行函数写法理解
- 文章标题
- Java中的String与常量池
- usaco Telecowmunication
- 黑马程序员——Java基础---多线程
- virtual
- 华南理工大学2013级计科一班操作系统实验
- Material Design 实现之Toolbar的应用及其菜单动画
- UE4的射线拾取
- js模块化历程
- 浏览器问题-FireFox-Adobe Flash 插件已崩溃解决方法
- UE4的MaterialInstance作用
- 实验一 DOS命令解释程序的编写
- Leetcode Factorial Trailing Zeroes
- Memcached 笔记与总结(5)Memcached 的普通哈希分布和一致性哈希分布
- Excel导入CSV文件中文乱码