Assembly language-Chapter 1 Wang Shuang

The production of assembly language

Early-rising programmers discovered the troubles caused by using machine language, which is difficult to distinguish and remember, which brought obstacles to the entire industry, so assembly language was born. Assembly language is a writing format in which machine instructions are easy to remember. The programmer writes the source program in assembly language, then uses the assembly compiler to compile it into machine code, which is finally executed by the computer.

The composition of assembly language

The assembly language has been developed so far, and it is composed of the following three types of instructions.

  • Assembly instruction: mnemonic of machine code, with corresponding machine code.
  • Pseudo-instruction: there is no corresponding machine code, it is executed by the compiler, and the computer does not execute it
  • Other symbols: such as +, -, *, /, etc., are recognized by the compiler, and there is no corresponding machine code.
    The core of assembly language is assembly instructions, which determine the characteristics of assembly language.

Memory

To make a CPU work, you must provide it with instructions and data. The instructions and data are stored in the memory.

Instructions and data

Instructions and data are application concepts. There is no difference between instructions and data in memory. They are all binary information.

Storage unit

The memory is divided into several units, and each storage unit is numbered sequentially starting from 0. For example, a storage unit has 128 storage units, and the number is from 0 to 127. As shown in the figure below, Insert picture description here
a storage unit can store a byte of numbers, that is, 8 binary bits, and there are several storage units in one storage, then they can store several bytes.

Storage unit conversion

1Bite (byte) = 8bite (bit) 1KB = 1024B 1MB = 1024KB 1GB = 1024MB 1TB = 1024GB

CPU reads and writes to the memory

As mentioned above, the memory is divided into multiple storage units. The storage units are numbered sequentially from zero. These numbers are the addresses of the storage units in the memory. A storage unit is like a room. To find a room, we need the room number. So the address is like the room number of the storage unit. We need the address of the storage unit to find the storage unit. The storage unit can store 8 binary numbers, just like there are 8 beds in a room.
When the CPU reads and writes data, in addition to the address of the storage unit, it also needs letters to operate during which period, which operation to perform, and whether to read data from it or write information.
If the CPU wants to read and write data, it must interact with the external period of the following three types of information.

  • The address of the storage unit (address information)
  • Device selection, read or write command (control information)
  • Data read or written (data information)

bus

The CPU transmits electrical signals through the bus to transmit address, data, and control information to the memory chip.
The bus is divided into three types according to logic:

  • Address bus
  • Data Bus
  • Control bus
    Take an example to illustrate how the CPU continues to read and write commands for data, as shown in the figure below.
    Insert picture description here
    1 The CPU transmits information through the address bus to specify the storage unit. For example, the above figure indicates the storage unit numbered 3.
    2 The CPU communicates through the control line. It is a read or write command that informs the storage unit to read the information in it, or to write information to the storage unit.
    3 The CPU uses data to transmit the information read from the storage unit or the information to be written to it.

Address bus

We know that the CPU specifies the memory unit through the address bus, so how many different information can be transmitted on the address bus, the CPU can address how many memory units. If a CPU has N address lines, it can be said that the width of the address bus of this CPU is N. Such a CPU can search for 2 N memory units at most.

Data Bus

The width of the data bus determines the data transfer element between the CPU and the outside world. 8 data buses can transmit 1 8-bit binary data (that is, one byte) at a time. By analogy, 16 address buses can transmit 2 bytes of data. The 8086CPU we learned has a data bus width of 16, which can transmit 2 bytes of data at a time. For example, if we want to write data 89D8H, if the address bus is 8-bit, so only one byte of data can be transmitted at a time, so it needs to be transmitted twice, the first transmission of low byte data D8, the second transmission of high byte Data 89. The CPU with a data bus width of 16 transmits 89D8H, which can be completed at one time.

Control bus

The CPU controls the external period through the control bus. The width of the control bus determines the CPU's ability to control external devices. How many control buses there are means how many kinds of control the CPU provides.

The way the CPU controls external devices

The CPU sends commands to the interface card through the bus, and the interface card controls the external devices to work according to the commands of the CPU.

Various types of memory chips

Computers are equipped with multiple memory chips, these chips are independent from the physical connection, different devices. From the read and write attributes are divided into two categories: random access memory (RAM) and read-only memory (ROM). The random access memory is readable and writable, but it must be stored on the power supply, and the stored information will be lost after a power failure. The read-only memory can only be read but not written, and its contents will not be lost after shutdown.
These memories are divided into the following categories in terms of function and connection

  • Random access memory is
    used to store the most sub-programs and data used by the CPU. The main random access memory is generally composed of RAM in two locations, the RAM installed on the motherboard and the RAM inserted in the expansion slot.
  • ROM
    BIOS equipped with BIOS (Basic Input/Output System) is a software system provided by the manufacturer, through which the hardware device can be used to perform the most basic input and output.
  • RAM on the
    interface card Some interface cards need to temporarily store large quantities of input and output data, and RAM is installed on the ride. The most typical is the RAM on the graphics card, generally called the video memory. We write the actual content into the video memory and it will appear on the monitor.

Memory address space

The memories mentioned above are physically independent devices, but they are mostly connected to the bus of the CPU, and the CPU can transmit control information to read and write operations on the memory through the control bus. So the CPU regards those memories as a total logical memory, and this memory is what we call the memory address space. The following figure shows how the CPU treats various types of memory in the system as a logical memory. Insert picture description here
All physical memory occupies an address segment in this logical memory. The CPU reads and writes data in this address space, in fact, it reads and writes data in the corresponding physical memory. The size of the memory address space is limited by the official address of the address bus. For example, if the 8086CPU's address bus width is 20, it can transmit 2 20 different messages, so 2 20 memory units can be located , and the 8086PC's memory address space is 1MB.
When we program based on a computer hardware system, we must know the memory address space allocation in this system, so as to ensure that the read and write operations are performed in the expected memory.

Guess you like

Origin blog.csdn.net/weixin_47617598/article/details/114852214