Wang shuangzhi's learning focus on assembly language

Source: Internet
Author: User

Chapter 4 Basic Knowledge

1.1 machine language

Machine language is a collection of machine commands. The machine command is a command that can be correctly executed by a machine. The computer's machine commands are a column of binary numbers. The computer converts it into a column of high and low levels to drive the computer's electronic devices for computation.

Because of the hardware design and internal structure, different level pulses are needed for each microprocessor to work. Therefore, each Microprocessor has its own machine instruction set, that is, machine language.

Early programming uses machine languages. Programmers will use 0 and 1 numbers to compress the program code on the tape or card, 1 punch, 0 do not punch, and then input the program through the tape machine or card machine into the computer for calculation.

 

1.2 generation of assembly languages

The main body of an assembly language is assembly instructions. The difference between Assembly commands and machine commands lies in the expression of commands. Assembly commands are easy-to-remember writing formats for machine commands.

For example, machine command 1000100111011000 sends the content of register Bx to ax. The Assembly command is written

MoV ax, BX. This method is similar to the human language for easy reading and memory.

 

Registers are the devices that can store data in the CPU. a cpu has multiple registers. Ax is the code of one register, and BX is the code of another register. For more details, we will discuss it in future courses .)

 

Since then, programmers have used assembly commands to write source programs. However, computers can only read machine commands. How can computers execute programs written by programmers using assembly commands? At this time, we need a translation program that can convert Assembly commands into machine commands. Such programs are called compilers. The programmer writes the source program in assembly language, and then uses the assembly compiler to compile the program into a machine code, which is finally executed by the computer.

 

1.3 assembly language composition

Since the development of assembly language, there are three types of commands.

(1) Assembly command: the mnemonic of the machine code, with the corresponding machine code.

(2) pseudocommand: no corresponding machine code is executed by the compiler, but not by the computer.

(3) Other symbols, such as +,-, *,/, are recognized by the compiler and do not have the corresponding machine code.

The core of an assembly language is assembly instructions, which determine the characteristics of the assembly language.

 

1.4 memory

CPU is the core component of a computer. It controls the operation of the entire computer and performs computation. To make a CPU work, you must provide instructions and data to it. Commands and data are stored in the memory, which we usually call memory. In a PC, memory is second only to CPU. Without the memory, the CPU cannot work even if the performance is good. This is like a smart brain that cannot think without memory. The disk is different from the memory. If data or programs on the disk are not read into the memory, they cannot be used by the CPU. To use assembly language programming flexibly, we must first understand how the CPU reads information from the memory and writes information to the memory.

 

1.5 instructions and Data

Commands and data are application concepts. There is no difference between commands and data in the memory or disk. They are binary information. When the CPU is working, it regards some information as instructions and some information as data, which gives different meanings to the same information. Just like the chess piece of go, there is no difference in the chess box, and it has different meanings in comparison.

For example, if the binary information in the memory is 1000100111011000, a computer can treat it as 89d8h data or as an instruction mov ax or BX for execution.

1000100111011000-> 89d8h (data)
1000100111011000-> mov ax, Bx (Program)

 

1.7 CPU read/write to memory

As mentioned above, memory is divided into multiple storage units with sequential numbers starting from scratch. These numbers can be seen as the address of the storage unit in the memory. Like a street, every house has a street number.

To read data from memory, the CPU must first specify the address of the storage unit. That is to say, it must first determine the data in the storage unit to be read. Just like finding someone on a street, you must first determine which house he lives in.

In addition, in a microcomputer, there is not only a memory device. When reading and writing data, the CPU also specifies the device to be operated on, the operation to be performed, whether to read data from it or write data to it.

It can be seen that to read and write data, the CPU must interact with the following three types of information with the external device (the standard is the chip.

Address of the storage unit (address information );

Device selection, read or write commands (control information );

Read or write data (data information ).

So what does the CPU transmit the address, data, and control information to the memory chip? The information that electronic computers can process and transmit is electrical signals. Of course, electrical signals must be transmitted through wires. It is usually called a bus. A bus is a collection of wires physically. Based on different transmission information, the bus is logically divided into three categories: Address Bus, control bus and data bus.

The process in which the CPU reads data from Unit 3 (see Figure 1.3) is as follows.

(1) The CPU sends address information 3 through the address line.

(2) The CPU sends out a memory READ command through the control line, selects the memory chip, and notifies it that it will read data from it.

(3) memory sends data 8 in Unit 3 to the CPU through data lines.

 

The write operation is similar to the read operation. For example, write data 26 to Unit 3.

(1) The CPU sends address information 3 through the address line.

(2) The CPU sends a memory write command through the control line, selects the memory chip, and notifies it to write data to it.

(3) The CPU sends data 26 to the memory unit 3 through the data cable.

 

From the above we know how the CPU reads and writes data. However, how can we use a computer to read and write data?

 

To allow a computer or microprocessor to work, enter the level information (machine code) that can drive it to work ).

For 8086cpu, the following machine code can read data from Unit 3.

Machine code 101000000000001100000000

