Assembly language Wang Shuang Second Edition summary

Source: Internet
Author: User

Assembly language Wang Shuang Second Edition summary, so the content is 8086

Summary asssembly, compilation summary
Why
The initial programming language is to use a punch, 0 1 code, and then insert the card into the computer to run and then
Look at the output, this pure 01 binary code, writing difficult to debug the display of difficult running results look at the pain, like
A simple "Hello World", 11 characters, need to 11x8 binary, and then output, it is more troublesome, because
It's all binary, code. In order to develop the program more efficiently, assembly language was introduced to replace the input of the binary code.
WHAT:
Assembly language is mainly composed of pseudo-instruction and assembly instruction, and other symbols.
How: to know how assembly language works, and to present the graphical interface that we now see, such as your tapping
The keyboard then displays the corresponding characters on the screen, or the text on the page you are currently viewing is displayed.
If you want to know this, then learn the assembly language, he will help you understand what you want to know and help you better learning operation
System.

Bus

The external bus of the CPU is divided into three kinds, address bus data bus control bus
We know that everything in the computer is turned into a binary, in the high-low level, that is, at the hardware level of the computer all information
Transmission is dependent on the high and low level (0 means that the lower 1 stands for higher level), the CPU through the bus and memory, the bus is like a pipe to the CPU
and memory connection, CPU equivalent is a workstation, memory is a reservoir, bus is a water pipe, the station and the reservoir connected
Of course, because the workstation gets what it needs through the pipeline, the address bus is the location of the pipe, and the data bus is the inside
The flow of water, the control bus equivalent to the switch.


Register

Because of the transfer of data between CPU and memory and some other problems, we'll talk about it later, so there's a register that's the equivalent of
The global variables in the C language, except that the name is fixed, the corresponding variables are stored in the corresponding content, but here the
Registers are hardware: registers are and some memory inside the CPU, mainly used to store some data, to provide the use of the CPU,
Mainly divided into: segment register, offset register, general register, flag Register,
Segment Register: CS (instruction segment address) SS (segment address of stack) DS es
Offset Register: IP (instruction) SP (stack offset is stack top) di si bx these three registers default to DS BP default point to CS
General Register: AX DX CX DX is a 16-bit register, but requires eight-bit registers in order to be compatible with previous eight-bit CPUs
So all 16-bit registers can be divided into two 8-bit registers, the register name of the first bit unchanged, the second bit changed to:
L (Low) or H (hign) such as:al AH Cl ch so that we can get a 8-bit register.
Flag Register: is a 16-bit long special structure, as in C language inside Bit-field by the corresponding name instead,
Some of the tags are stored for some operations, such as our most common: 5+18 = 23,5+8=13 need to be in a bit, 5+8
Causes the value of the overflow register to change to 1 and then the 10-bit addition, plus the register value, 0+1+1=2, gets
23, a total of 16 marks for, can help me deal with many of the problems in the process of running, especially judge size.

Addressing mode

In front we talked about address bus, register, here we say, how the CPU through address bus, in memory to find the corresponding
Address, we know that the address range of the 16 address bus is 64KB, which is too small for our program, in order to increase
Address range, we use a segment + offset method to increase the range of addressing, as we write compositions, the article divided into different bits
Paragraphs, each of which has the first sentence, we can find the corresponding text only if we know the words in the paragraph.
The CPU can also increase the addressing range in this way, the actual address of 8086CPU is 20 bits, not our 16 bit so the actual
Address is required segment + offset, composed of 20-bit address, is actually very simple, is to move the segment address Left 4 bits, and then add the offset
The 4-bit constitutes the actual address of the 20-bit. Further, the memory is not the concept of paragraph, but the CPU itself divides the segment, through
Segment and offset to find the actual address, the actual situation may have a large program, you need a chunk of memory to manage, this time
The 16-bit address x16 is the start address of the segment, and the 16-bit offset address points to the address within the segment, although the offset is relative, but by
Segment and offset is the actual address can be found, so that our program processing speed will be faster actually I think this is the same as the array principle
Of course, we have to understand that this kind of thinking is possible. There are three ways to address the actual CPU, as defined in our C language:
Constant variable variable + constant variable + variable + constant
The same CPU addressing method can also be passed by this constant (direct address) variable (value stored through the Register) variable + constant
Such as:ax:[0] ax:[bx] ax:[bx+1] ax:[cx+bx+1) The address of the segment is stored in AX
This way, the address of the segment is found through the forged address in Ax, and then the actual address is found by the offset. The CPU is in this way the register
and memory pass data to each other, so as to achieve their own memory or read memory purposes.
The point here is that all the segment addresses are multiples of 16, and the offsets are all starting from 0.
Say here to mention, register conflict problem, use stack to save the register value, the register used in the program, before use
Register conflicts (common registers for multiple programs) can be resolved by recovering the value of the register when the value of the register is all in the stack, when exiting the subroutine
of the situation). Of course, you can pass multiple parameters at once through the stack, solve the problem of too many parameters, just as we use arrays in C language is the same
Truth, here can use stacks can also be arrays, in the CPU is memory.

