The Structured Design of Assembly Language and Its Application in Tetris

introduction

Assembly language is a machine-oriented programming language represented by mnemonics. The mnemonic makes the original machine language relatively intuitive, easy to understand, easy to use, and the assembly language has a one-to-one correspondence with the machine language, so it inherits the direct, fast and efficient characteristics of the machine language. The underlying language. However, the disadvantages of assembly language are also very obvious. For example, writing a large program requires consideration of many hardware memory allocations and the processing of interrupt programs. Otherwise, register conflicts are likely to occur, resulting in program crashes. In order to simplify the assembly process of assembly language, this paper proposes a structured assembly programming idea, and takes the Tetris game based on AT89C51 chip (the following discussion of assembly language for 51 single-chip system) as an example to show in 51 single-chip microcomputer. The advantages of assembly language structured writing.

1 Structured design ideas of assembly language

1.1 Variable definition

The declaration of variables is not required in assembly language, because assembly language operates directly on specific memory units, and each unit has a hexadecimal address code, so all variables can be artificially represented by the address code. However, assembly language provides EQU directives that can mark a specific memory space as a specific name, which makes it possible to define variables. The advantage of using the EQU directive is to separate the abstract physical memory into specific variable names, avoiding memory conflicts and increasing program readability.

1.2 sub-function design

The role of sub-functions in program structuring is that it simplifies the writing of main functions, making the programming of the program trunk clear, while some complex algorithms and functions are implemented in layer-by-layer sub-functions. However, if the assembly language is not handled properly during the call of the sub-function, it is extremely easy to cause stack errors, memory conflicts and other issues. This paper proposes an optimized sub-function design.

Design structure

Figure 1 Working register area temporary variable storage hierarchy

First, the four working register areas (00H~1FH) of the 51 MCU memory are used as the temporary variable storage area of ​​the sub-function, as shown in Figure 1; the other part is the user area (20H~7FH), which is used as the main function variable. With the stack area. Secondly, each group of the four working register areas is used as a temporary variable of the sub-function of the same level. The low-level sub-functions can only be called by the high-level sub-functions, and the sub-functions of the same level are not allowed to be nested together. All sub-functions need to declare the working register group number they use when writing to prevent conflicts. When the function is nested, the switching of the working register group is realized by switching between the two flag bits RS1 and RS0, so that the calling and nesting of the sub-function can be realized conveniently and reliably.

1.3 interrupt function design

Unlike sequential design programs, the 51 series microcontrollers also need to consider the design of the interrupt function. The interrupt of 51 MCU has external interrupt, timer interrupt, serial port interrupt and so on. The interrupt program functions when the interrupt source is triggered. In other words, the interrupt program may abort the main program at any time. If at this time, the interrupt function enjoys the same temporary variables as the main or subfunction in the main program, then when the interrupt occurs, these temporary variables are overwritten, resulting in a memory conflict. Therefore, the temporary variable system of the interrupt function should be different from the main program. The following are three options:

The first solution is to divide the working registers into two categories, one is used as a temporary variable for the main program function, and the other is used as a temporary variable for the interrupt function. In this scheme, the number of groups of working registers of the microcontroller limits the function design.

The second scheme allows the interrupt function to share the working register area with the subfunction of the main program, but at the cost of protecting and restoring the scene when the interrupt is called, that is, the interrupt function and its subfunctions must be used at the beginning and end of the interrupt function. The data of the register is pushed in and popped out to ensure the consistency of the temporary variables of the main program function before and after the interruption.

The third method is to avoid inserting a sub-function into the interrupt function by setting the flag variable. In the interrupt program, the main function is returned after modifying the flag variable according to the state. In the main function, the corresponding interrupt flag is judged to execute the corresponding subroutine. The advantage of this programming method is that the interrupt program is very simple and can be completed in a short period of time, reducing the possibility of interrupt errors; the disadvantage is that the response speed of the interrupt execution will be reduced because the main function has a certain interrupt flag. It is lagging behind the interrupt, and if the structure of the main function is a large loop type, then only a few interrupts can be processed in one loop (most often only once), this programming method is a function that requires high frequency interrupts. It is not suitable.

High Voltage SWA Armored Cable

High Voltage SWA Armored Cable, also known as Steel Wire Armored Cable, is a type of Power Cable used for transmitting electrical power at high voltage levels. It is designed to withstand high voltage levels and provide protection against mechanical damage, moisture, and other external factors.

The cable consists of a copper or aluminum conductor, which carries the electrical current, surrounded by layers of insulation materials such as XLPE (Cross-Linked Polyethylene) or PVC (Polyvinyl Chloride). These insulation layers provide electrical insulation and protect the conductor from external elements.

The SWA (Steel Wire Armored) layer is then applied over the insulation layers. It consists of galvanized steel wires wrapped around the cable, providing mechanical protection and additional strength. The steel wires also help to distribute any mechanical stress or tension evenly along the cable, preventing damage to the conductor.

The armored cable is further protected by an outer sheath, usually made of PVC or LSZH (Low Smoke Zero Halogen), which provides additional protection against moisture, chemicals, and UV radiation.

High Voltage SWA Armored Cable is commonly used in various applications, including power transmission and distribution systems, underground installations, industrial plants, and construction sites. It is suitable for both indoor and outdoor installations, offering reliable and safe power transmission in high voltage environments.

SWA Armored Copper Cable,Copper Conductor Cable,Steel Wire Armored Electric Cable,High Voltage SWA Electrical Armoured Cable,XLPE Underground Steel Wire Armored SWA Power Cable

Ruitian Cable CO.,LTD. , https://www.rtlinecable.com