Assembly language.

  Not Coban graduation, learn Java directly into the line, the recent plan to learn C language, understand some of the entry-level language, it looked a little something to get started, this one also pick up assembly language, here labeled the original address, respect the original.

  "Assembly language" - from the bottom of the contest - Reviewing the Old   https://www.cnblogs.com/yougewe/p/8011911.html .

  Assembler language definition Wikipedia: assembly language (assembly language) for a computer , a microprocessor , microcontroller, low-level language, or other programmable devices, also referred to as a symbolic language. In assembly language, using mnemonics instead of machine instructions of the operation code , the address with a label or a symbol instead of an instruction or operand addresses. In various devices, assembly language, machine language corresponding to a different set of instructions , into machine instructions through the assembly process. Specific assembly language and machine language instruction set specific one to one, not directly portable across different platforms.

First, the assembly language can do? Second only to machine language?

  Computer work is driven by a series of machine operating instructions that are a series of binary numbers 0101000110, corresponding to high and low levels of the computer, and the set of these machines is the machine language instructions, this is the bottom, and one pair of hardware one already.

  Obviously, such a machine language against humanity. Only a genius and a madman to have the ability to control him.

  So assembly language produced. 0,100,100 assembler language is to convert some are difficult to remember format for ease of memory, people can be understood a little point. As the contents of register ax bx sent, the corresponding machine instructions is: 100001001110110000 (do not know hell is, if you really want a closer look, then you have to view the circuit connected to), the assembler instruction becomes: mov ax, bx. Haha, it is not easy to understand more. So, I summed up a truth, in fact, the so-called difficulty with simple, really just the opposite, there is no comparison there would be no harm!

  Back to the previous question, assembly language can do? This question is a bit low, the machine language are able to do, the compilation are competent? However, machine language so Niubi it? Is it so much tech stuff machine language can be doing? This is nonsense, go to the last all languages ​​are machine language, no machine language can not do something, it can be said, no compilation can not do something, it just skill is not enough, ha ha!

  There are three types of the assembler instructions: 1) assembly instructions (machine code mnemonic, one correspondence with machine instructions, if you can, in fact, as long as this thing you can operate the computer all hardware); 2) directive (no corresponding machine code , performed by the compiler, the computer does not perform, that is converted into a set of compiler or machine code to the more modern high-level language compilers are more do children's); 3) other symbols (such as + - * /, and the second, as converted by the identified compiler)

Second, the assembler to write, to understand what are the basics? (I think this is more interesting than the language itself)

  A memory effect after the CPU, CPU calculates, for its memory.

  A storage unit, a relatively small memory or external memory of the memory block (since I am not sure is not the smallest block, ha, anyway, it is the default operation of the memory block in the case where it is or a multiple thereof).

  CPU memory read and write, the need for interaction Step 3: address (address information) of the storage unit is positioned; selection device, a read or write command (control information); data (information) read or write to the device.

  Address bus, the number of address bus determines the CPU memory maximum operational (this and some operating system does not take a lot of memory a bit like, also may explain why some of the largest mobile phone can expand the memory xxG);

  A data bus, its width (number) determines the transmission speed of the CPU and the outside world (the wider data bus, a larger amount of data can be transmitted, faster).

  Control bus, the number of which determines the amount of an external control mode.

  Understanding these can be considered some of the understanding of the hardware, and the code for a real deep understanding of the role it!

Third, the compilation of which can operate things? (This is also not the same to write code)

  Register, which is the whole core assembly operations, most of the operations are operations on the register.

  For the study, the more we understand the principle, there is no textbook out the latest equipment embarrass us.

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

  -X-ABCD , general purpose registers, a general data store. However, in assembly, the CX has a special function for storing the number of loop cycles. Register here has high and low points, H, L level, respectively. Example:

mov ax, 11; 11 into a register ax 
MOV bl, 3; 3 into the bl register 
add ax, 5; ax register plus the value 3

  Segment register Note that the concept of segments, the source of the most fundamental physical segment address of the memory cell embodiment of the decision given by the CPU, 8086CPU as (x16 + segment address = offset address physical address). However, the actual segment partitioning artificial concept, 10000H ~ 100FFH may be segments, 10000H ~ 10080H may be segments.

   CS, IP  is the most critical two registers, which indicates the address of the current instruction to be read, the CS is a segment address, IP is an instruction pointer register. CSx16 + IP is the current CPU instruction to be executed. Another simple words, let the CPU to execute any order, as long as the change in the value of these two registers can be done. (There is a feeling emperor, ha ha), but the CPU can not provide mov cs, 11h commands operate, jmp cs: ip change value, so jump to the command want to perform.

  DS  register is a segment address for storing data, such as to read a certain data value, then we must first point where the DS address, plus the offset address [...], data reading can be the ( ES as an additional segment register DS consistent with the function, in the case of too many segments, as the case may be can be selected), such as:

mov bx, 1000h; 1000h into the register bx 
mov ds bx; segment address points to the specified value bx, mov ds, 1h is not legal 
mov al, [0]; send the value of the memory cell 0 the register al

  SS, SP, BP  is associated stack register. Stack mechanism provided by the CPU, this is really a great invention, although apparently simple.

  

  Drawing process

  Stack Process

  In the language level is manifested, push, pop two commands at any time, SS: SP point to the top of the stack. When push, SP = SP-2, when the pop, if the received value into register the first stack, and SP = SP + 2, the following points to a cell. This is what use is it? Yes, of course, it can be used to temporarily store various data, and then insert the function execution is completed, site restoration, in fact, most of the time is so useful.

Fourth, the real compilation of what? (In fact, here, I have been personally feel a little close to the high-level language)

  Everyone says hello world from learning the language is beginning, but it seems not work in the assembly here, which should be too difficult, how can it Started! Getting started is as follows:

Copy the code
assume cs: codesg; register associated with the snippet 

codesg segment 
    Start: 
        mov ax, 0123H; value into the register 
        mov BX, 0457h 
        the Add ax, BX; ax + BX register value adding 
        add ax, ax; ax squared operator 
    
    mov AX, 4c00h 
    int 21H; end of program returns 

codesg ends 
end start; entry label as specified program start
Copy the code

   Segment Prefix, may be directly specified in a span of memory cells to read.

Copy the code
mov ax, ds: [bx] ; ds segment address, the offset address in bx, ds: cs: ss: ... as the segment prefix 
MOV AX, CS: [bx] 
MOV AX, SS: [bx ] 
MOV AX, ES: [BX] 
MOV AX, SS: [0] 
MOV AX, CS: [0]
Copy the code

  Positioning a sample code address, how to locate the code memory address (I feel able to tell the location of a data in memory is a cool thing, definitely enough you loaded to force)?

Copy the code
assume cs: codesg; associated with the code segment register, which is the start address cs: [0], subsequent addresses only need to know derive subtraction code you want to know the memory address 

codesg segment 
    DW 0123H, 0456h, 0789h, 0987h 
    Start: 
        MOV BX, 0 
        the Add AX, 0         
        the Add CX,. 4 
        
    S: the Add AX, CS: [BX] 
        the Add BX, 2 
        Loop S 
    
    MOV AX, 4c00h 
    int 21H     

codesg ends 
End Start
Copy the code

 

  SI, DI  register, it functions similar to the BX register, but these registers can not be split into two 8-bit registers, i.e., can not be divided into like BX as BH BL, SI / DI can not be divided into SH SL. A source index register SI, DI is the object of the index register. In the processing instruction string, as implied by the SI source address of the string, the default in DS; the DI string object is used as an implicit address, by default in the ES; at this time can not be mixed.

  BP : and SP are used in combination, used as a calibration SP, only looking at the stack of data and the use of individual addressing when they could be used for example, the stack pressed into a lot of data or address, you must want to access the data or address by SP, SP but to point to the top of the stack, it can not be lightly changed, this time you will need to use the BP, SP pass value to BP, to find data by BP or the stack address.

  PSW  register, a flag register for storing various operation status flags, the type of operation with corresponding trade-offs to obtain desired results relevant. For example, the machine is not negative, just sign. FIG lower blank flag bit is not used, may be from another perspective, the flag is not much, in essence.

  OF (11-bit -overflow flag- overflow flag)

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

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

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

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

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

  AF (4 bits -auxiliary carray flag- auxiliary carry flag)

  PF (2 bits -parity flag- parity flag)

  CF (0 bits -carry flag- carry flag)

  Use pushf, popf be staging flag state.

Fifth, another level of functionality? (Genesis function)

  Interrupted. Use interrupt, the CPU may be able to put down the current work, turn to handle requests interrupt processing is completed, continue to return here to continue. Interrupt functions important ah!

  Within interrupt. BIOS interrupts the whole routine.

  int n can be specified interrupt number. Save interrupt source interrupt processing program corresponding to the vector table entry. Use iret return to the position before the interruption.

  Communication between the CPU and the port using an external device.

in al, 20h; 20h from the port reads a byte 
out 20h, al; to finalize a byte port 20h

  CMOS RAM chip.

  External interrupt. Always ready to receive peripheral input arrives, that is done by interrupting mechanism. Interruption is great!

 

  Assembler programming skills are still better, but this paper does not speak the language level of many things. Because of the more tricky things, I think the modern language has more than enough, we did not need to spend too much effort to go up in the assembly.

  Learn compilation, I do not want to write anything fast hardware features, but to make themselves more clearly understand what they are doing things.

  I feel the need to try to understand!

Guess you like

Origin www.cnblogs.com/JohanChan/p/11736725.html