Instructions

We all know that a program is composed of instructions, as we write C language, assembly language is the same, but assembly language
Consisting of assembly instructions and pseudo-directives, the assembly instructions are processed by the CPU, pseudo-instructions and compiled compiler processing, we write C language is by the C language compiler
The compiled link finally forms a binary executable, but since our CPU can recognize assembly language, assembly language can be executed directly in the CPU
So there is no need to compile, this is the assembly language is a great place, another great place is can through the address, operation we want to do everything
Things, do C language Java language and other languages can not do, this is why we learn it, but also its charm, when we use the tool to use the U-disk
System as a startup disk, it feels amazing, learn the assembly can slowly uncover these mysterious veil, you can also write the program by yourself
Making a U-disk Startup disk is not a problem, the key problem is that you need to understand the different CPU instructions. Of course, I think the CPU is updating quickly.
But don't worry, these are standard, but individual places are not the same, and will have a description oh. Having said so much, let's write a
The simplest ax = 1,ax = Ax +1 bar.
mov ax, 1; store ax register as 1 or 0001H, h means 16 binary
Add ax, 1; AX = ax + 1
Assembly directives are generally divided into: transfer instruction, jump instruction, contrast command
Transfer instruction: In fact, the same as the assignment in C language, the jump command is the same as go syntax through a tag, the judgment is if else ....
Transfer instructions: MOV push pop
Jump command: Jumping loop call ret Iret
Comparison instruction: CMP determines the size of two values in the presence of a flag register, can be judged by the command of the result
Conditional Jump instruction: Jcxz je jne ja jna jb jnb by literal means can be understood, jcxz equals JE is the judgment equals (if statement)
Jne is not equal to Ja is above higher than JB Blow is lower than the meaning, through CMP contrast and then use Judgment statement (equivalent if judgment statement)
Our if statements are implemented through these.
Data format: DB: (Byte type) DW (two bytes in a word) dd (double word, DWORD)
Operational data: The Add Sub mul div is: subtraction; Inc (self-increment similar to + +) dec (self-test)
Operation Flag Register: Popf PUSHF std CTD, etc., can view relevant information
Repeat: Rep db ' A ' is continuously allocating CX memory based on the value of the CX register but originally storing a,
Move operation: Movb movdw MOVDD Copy the data of byte word DWORD size one at a time from one address to another address according to the corresponding register
The stored address, as well as the offset, and automatically adds 1 to the value of the register that stores the offset

Internal interrupt

The so-called interruption is interrupting what the CPU is doing (when the CPU finishes executing instructions) and then letting the CPU handle what you commit.
I used to know that the BIOS is basic input and output base inputs and outputs but that's all, I know after I've finished the assembly,
is to use interrupts to invoke input and output methods that have been written in memory. The CPU uses a table to store the addresses of all hardware-provided interrupt methods,
The interrupt vector table stores the corresponding method in memory address, after the interrupt occurs, go to interrupt vector table to find the corresponding address, and then jump to the past
Execution completed, end of break, continue next instruction. Internal interrupts mainly refer to interrupts inside the CPU, and interrupt information from inside the CPU such as
Division error stepping execution into instruction execute int instruction, we also know that the CPU has a port can be used to connect external devices such as keyboard and mouse, then the keyboard
Input how to handle it, the keyboard input a character, then call the corresponding external interrupt, tell the CPU I have input information here, then the CPU will be processed, and then we
The characters you just typed are visible on the screen, and interrupts from external devices are external interrupts.

Interrupt principle

Interrupts the first to write your good interrupt program, put in a stable and secure memory, and then put the program's address offset into the interrupt table, this is the installation of the interrupt program
Process, and then is called according to your interrupt vector in the interrupt vector table subscript, the 8086CPU interrupt call is the keyword INT + interrupt vector subscript, it can be called.

Program Compile link Run debug

MASM link Debug These tools are packaged here:
Http://pan.baidu.com/s/1c2kEHXI
Http://pan.baidu.com/s/1qYQnHFm I wrote the exercises

Summarize

Looking at this book is basically playing a compilation of the basis, so that you have a clear understanding of the address, data, instructions, know how a program is running, the CPU through a variety of registers to distinguish
Who is the data, who is the instruction, let you understand this processing logic, process and the idea of dealing with problems, of course, I think after reading this, in going to see the operating system composition principles and other books, will
With less effort, because the Assembly will let you have a clear understanding of the bottom of the system, the bottom of the operating system to learn the upper layer will have a sense of epiphany, understand the development of the operating system
You will be in awe of him, because these are the best programmers of the crystallization of scientists, you use every day is a lot of cattle people write out, although I just use the computer
But I think it's like communicating with them, don't you feel like you're typing a character on the keyboard and you're going to show a character on the screen that's a magical thing? In this
We are accustomed to the hidden behind exactly how profound knowledge after several generations of development, I think as a good computer learning staff need to master. History of Learning Technology
The importance of this: The longer the history of traceability, the clearer the context of technology becomes.

Assembly language Wang Shuang Second Edition summary

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.