当前位置:网站首页>Arithmetic and logical operations
Arithmetic and logical operations
2022-04-23 05:26:00 【What’smean】
Write it at the front
Pictured here x86-64 Some integer and logical operations of . Most of these instructions have various variants with operands of different sizes .eg:ADD It consists of four addition instructions : addb、addw、addl and addq, They are byte addition 、 Word addition 、 Double word addition and four word addition ;lea Command variant ( Sort by size ):leaw 、leal、leaq, They are word addition 、 Double word addition and four word addition .
These operations are divided into four groups : Load valid address 、 Unitary operation 、 Binary operation and shift . One of the unary operations has an operand , Binary operations have two operands .
Load valid address leaq
leaq S,D
leaq: In form, it reads data from memory to register , In fact, the valid address is written to the destination operand .
eg:
c Language
long scale(long x,long y,long z){
long t = x +4* y + 12*Z;
return t;}
Compile time , The arithmetic operation of this function takes three leaq Instructions implement :
long scale(long x, long y,long z)
x in %rdi, y in %rsi,z in %rdx
scale:
leaq (%rdi,%rsi,4),%rax //x+4*y
leaq (%rdx, %rdx,2),%rdx //z +2*z =3*z
leaq (%rax,%rdx,4), %rax //(x+4*y)+4*(3*z)=x +4*y +12*z
ret
Unary and binary operations
Unitary operation
A unary operation has only one operand , This operand even if the source operand is the destination operand , The operand can be a register , It can also be a memory location .
eg:decq (%rsp) // Make stack top 8 Byte element -1 Be similar to C In language --
incq (%rsp) // Make stack top 8 Byte element +1 Be similar to C In language ++
Binary operation
Binary operations have two operands , The second operand is both the source operand and the destination operand . This grammar is similar to C Assignment operators in languages , for example x-=y.
The first operand source operand can be an immediate number 、 Register or memory location .
The operand of the second operand can be a register or a memory location . Be careful , When the second operand is a memory address , The processor must read the value from memory , Perform the operation , Then write the result back to memory .
Shift operation
Shift operation , The first item first gives the amount of shift , Then the second term gives the number to be shifted ; It is divided into arithmetic shift and logical shift .
The first shift can be an immediate number , Or put it in a single byte register %cl in .( notes : Only this specific register is allowed as an operand ).
The shift left command has two names :SAL and SHL. The effect is the same , Fill in... On the right 0.
The shift right command is different ,SAR Perform arithmetic shift ( Fill in the sign bit ), and SHR Perform logical shift ( Fill in the 0).
The destination operand of the shift operation can be a register or a memory location .
Learn from 《 Deep understanding of computer systems 》
版权声明
本文为[What’smean]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204220544124856.html
边栏推荐
- What are the reasons for the failure of digital transformation?
- Nécessité de précharger les cookies dans le sélénium
- Double click The jar package cannot run the solution
- Laravel database
- Laravel implements the Holy Grail model with template inheritance
- Basic use of sqlyog
- selenium预先加载cookie的必要性
- 可执行程序执行流程
- JSON.
- Kanban Quick Start Guide
猜你喜欢
Graphics. Fromimage reports an error "graphics object cannot be created from an image that has an indexed pixel..."
The 2021 IT industry project management survey report was released!
Traversal array, object parent-child communication props / $emit
Requirements for SQL server to retrieve SQL and user information
領域驅動模型DDD(三)——使用Saga管理事務
Redis的基本知识
CPT 104_TTL 09
Basic knowledge of redis
!!!!!!!!!!!!!!!!!!
我这位老程序员对时代危险和机遇的一点感悟?
随机推荐
Data management of basic operation of mairadb database
JS time format conversion
Log introduction and building web application
2021-11-01
selenium预先加载cookie的必要性
Anti crawler (0): are you still climbing naked with selenium? You're being watched! Crack webdriver anti crawler
史上最强egg框架的error处理机制
双击.jar包无法运行解决方法
Simple and basic use of switch and if
Redis的基本知识
WTL 自绘控件库 (CQsCheckComboxBox)
Getting started with varnish
我这位老程序员对时代危险和机遇的一点感悟?
WTL self drawn control library (cqscheckcomboxbox)
Knowledge of egg testing -- mock, Supertest, coffee
My old programmer's perception of the dangers and opportunities of the times?
Blender programmed terrain production
Use of uniapp native plug-ins
分支与循环语句
Escape characters \ splicing of data formats