Meaning: reads data from Unit 3 and sends it to the Register ax

After receiving this machine code, the CPU completes the read and write operations described above.

Machine code is hard to remember and expressed by assembly instructions.

Machine code: 10100001 00000011 00000000

Corresponding Assembly commands: mov ax, [3]

Meaning: transfer the content of Unit 3 to ax

 

1.8 Address Bus

Now we know that the CPU uses the address bus to specify the memory unit. It can be seen how many different information can be transmitted on the address bus, and the CPU can address the number of storage units.

Assume that a CPU has 10 address buses. Let's take a look at its addressing. We know that in an electronic computer, a wire can transmit only two stable states, high or low. In binary format, 10 bytes of binary data can be transmitted from 1 wire or wires. How many different pieces of data can be represented by the 10-bit binary number? The 10th power of 2. The minimum is 0 and the maximum is 1023.

Figure 1.4 shows the binary information sent online from a CPU with 10 address lines to the memory at 11. Consider what content is transmitted on the address bus when the access address is a memory unit of 12, 13, and 14?

 

 

 

If a CPU has n address lines, it can be said that the address bus width of the CPU is N. Such a CPU can search for a maximum of 2 nth memory units.

 

1.9 Data Bus

Data transmission between CPU and memory or other devices is performed through the data bus. The width of the Data Bus determines the CPU and external data transmission speed. Eight data buses can transmit an eight-bit binary data (one byte) at a time ). 16 data buses can transmit two bytes at a time.

The data bus width of 8088cpu is 8, and that of 8086cpu is 16. Let's take a look at how they transmit data through the data bus when writing data to the memory 89d8h. Figure 1.5 shows data transmission on the 8088cpu data bus; Figure 1.6 shows data transmission on the 8086cpu data bus.

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

8086 has 16 data lines and can transmit 16-bit data at a time, so 89d8h can be transferred at a time; while 8088 only has 8 data lines and can only transmit 8-bit data at a time, therefore, when writing data to the memory for 89d8h, two data transfers are required.

1.10 control bus

The CPU controls external devices through the control bus. The control bus is a general term here, and the control bus is a set of different control lines. The number of control buses means that the CPU provides control over the number of external devices. Therefore, the width of the control bus determines the CPU's ability to control external devices.

The memory read or write commands mentioned above are integrated by several control lines. One of them is called the "read signal output" control line, which is used by the CPU to send read signals externally, the CPU outputs a low level to the control line, indicating that the data will be read. A control line called "Write signal output" transmits the write signal.

 

1.1 ~ Conclusion 1.10

(1) An assembly command is the mnemonic of a machine command, which corresponds to one machine command.

(2) Each CPU has its own assembly instruction set.

(3) information that can be directly used by the CPU is stored in the memory.

(4) There is no difference between commands and data in memory, and they are binary information.

(5) number of storage units in sequence from scratch.

(6) A storage unit can store 8 bits, that is, 8 bits.

(7) 1 byte = 8bit 1kb = 1024b 1 MB = 1024kb 1 GB = 1024 MB.

(8) Each CPU chip has many pins that are connected to the bus. You can also say that these pins lead to the bus. A cpu leads to three bus widths, which indicate the performance of the CPU in different aspects:

The address bus width determines the addressing capability of the CPU;

The width of the Data Bus determines the amount of data transferred at a time when the CPU and other devices transmit data;

The width of the control bus determines the control capability of the CPU on other devices in the system.

In the Assembly course, we introduced three types of buses from the functional perspective, and did not discuss the actual connection conditions.

 

Detection site 1.1

(1) If the addressing capability of one CPU is 8 KB, the address bus width is.

(2) 1 kb memory has a storage unit. Number of the storage unit from.

(3) 1 kb of memory can store a bit and a byte.

(4) 1 GB, 1 MB, and 1 kb are bytes.

(5) If the address bus widths of 8080, 8088, 80286, and 80386 are 16, 20, 24, and 32 respectively, their addressing capabilities are as follows: (KB), (MB), (MB), (GB ).

(6) The data bus widths of 8080, 8088, 8086, 80286, and 80386 are 8, 8, 16, 16, and 32, respectively. The data they can transmit at one time is: (B), (B ).

(7) read 1024 bytes of data from the memory. 8086 must be read at least, and 80386 must be read at least.

(8) In the memory, data and programs are stored in the form.

 

 

 

 

1.11 memory address space (Overview)

 

What is the memory address space? For example, if the address bus width of a CPU is 10, 1024 memory units can be addressable (one memory unit is one byte, so the address can be 1024b, that is, 1 kb ), the 1024 searchable memory units constitute the memory address space of the CPU. The following is an in-depth discussion. First, we need to introduce the basic knowledge of the two parts: the motherboard and the interface card.

 

1.12 main board

