当前位置:网站首页>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
边栏推荐
- Settings the PC must be turned on
- VGA display of de2-115 FPGA development board
- Typescript and go --- essence
- 使用调试工具调试博图TCP连接所遇到的问题
- Is it safe for tongdaxin to open a stock account
- shell 字符串变量
- Windows下MySQL的安装和删除
- NVM installation and use tutorial
- Dialogue: recommended system quick start route and summary of knowledge points
- 多台云服务器的 Kubernetes 集群搭建
猜你喜欢

Les neuf caractéristiques de la parole et les neuf temps en anglais

Experts' suggestions | 8 measures to accelerate your innovative career planning and growth

Why should programmers be softer?

Replace element - counter use of content (2)

完整详细的汇编实验报告

Getting started with numpy Library

JVM uses tools to analyze classic cases of OOM

Shell operator
Deep parsing and implementation of redis stream advanced message queue [10000 words]

Where can the brightness of win7 display screen be adjusted
随机推荐
Discriminative v.s.Generative
‘nvidia-smi‘ 不是内部或外部命令,也不是可运行的程序或批处理文件
JVM uses tools to analyze classic cases of OOM
BACnet gateway bl103 for building automation
What if the CPU temperature of Dell computer is too high
Shell string variable
Gorm-- search you don't know
Scope of ES6 variable
Cesium learning notes
请问通达信股票开户是安全的吗?
Settings the PC must be turned on
Golang project dependency management tool go vendor, go Mod
About reconnection of STM32 using lan8720a plug-in network cable
算力&NFT交易平台F3.xyz旗下独家权益NFT项目Hash Eagle将盛大发行
论文阅读:Graph Contrastive Learning with Augmentations
使用调试工具调试博图TCP连接所遇到的问题
Mise en place d'un Cluster kubernets avec plusieurs serveurs Cloud
Websocket -- reverse proxy to solve cross domain problems
NVM installation and use tutorial
启牛是正规的吗?股票开户安全吗?