Introduction to assembly language

Source: Internet
Author: User
Learn the knowledge you should know before compiling
1. What tools and procedures are needed for compiling and where to download.
At this stage, it is sufficient for the assembler to need only two procedures. Masm.exe,link.exe. The former is the compiler, the latter is the link program. In addition, to verify and debug the program, you need a program Debug.exe, which is provided by Windows itself.
After downloading both, put it in a directory (any directory can), considering that many commands need to be typed through the keyboard, so it is recommended that you do not put the file into a long file name directory, Chinese directory or a very deep directory. For example, you can build a "D:\Masm" directory, and recommend that the following programs are placed in this directory, hereafter called this directory as an assembly directory. 2. Learn what programming knowledge is needed for the compilation.
Without any knowledge of programming, learning this language equals impossible, so please give up the idea of learning. In general, you should know at least the following points:
* The logical structure of the program's operation is sequential (executed sequentially by the statement), and the branch structure (IF ...). THEN ... ELSE ...), loop structure (for ...). NEXT) Three kinds of structures.
*) know what a subroutine is and what is called.
* Compile the programmer's perspective. The programming requirements for different programming perspectives are not the same. Like deleting files:
>> user's perspective is to find the "Delete" button or menu, and then click.
>> Advanced Programmer's perspective is to know the deleted file and issue a delete command. These are implemented through the API.
The >> sinks Programmer's perspective is to get the file name to be deleted, locate the file location, and delete the interrupt command by calling.
>> the perspective of the operating system developer is when you receive the Delete command, locate the system root area, and then locate the subdirectory by the link in the root directory, until you find the file that you want to delete, and then modify the file name according to the rules for removing files from the operating system.       Like DOS, just change the first character to "?". According to the program statement equivalence point of view, a line of VB printing statements, with the Assembly to achieve about 120 more lines. Know the visual angle of assembly language to know, the road ahead is bumpy, no patience is not. It's not easy to do a complex operation with a few minutes of a few lines of program. 3. What is the use of the study of compilation?
The assembly was produced in the DOS era or earlier, and now it is the Windows age, so it may be regrettable to say: although there are cattle in the compilation of core-level programs, but we are almost useless, in addition to the necessary time to analyze the one or two program part of the code, nothing else to do. And not all assembly commands can be used under Windows. And the general pursuit of "fashionable" and learn the language, the final result is the loss of the wife and folding soldiers. So before you learn, you have to think about it. I advise those who learn to compile for the "hacker" to stop.
0th, Preliminary knowledge 1, an assembler process is how to compile.
1 First you need to find an editor that can be edited with any "plain text" editor. Like Notepad. Save it to the assembly directory later. The extension is ASM, such as Myfirst.asm. But it's recommended that you find a compiler that shows the current line. It's easy to make mistakes in the back row.
2 then enter the D:\Masm directory in DOS, enter "MASM myfirst.asm", if the error system will prompt the line position and error reason. 3 and then enter "link Myfirst.obj", you can see the current directory has a myfirst.exe program. 2. What is the difference between a macro compilation and a compilation?
The difference is that the former provides macros and the latter does not. The latter has not been found, so you can assume that there is no difference. 3, machine language, assembly language, high-level language of the relationship
The first computer uses the machine language, which is expressed directly in binary notation, through the direct input binary number, plug the circuit board and so on, this "programming" is very easy to make mistakes, each command is through the Search command table to achieve, since it is through the "look-up table" to achieve, which of course, can also let the computer to replace the human look-up table realized. So the assembly language is produced, so no matter how others define the machine, I think the two are equivalent. Later, people found that in assembly language to compile a function, a continuous piece of code are the same or similar, so consider using a language to replace this section of assembly language, so that the emergence of high-level language. Therefore, all high-level languages can be converted into assembly language, and so assembly language can be converted into machine language. Conversely, all machine languages can be converted into assembly language (because they are equivalent). But not so assembly language can be turned into high-level language. 4, the composition of the computer
Usually the computer is defined into five parts: the operator, the controller, the memory, the input system, the output system.
For simplicity's sake, we understand this: the operator + controller =CPU. Memory = RAM (not including the external storage, also does not include cache). Input system = keyboard (not including mouse), output system = Monitor (not including printer, plotter). 5, register and memory of the difference
Registers are in the CPU. Memory is in the memory bar. The former is about 100 times times faster than the latter. The following program requires each to specify either no memory data or a memory data with the participation of a register. (That is, there is no instruction that accesses only memory). 6, the assembly language count
Unlike the count in life, the count in the assembly begins at 0. For example, 16 counts are from the 0~15, not the 1~16 of life. This seems to be simple, true operation is not easy, do not believe to wait to see. 7, the issue of the system
    and the different place in life is the system. Remember the following common sense:
