当前位置:网站首页>Cool assembly tutorial - concise x86 assembly language tutorial (1)
Cool assembly tutorial - concise x86 assembly language tutorial (1)
2022-06-25 14:03:00 【Full stack programmer webmaster】
Hello everyone , I meet you again , I'm your friend, Quan Jun . The first ○ Chapter Write it at the front I don't want to exaggerate or belittle assembly language . But I want to say , Assembly language has changed 20 The history of the 20th century . Compared with the predecessors , Our generation of programmers are happy enough , Because we have all kinds of programming languages , We can operate the keyboard 、 Sit in front of the monitor , Even with a mouse 、 speech recognition . We can use the keyboard 、 Mouse to control “ personal computer ”, Instead of sharing a cumbersome relay with a group of people 、 Switch to operate the supercomputer . by comparison , Our predecessors had to write programs in machine language , They don't even have the simplest assembler to translate mnemonics into machine language , And we can choose the one we like from thousands of computer languages , And assembly , Although not a kind of “ Commonly used ” Of has “ Rapid prototyping ” The language of ability , But it is also one of the languages we can choose .
Each computer has its own assembly language —— There is no need to count on the portability of assembly language , Select assembly , It means choosing performance over portability or ease of debugging . This document describes x86 assembly language , After that “ assembly language ” The word" , If not, it means ia32 Upper x86 assembly language .
Assembly language is easy to learn , A language that is difficult to master . Recall the year , I learned assembly from the beginning to write the first runnable program , It's not enough 4 Hours ; But to this day , I still dare not say that I am proficient in it . Write fast 、 Efficient 、 And can make the processor “ Perform comfortably ” It's a very difficult thing to do , If you study in your spare time , Usually 2-3 It takes years to do . This textbook is not expected to teach you a lot of assembly language skills . For readers ,x86 assembly language ” Right here ”. However , Don't rigidly confine yourself to the content of this textbook , Because it can only tell you that the assembly language is “ Such a thing ”. Learn assembly language well , It depends more on one's creativity than on one's understanding , I can tell you what skills I know , But surely this is not enough . A person who has had an important impact on my programming career once said this to me :
Writing assembly language programs is not the hardest part of assembly language , Innovation is .
I think , I'm afraid those who would like to read this document won't ask me “ Why learn assembly language ” Questions like this ; however , I still want to say a few words : First , Assembly language is very useful , I personally advocate taking it as C Prerequisite courses in language , Because by learning assembly language , You can learn how to design data structures effectively , Let the computer process faster , And use less storage space ; meanwhile , Learning assembly language can make you familiar with the internal operating mechanism of the computer , also , Effectively improve debugging capability . In my personal experience , The difficulty of debugging an unstructured program , It is much more difficult than debugging a structured program , because “ structured ” It is to improve readability and debuggability at the expense of running efficiency , This is very necessary to complete the coding phase of general software engineering . However , In some places , such as , Hardware drivers 、 The bottom of the operating system , Or code that often needs to be executed in a program , These advantages of structured programming are sometimes obliterated by its inefficiency . in addition , If you want to really control your program , It is not enough to know only source code level debugging .
Impetuous people like to say , use C++ Writing programs is enough , Even said , He doesn't just master C++, And proficient in STL、MFC. I don't agree with this view , Mastering the above is what every programmer should do , However C++ It's just us ” Commonly used ” It's a language , It's not all about programming . Low level developers like to say , well ,C++ How powerful it is , It can do anything —— It's not true . Easy to maintain 、 debugging , These are indeed our goals , however , Writing programs can't just pursue this goal , Because our ultimate goal is to meet the design requirements , Not personal irrational ideals .
This textbook is suitable for readers who have already learned a structured programming language . Its content is based on my 1995 A handout written when telling others about assembly language . Of course , As we all hope , It includes features supported by the latest processors , And the corresponding contents . I assume that the reader already knows some basic concepts of programming , Because without these, you can't understand assembly language programming ; Besides , I hope the readers have a good foundation for programming , Because if you lack knowledge of structured programming , Writing assembly language programs can quickly break your structured programming habits , Greatly reduce the readability of the program 、 Maintainability , Eventually your program will be stuck in a pile of code that has to be discarded .
Basically , The goal of this document is to facilitate self-study as much as possible . however , It also has some requirements for you , Although not very high , But let me emphasize .
Learn assembly language , You need
Courage . Don't be afraid to touch the internal workings of those computers . knowledge . Understand the number system commonly used by computers , Especially binary 、 Hexadecimal 、 octal , And how the computer saves data . to open up . Accept the difference between assembly language and high-level language , Instead of accusing it of being hard to read . Experience . Requires a little programming experience in any other programming language . Mind .
Have a good time programming !
Chapter one Introduction to assembly language Let's start with something that doesn't have much to do with actual programming . Of course , If you are eager to see more substance , You can skip this chapter first .
that , I think there may be a problem that is very important for beginners , That's it :
What is assembly language ? Assembly language is a kind of coding language closest to the core of computer . Unlike any high-level language , Assembly language can almost completely correspond to machine language . Pretty good , We can write programs in machine language , But now except for those computers that don't have assemblers , Write more than... Directly in machine language 1000 People with more than one instruction can only be counted as those who are called by us “ saint ” The victims of . After all , Remember some short mnemonics 、 It is up to the machine to consider the trivial coordination process and check for errors , Than memorizing a large number of hexadecimal codes that change with the computer 、 It is much better to make mistakes without any hints . Skilled assembly language coders can even read the general meaning of assembly language directly from hexadecimal code . Of course , We have better tools —— Assembler and disassembler .
In short , Assembly language is a form of machine language that can be read by people , It's just easier to remember . As for macro assembly , Is an assembly language that contains macro support , This allows you to focus more on the program itself when programming , Instead of busy computing and rewriting code .
Assembly language is the programming language closest to computer hardware besides machine language . Because it is so close to computer hardware , therefore , It can maximize the performance of computer hardware . Programs written in assembly language are usually faster than high-level languages and C/C++ Much faster – Several times , Dozens of times , Even hundreds of times . Of course , interpretative language , Such as interpretive LISP, There is no JIT technology Java Running in the virtual machine Java wait , Its program speed can not be compared with that of assembly language program .
Never ignore the high speed of assembly language . In the actual application system , We tend to use assembly to completely rewrite some frequently called parts in order to achieve higher performance . Application assembly may not improve the stability of your program , But at least , If you are very careful , It also does not reduce stability ; meanwhile , It can greatly improve the running speed of the program . I strongly recommend that all software products end up Release Before the whole code Profile, And appropriately replace some high-level language code with assembly . At least , Knowledge of assembly language can tell you something useful , such as , How many registers do you have . Sometimes , Manual optimization is more effective than compiler optimization , and , You have complete control over the actual behavior of the program .
I think I'm wordy . All in all , Before we finish this chapter , I want to say , Don't rely on the compiler for optimization —— Be realistic , The best compiler can't always produce the best code .
I learned BASIC, Fortran and Pascal, It's about a For a containing 100 individual 32bit An array of integers for quick sorting , And the output of the applet . In fact, there are some slight differences between the machine code written by the assembler and the machine code written by the assembler attached to it in the debugger other , The former is bigger , But it may be more efficient , Because the assembler can put the code where it is suitable for the processor, this sentence assumes that the two programs are optimized to the same extent , A poorly written assembler and a well written C Program comparison , Assemblers are not necessarily faster .
Please look forward to the next chapter .
Publisher : Full stack programmer stack length , Reprint please indicate the source :https://javaforall.cn/151694.html Link to the original text :https://javaforall.cn
边栏推荐
- Rust, the best choice for programmers to start a business?
- Parabolic motion in unity 2D games
- Syntax 'trap'
- 'NVIDIA SMI' is not an internal or external command, nor is it a runnable program or batch file
- Why should programmers be softer?
- 电脑必须打开的设置
- Discuz copy today's headlines template /discuz news and information business GBK template
- 楼宇自动化专用BACnet网关BL103
- VGA display of de2-115 FPGA development board
- NVM installation and use tutorial
猜你喜欢

