"Assembly Language"--from the bottom of the contest--warm so know the new

Source: Internet
Author: User
Tags processing instruction

In school, most of the students may be the language of the introduction of the C language, but often more or less will learn the assembly language. However, at that time, we felt that the compilation was really too difficult, and the meaning seems to be small.

And now, after work, find some truth, the more basic, the more can reflect your uncommon. So, I opened this book again, to aftertaste the bitterness of the year.

First do some reading after the summary, this should also be able to quickly reflect the performance of how much knowledge gained!

What can the assembly language do? Second only to machine language?

Computer work is driven by a series of machine instructions, these instructions are a series of binary number 0101000110, corresponding to the high and low level of the computer, and these machine instructions are the machine language, which is the lowest, and the hardware one-to-do already.

It is clear that such machine language is anti-human. Only geniuses and lunatics have the power to control him.

So the assembly language produced. assembly language is to convert some difficult to remember 0100100 into a format that is easy to remember, so that people can understand a little bit. If the contents of the register BX sent to AX, the corresponding machine instruction is: 100001001110110000 (completely do not know what the thing, if you really want to scrutiny, then you have to see its circuit connected), and into the assembly instruction after: MOV ax, bx. Haha, is not easy to understand a lot. Therefore, I also summed up a truth, in fact, the so-called difficulties and simple, really just relative, no comparison will not hurt!

Back to the previous question, assembly language can do? This problem is a little low, the machine language can be done, the assembly is capable? But is the machine language so awesome? What can be done with so many high-tech machine languages now? This is nonsense, all languages go to the end, are machine language, there is no machine language to do things, it can be said that there is no assembly to do things, but I do not have enough, haha!

The Assembly has three main types of instructions: 1) assembly instruction (machine code mnemonic, and machine instruction one by one corresponds, if possible, in fact, as long as this thing you can operate all the computer hardware); 2) pseudo-instructions (no corresponding machine code, executed by the compiler, the computer does not execute, That is, the compiler is converted into a group or more of the machine code, the modern high-level language compiler is doing this thing); 3) Other symbols (such as +-*/, as in the second one, are recognized by the compiler)