* The internal storage of the computer is binary.
* Our Assembly source program by default is in decimal. (Unless you specify the type)
* The debugger that we use debug defaults to hexadecimal. (cannot indicate other types)
16 of the 16 single-digit digits are: 0,1,2,3,4,5,6,7,8,9,a,b,c,d,e,f. 8, the conversion of the system
A simpler method is to look up the table method.
decimal hexadecimal binary
0 0 0000
1 1 0001
2 2 0010
3 3 0011
4 4 0100
5 5 0101
6 6 0110 7 7 0111
8 8 1000
9 9 1001
Ten A 1010
One B 1011
C 1100
D 1101
E 1110
F 1111

Well, combine 6,7,8 three. Let's count a "problem". When a group of data is displayed, each data occupies four locations, with a total of 16 per row. Q: Where is the hexadecimal 13 position (the first few lines, the first few columns).
The format is as follows: M m m n n o p p p ' NOTE: ABC is afraid to confuse with the above hex.
R R R S s t t u u you u
The first is to talk about basic knowledge
1, access to memory
Program in storage, access to memory is almost every program to do the operation, the computer to the memory address is linear, that is, a one-dimensional, such as 256M of memory, address should be from 0~ (256m-1), this address is called Physical address or absolute address.
1.1 Address representation
But from the point of view of compiling programmers, memory is two-dimensional, to illustrate an address, you need to give two values, just as you specify a point on the plane need to say (x,y) coordinates, the assembly Programmer's memory angle also requires two "coordinates", the former is called Segment Address (Segment), the latter is called the offset address ( Offset), which is called the logical address.
For example, "1234:3df5" is an address. "1F3F:" is not an address, because he only has a segment address, no offset address. Note that subsequent addresses are represented in hexadecimal.
1.2 Address Calculation
As mentioned earlier, the computer address is one-dimensional, the assembly programmer is two-dimensional, then how to convert the two. The latter to the former conversion method is, "segment address string" After a "0", and then add the offset address.
such as "1234:3df5" (16-plus subtraction operation See related information)
12340--After the string, add a 0.
3df5
-----
16135-Note that this string is still hexadecimal.
So, the address "1234:3df5" in the eyes of the assembler programmer is the physical address (computer addresses): 16135.
Knowing the transition from the latter to the former, then from the former to the latter.
"Don't know", why don't know, continue to look down.
1.3 In the end which address to know the address algorithm of 1.2, I found another problem:
How much is the physical address of "1000:6,135"? 10000+6135=16135.
The physical address of "1001:6,125". 10010+6125=16135.
......
So which one is right? The answer to the question is this: Suppose I let you click the "L" button now, I can tell you one or more of the following methods.       1 Click the "L" key, 2 click the fourth line of the keyboard tenth key; 3 Click the Fourth key in the tenth column; 4 Press the key on the right of "K"; 5 by standard fingering Click on the right ring finger. The above example means that there are many representations of the same address, in which case, depending on the actual use. But either way, as long as you can achieve the purpose. (In practice this problem is generally not bothered by this problem, but when beginners suddenly think impassability).
1.4 How much memory is available to access
Either the segment address or the offset address is four-bit hexadecimal (if four digits are not enough, the front is 0). In other words: a total of access to the address said: 0000:0000~ffff:ffff. A total of ffff0+ffff+1=10fff0 addresses. Which is less than 1M of space.
Remember the following conclusions:
* No matter how much your actual memory, we can only access less than 1M of space at the moment.
* In fact, even this 1M can not be used up. The upper 384K of the address can only be read and cannot be read, generally known as ROM.
* Low-end 640K can read and write. But this 640K low-end 100 more K also can't write casually, so DOS system use this area.
*) original 1024M of memory, assembler can only use more than 400 K. This memory is easily equivalent to the size of a normal document. But that's enough.
2, the use of debug
Remember the following two commands first: d command and Q command. The former is the display of memory content, the latter is the Exit Debug command.
------------------------below for copying other people's content----------------------
DEBUG. EXE program is a special debugging tool designed for analyzing, developing and developing assembly language program, which has many functions such as tracking program execution, observing intermediate running result, displaying and modifying register or storage unit contents. It can make the program designers or users touch the inside of the machine, so it can be said that it is the heart of 80x86cpu window, but also we learn assembly language must master Debugging tools.

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.