In-depth understanding of computer systems (3.2)---Data formats, access information, and operand indicators

Source: Internet
Author: User

This article reprinted address : http://www.cnblogs.com/zuoxiaolong/p/computer14.html

Introduction

The content of this article can actually become the basis of assembly language, because the assembly language most of the time is in the operation of some of the things we normally do not see, so the purpose of this article is to make clear, assembly language is in the operation of something. Or, more precisely, the various assembly instructions are what objects are being manipulated.

assembly-Level objects

In the normal development process, the CPU processor state is hidden from the developer, we do not see the state of the various objects in the CPU. But in assembly language, we can clearly see the state of these objects, where the CPU mainly contains the following objects.

Program Counter (PC): Record the address of the next instruction.

Integer register File: A total of 8, you can store some address or integer data.

Condition Register: To save the state information of the arithmetic or logic instruction, the process control of the program can be realized.

Floating-point registers: stores floating-point numbers.

As can be seen, these are the CPU processor in the object, the previous chapter we wrote a simple C program, I believe that if you do not see the assembly code, you can not see in the program running process, the CPU of these objects are doing some what kind of operation, and in the storage of what kind of content.

Format of the data

In the previous chapter, almost all of the assembly instructions have a letter l, such as MOVL, Addl, Subl, PUSHL, and so on, the suffix of the L is actually the data format represented, indicating that we are manipulating 32-bit values.

The data format is constantly changing as the computer expands from 16 bits to 32 bits, so that the current 64-bit. But history will affect the direction of the future, so we are used to call 16 "word", while 32 is "double word", corresponding, 64 is "four words".

Let's take the IA32 architecture as an example to see what the suffix of each data format corresponds to.

The figure has been introduced relatively clear, LZ here is no longer nonsense. It is necessary to mention that a long long int does not support this data format in the IA32 schema, so it does not list its suffix. In addition, a long double is an extension type, typically represented by 12 bytes.

The above diagram is very simple to use, such as MOV instruction, it is a data transfer instruction, then MOVB represents the transmission of a byte of data, MOVW represents the transmission of two bytes of data, and MOVL represents the transmission of four bytes of data.

Register

Registers are very important objects in the CPU, in general, many temporary variables are stored here, as in the previous chapter of the temporary variable T, after optimization, T will no longer enter main memory, and only left in the register. This can improve the speed of the program, because the register speed is higher than main memory, but also between the register and main memory transfer data, is a very time-consuming thing.

The following is a register icon in a book, which is based on the IA32 architecture.

As you can see, for%ESP and%EBP registers, they are labeled as stack pointers and frame pointers, respectively. For the other six registers, most of the time they are the same, but there are some differences.

For example,%eax registers, which are often used to store the return value of a function. For%eax,%ECX,%edx, and%EBX, they can all be accessed in separate bytes. It is also necessary to mention that these eight registers can be accessed by double-byte.

In addition to the above differences, the usage practices of%eax,%ECX,%edx and%EBX,%esi, and%edi are somewhat different, as we will discuss in depth later. Here you can just get to know these eight immortals.

Operand indicator

Operand indicator This title is given in the book, but the LZ feels that the concept is not easy to understand, the operand indicator is actually refers to a value of the identification method, used to get involved in various operations of the operand.

There are three kinds of identification methods, one is the $ symbol followed by a standard C, such as an integer, such as $100,$0x11 and so on. The second is a register, which, when used as an operand, is the value of the register being taken. In addition, for registers, it is also possible to selectively manipulate 4, 2, 1 bytes, and do not necessarily have to operate 4 bytes. The last one, we are relatively familiar with, is memory or memory. When it is used as an operand, it calculates the value of the memory address and then goes to the address to take the corresponding value.

For the identification of the three types of operations, a table is given in the book, where the LZ paste.

The first column represents the type, while the first line refers to the immediate number, the second row refers to the register, and the rest is the memory. For the immediate number and register, it is better to understand, is to directly take the value or the value of the register. For memory, there are a number of situations, but we can also see that all of the above is actually the last special case. IMM (eb, ei, s) is the general form of memory value, for example, when Imm is 0 o'clock, it is the second-to-last method of value. For other forms, it can be extrapolated in the same way.

Because of the relative memory, it is more difficult to understand. So here LZ to give a simple example, for example, for 4 (%esp,%eax,4) This operand, it represents the memory address is 4+%esp+4*%eax the value of the memory area.

The operands are the majority of the instructions, so the above-mentioned methods, in the following articles we will often see, they will be a good friend of the ape friends.

Article Summary

This chapter only introduces some of the basics of the compilation, which is relatively not particularly difficult, but is the key to opening the door behind the mystery. So if any of the apes do not understand the content of this chapter too much, LZ hope you can start from the practice to understand the contents of this chapter. This can be combined with the previous chapter to look for data formats, operands, and registers in the assembly code given in the previous chapter, which should be very easy, since the assembly code in the previous chapter is filled with the contents of these three parts.

In-depth understanding of computer systems (3.2)---Data formats, access information, and operand indicators

Related Article

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.