Ii. what are the basic knowledge to be compiled? (I think it's more interesting than the language itself)

Memory, which acts second only to CPU,CPU, it carries on the memory.

Storage unit.

The CPU reads and writes to the memory, requires 3-step interaction: The address of the storage unit (address information), the selection of the device, the command to read or write (control information), the read or write data (data information).

Address bus, the number of address bus, determines the CPU can operate the maximum memory (this and some operating systems with a little bit of memory, it can also explain why some phones can only expand xxg memory);

Data bus, its width (quantity) determines the speed of the CPU and the outside world (the wider the data bus, the more data can be transmitted at one time, the faster the speed).

The control bus, the number of which determines the number of control mode of the external device.

Understanding the above is also a bit of understanding of the hardware, and a deep understanding of the role of real code!

Iii. What are the things that can be manipulated by the assembly? (This is not the same as writing code)

Register, this is the core of the entire assembly operation, most of the operation, is the operation of the Register.

For learning, we are more to understand the principle, textbooks are not the latest equipment to come out difficult for us.

For 8086CPU, there are 14 registers, namely: AX, BX, CX, DX, SI, DI, SP, BP, IP, CS, SS, DS, ES, PSW.

  Abcd-x, a general-purpose register that stores general data. However, in the assembler, CX has a special function for storing loops in the loop. The registers here are divided into high and low levels, H, L respectively. Example:

mov  One    ; send 11 into register ax mov 3       ; 3 fed into BL register Add 5       ; Add 3 to the value of the AX register

Segment register, note the concept of segment, the most fundamental source of the segment is the physical address of the memory unit given by the CPU, which is determined by the 8086CPU way (segment address x16+ offset address = Physical address). But the actual segment is a man-made concept, 10000H~100FFH can be a segment, 10000h~10080h can also be a segment.

   CS, IP is the most critical two registers, they indicate the current address to read the instruction, CS is the segment address, IP is the instruction pointer register. Csx16+ip is the instruction that the CPU is currently executing. In other words, to let the CPU execute what command, as long as the two registers to change the value, you can do it. (There is a sense of the emperor, haha), but the CPU can not provide MOV cs, 11h and other command operations, using JMP CS:IP to change the value, so jump to the command to execute.

  The DS Register is the segment address that is used to store data, such as to read a value in a piece of data, then the DS points to the address there, plus the offset address [...], you can read the data, such as:

mov bx, 1000h    ; The 1000h is fed into the BX register mov ds bx           ; The segment address points to BX value specified value, MOV ds, 1h is not legal mov al, [0]          ; The value of number No. 0 memory unit is fed into the AL register

CPU provides the stack mechanism, which is really a great invention, though it looks very simple.

  

into the stack process

The stack process

The language level shows that push, pop two commands, any moment, ss:sp all point to the top of the stack element. Push, when Sp=sp-2,pop, if there is a received register, the top value of the stack is first fed, then sp=sp+2, pointing to the following cell. What's the use of it? Of course it is useful, it can be used to temporarily save a variety of data, and then insert the function after the completion of the site recovery, in fact, most of the time it is used.

Iv. What is the real compilation? (In fact, here, personally feel a bit near the high-level language)

Everyone says that learning language starts with Hello World, but it doesn't seem to work in the Assembly, so it's too difficult to get started! Get started here:

AssumeCS:Codesg;associating a register with a code snippetCODESG SegmentStart:         movAX, 0123h;register-fed value        movBX, 0457hAddAX, BX;ax + BX Register value correlation        AddAX, Ax;calculate the square of Ax        movAx, 4c00hint21h;Program End returnCODESG endsend Start;Specifies that the program entry label is start

A segment prefix that can be read directly to a specified span of memory unit.

mov ds: [BX]     ; segment address in DS, offset address in bx, Ds:cs:ss: ... Wait for the segment prefix movcs:[bx]movss:[bx]moves:  [bx]movss:[0]movcs:[BX]

A sample location code address, how to locate the address of the code?

AssumeCS:Codesg;Associate a register with a code snippet whose start address is cs:[0]CODESG segment DW 0123h,0456h,0789h,0987hStart:         movBx0        AddAx0                AddCx4            S:  AddAxCS:[BX]AddBx2Loop SmovAx, 4c00hint21h codesg endsend start

SI, di register, its function and BX register similar, but these two registers can not be divided into two 8-bit registers, namely can not be like BX to be divided into BH bl, Si/di can't divide into SH SL. Si is the source variable address register, and DI is the destination variable address register. In the string processing instruction, SI is used as the implied source string address, default in DS, and di used as the implied destination string address, default in ES;

BP: is used in conjunction with the stack pointer sp, used as an SP calibration, only when looking for data in the stack and using individual addressing methods can be used for example, the stack of a lot of data or address, you would like to access the data or address through the SP, but the SP is to point to the top of the stack, Can not randomly change, this time you need to use BP, the value of the SP to BP, through the BP to find the data or address in the stack.

PSW register, Flag register.

Of (11-bit-overflow flag-overflow flag bit)

DF (10-bit-direction flag-directional sign bit)

IF (9-bit-interrupt flag-interrupt flag bit)

TF (8-bit-trap flag-trap flag bit)

  SF (7-bit-sign flag-minus sign bit)

  ZF (6-bit-zero flag-0-value flag bit)

  AF (4-bit-auxiliary CArray flag-auxiliary carry flag bit)

  PF (2-bit-parity flag-parity mark Bit)

  CF (0-bit-carry flag-carry flag bit)

  Use Popf. Popf the staging of the flag State.

Five, another level of function?

Interrupt. The use of interrupts allows the CPU to drop the current work, instead of processing the interrupted request, and after the processing is complete, continue back here to continue execution. The interruption of the function is very important AH!

Internal interrupts. The BIOS interrupts the full process routine.

int n can specify an interrupt number. The Interrupt vector table holds the entry for the handler that corresponds to the interrupt source. Use Iret to return the position before the break.

The interface between the CPU and the external device uses a port.

In Al, 20h; Reads a byte from a 20h port out of 20h, AL; Finalize a byte on port 20h

CMOS RAM chip.

External interrupts. Receive the arrival of the peripheral input at any time, that is done through the interrupt mechanism. The interruption is great!

There are many programming skills, but this article does not speak much of the language level. Because, the more skillful things, I think the modern language is enough, we do not need to spend too much time on the assembly.

Understanding the assembly is not about what you want to write, it's about making yourself more aware of what you're doing.

I think it's necessary to get a good understanding!

  

"Assembly Language"--from the bottom of the contest--warm so know the new

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.