K-line diagram 24 classic diagrams (shadow)

Rust, the best choice for programmers to start a business?

Suanli & NFT trading platform f3 The exclusive NFT project of XYZ, hash eagle, will be grandly launched

Nr-arfcn and channel grid, synchronous grid and GSCN
![[proteus simulation] 51 MCU +ds1302+lcd1602 display](/img/02/9644415b72c330afa15060d81d4cbc.png)
[proteus simulation] 51 MCU +ds1302+lcd1602 display

k线图24种经典图解(影线篇)

Preventing overfitting of deep neural networks (mysteries of neural networks Part II)

DE2-115 FPGA开发板的VGA显示

程序员为什么要软一点?

Pourquoi les programmeurs devraient - ils être plus doux?
随机推荐
用NumPy实现神经网络(Mysteries of Neural Networks Part III)
楼宇自动化专用BACnet网关BL103
untiy强制刷新UI
sigmoid函数sigmoid求导
SSH secret free function for # scripting
Is it safe for Guosen Securities to open a stock account? Excuse me?
哈希表、哈希冲突
Deep parsing and implementation of redis stream advanced message queue [10000 words]
Is it unsafe to make new debts
mysql数据库压缩备份_Mysql备份压缩及恢复数据库方法总结
VGA display of de2-115 FPGA development board
Use of bind() in JS and handwritten bind()
NVM installation and use tutorial
JVM uses tools to analyze classic cases of OOM
使用KVM虚拟化部署EVE-NG
Gorm-- search you don't know
语法'陷阱'
Unity 2D游戏中的抛物运动
When the input tag type is number, the input of E, e, -, + is blocked
Rust,程序员创业的最佳选择?