Assembly Language Suite software production (2)

Source: Internet
Author: User

Section III Program merging

I have seen a variety of combinations, although not much, but at least hundred. The most trouble is of course the lack of complete planning, followed by a letter horse to the reins, a full flow of the account! Obviously the gate in the east, the program hard to the west, until the tour of the Grand View Garden, dark, just out of the East gate!
This program I collected a large stack, but for example, but the powerless. Reason without him, really impatient to copy again, see on a headache!
The most powerful function of the computer is to deal with the repetitive work, why does the general programmer deliberately jealous with the computer? Without saying anything else, it takes a few months of precious time to put the program into the computer, is it really worth it?
There is a program, a full of more than 40 pages, I only slightly adjusted, then reduced to 10 pages, processing speed is five times times faster. Why is it so far away? Very simple, some people do not like using the brain, over time, accustomed to natural, the brain gave birth to iron stainless! Nothing can be thought of except go through formalities.
To be a good programmer, the first condition is not lazy, the second condition to have the habit of analysis and observation, the third and most important, is to have the spirit of the pursuit of perfection. Programmers like artists, whether their own or someone else's program, should be repeated, and constantly pondering the improvement.
I have seen a woman sweeping the floor, and no matter where she is, she shall see no mess. This kind of talented person is worthy of respect, this kind of spirit is great, have nothing to do with her profession!
The program is not concise enough to write, there are three reasons, the first is the programmer incompetent, this program can be written to run, it is quite rare; the second reason is not to understand the skills, hard bridge hard horse, do not know what is efficiency, do not know how to achieve. The program you write is not understood, not to mention others? The third is the lack of professionalism, perfunctory, such people I despise the most.
At the beginning of the program, if you understand the task clearly, then analyze the factors and split the module. All the similar cases are merged into one place, and then replaced by variables, uniformly executed. This is originally a work, the situation mentioned above can not happen!
The question is, what happens when it does? I suggest the best rewrite, if you must change, you have to use the skills of the combination of procedures, condensed.
The purpose of the merger is to improve efficiency, and the method of merging is different depending on the situation, just like the disease in life, we must first find out the cause, or we cannot drug it. I try to explain briefly the following, with some examples of what I know.

I. Consolidation of processes:

To do a process merge, you first need to identify the following points:
1, first find the process similar, all moved to a pile, if not found, it is hopeless.
However, this program is too small, it is impossible to have a similar situation, or the writing is not messy, trust horse to the reins. There is a similar process, but there is no common principle, it is impossible to concentrate. Of course, some programs may not be condensed because of the amount of work and the details of the processing.

2, in a similar program, to find different instructions or processes, and if not, that is repeated, it is desirable to merge.

3, replace the different instructions or processes with variables, or put the entry of the various programs in the register.

4, the program in the application of the process, set the variables and the use of registers.

5, merging similar programs, and replacing them with different application variables.

The following example, a piece of a drawing program, changes the original title and will be dispersed in a number of different sections, as follows:
189: mask proc near
190: mov dx , 3c4h
191: mov al,2
192: out dx,al
193: mov dx,3c5h
194: MOV  al,pcolor
195: out dx,al
196: ret
197: MASK ENDP
...
380: mov dx,03ceh
381: mov al,3
382: out dx,al
383: mov  al,18h
384: inc dx
385: out dx,al
386: ret
...
490: mov dx,3ceh
491: mov al,3
492: out dx,al
493: mov dx , 3CFH
494: mov al,0h
495: out dx,al
496: ret
...
589: cross proc near
590: mov dx,3c4h
591: mov al,2
592:  Out dx,al
593: inc dx
594: mov al,0fh
595: out dx,al
596:  RET
597: CROSS ENDP
...

There are more than 10 such paragraphs, each of which seems to be slightly different and cannot be merged. However, careful analysis, it is obvious that the programmer training is not enough, a very regular program, the arrangement is very disordered, so that the point.

Let's first summarize the problem and decide how to merge. First, the above procedures should be unified as subroutines; second, the total variables are only four, of which two are transfer values, and two are output ports. The latter has a continuous relationship, equal to only one. Therefore, before calling this subroutine, you should call the shilling DX as the output port, and then load the variable into the ax, one at a time. This subroutine is as follows:
300:sub:
301:out Dx,al
302:inc DX
303:mov Al,ah
304:out Dx,al
305:ret
Such a short subroutine, there is no need, depending on the effectiveness of time and space depends. No matter how the finishing, is far better than the original.
Another kind of situation, more frightening, that is, in the keyboard input, with the flow way, one by one compare the input code, and then one by one respectively.
For example, in order to check the left, right, top, and bottom eight directions of a cursor key for a corresponding processing, the program actually writes:
100:pp1:mov ah,0
101:int 16H
102:CMP ax,4800h; ↑ Key
103:jne NEXT1
104:call Movdata; SET buffers
105:call SETDLT; SET INCREMENT
106:NXT01:
107:call Dotup
108:loop NXT01
109:call Xordot; SET NEW DOT
110:call xydisp;D ISP NEW xxx,yyy
111:JMP PP1
112:NEXT1:
113:CMP ax,5000h; ↓ Key
114:jne NEXT2
115:call Movdata; SET buffers
116:call SETDLT; SET INCREMENT
117:NXT02:
118:call Dotdown
119:loop NXT02
120:call Xordot; SET NEW DOT

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.