Each pc has a motherboard With core devices and some main devices connected through the bus (address bus, data bus, and control bus. These devices include CPU, memory, peripheral chipset, and expansion slot. The expansion slot is usually inserted with RAM memory and various interface cards.

 

1.13 Interface Card

In computer systems, all the devices that can be controlled by programs must be controlled by the CPU. The CPU cannot be directly controlled by external devices, such as monitors, speakers, and printers. Directly controlling these devices is the interface card that is inserted into the expansion slot. The expansion slot is connected to the CPU through the bus, so the interface card is also connected to the CPU through the bus. The CPU can directly control these interface cards to indirectly control the CPU's peripherals. Simply put, the CPU sends commands to the interface card through the bus, and the interface card controls peripherals Based on the CPU commands.

 

1.14 various memory chips

A pc is equipped with multiple memory chips which are physically independent and different devices. There are two types of read/write attributes: random memory (RAM) and read-only memory (ROM ). Random memory can be read and written, but it must be stored in a live state. The stored content is lost after shutdown. read-only memory can only read and cannot be written, but its content will not be lost after shutdown. These memories can be divided into the following categories in terms of functions and connections.

Random memory

It is used to store the vast majority of programs and data used by the CPU. The primary random memory is generally composed of two locations of RAM, which are mounted on the motherboard Ram and the ram inserted in the expansion slot.

Rom with BIOS (Basic Input/Output System, Basic Input/Output System)

The BIOS is a software system provided by the motherboard and various interface cards (such as video cards and network cards). It can be used to make the most basic input and output. Plug in the ROM that stores the corresponding bios on the motherboard and some interface cards. For example, the ROM on the motherboard stores the BIOS of the motherboard (usually called the system BIOS); the ROM on the video card stores the BIOS of the video card; if the NIC is installed with a Rom, then the BIOS of the NIC can be stored.

Ram on the Interface Card

Some interface cards need to temporarily store large amounts of input and output data and have Ram attached to them. The most typical is Ram on the display card, which is generally called memory. The display card outputs the stored data to the display at any time. In other words, we write the content to be displayed into the video memory and it will appear on the display.

Figure 1.7 shows the logical connection of various types of memory in the PC system.

Figure 1.7 logical connection of various types of memory in PC

 

1.15 memory address space

These memories are physically independent devices, but they are the same on the following two points.

A. They are connected to the CPU bus.

B. When the CPU reads or writes them, it sends out memory read/write commands through the control line.

That is to say, when the CPU controls them, it treats them as memory and regards them as a logical memory composed of several storage units, this logical memory is what we call the memory address space. In the course of compilation, we are faced with the memory address space.

Figure 1.8 shows how the CPU treats various types of memory in the system as a logical memory.

Figure 1.8 view various types of memory as a logical memory

In Figure 1.8, all physical memory is considered as a logical memory consisting of several storage units. Each physical memory occupies an address segment, that is, an address space. In this address space, the CPU reads and writes data in the corresponding physical memory.

Assume that the address segments of the memory address space in Figure 1.8 are allocated as follows.

Address 0 ~ 32 KB of 7fffh space is the address space of the primary random memory;

Address: 8000h ~ The 8 KB size of 9fffh is the memory space of the video address;

Address: a000h ~ The 24 KB space of ffffh is the address space of each Rom.

In this way, the CPU writes data to memory units with a memory address of h, and the data is written to the primary random memory. The CPU writes data to memory units with a memory address of H, this data is written into the video memory and then output to the display by the video card. The CPU writes data to the memory unit with the memory address c000h without any result, the content in the c000h unit will not be changed. The c000h unit is actually a unit in the ROM memory.

The size of the memory address space is limited by the width of the CPU address bus. The address bus width of 8086cpu is 20, which can transmit 20 power address information of 2 (ranging from 0 to 2 ^ 20-1 ). 2 ^ 20 memory units can be located, and the size of the memory address of the 8086pc is 1 MB. Similarly, if the address bus width of 80 Gb/s CPU is 32, the maximum memory address space is 4 GB.

When programming based on a computer hardware system, we must know the memory address space allocation in this system. Because when we want to read and write data in a certain type of memory, we must know the address of its first unit and the address of the last unit, only in this way can read and write operations be performed in the expected memory. For example, if you want to output a piece of information to the monitor, you must write the information to the video memory before the video card can output it to the monitor. To write data to the video memory, you must know the address of the video memory in the memory address space.

The memory address space distribution varies with computer systems. Figure 1.9 shows the basic information about the memory address space allocation for the 8086pc machine.

Figure 1.9 memory address space allocation for 8086pc

 

Figure 1.9 tells us that the address ranges from 0 ~ Reading data from memory units of 9ffff is actually reading data from the primary random memory ~ Bffff memory units write data, that is, write data to the video memory, the data will be output to the display card; we to the address c0000 ~ The Data Writing operation in the memory unit of fffff is invalid because it is equivalent to rewriting the content in the read-only memory.

 

Memory Address Space

The CPU is used to run the program. When programming in assembly language, we must consider the problem from the CPU point of view. For the CPU, all the storage units in the system are in a unified logical memory, and its capacity is limited by the CPU addressing capability. This logical memory is what we call the memory address space.

For beginners, this concept is abstract. In the subsequent courses, we will use some programming practices to increase our perceptual knowledge.

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.