Fifth Section Program writing
Said a lot, before the real writing program, the use of instructions is equivalent to writing programs. Just before using the instructions, we must fully understand the reprehensible related issues. Otherwise, the application instructions as wishy-washy general, piling up a group can work the finished product, I personally do not think that can be called "writing Program", at best, just graffiti.
I. The arrangement of the temporary storage device
Because the register is not enough, it must be arranged in advance before it can be effectively applied.
A further example illustrates the factors that need to be arranged:
1, Glyph size: This item has two variables need to be arranged, one is the horizontal beginning, the final value; The other is the longitudinal beginning and end value. Because at the beginning of the design, I have taken into account the problem of limit value, will be limited to 256 points, just in the range of a character. So we can put the horizontal starting value in the Register BL, the final value in BH, while the longitudinal start value in the DL, the final value into DH.
2, stroke thickness: There are four variable values, placed in cl, and the CH is 0. (This is very important, in order to streamline and efficiency, it is best to have a register of 0)
3, codewords into: In the beginning of the device Si.
4, Glyph output: In the final register di, according to BX and DX value to obtain.
Second, the program specification
The fourth section of chapter II has been introduced in this Conlio.
Iii. Procedures and Instructions
Part---------Description of------program----
1:;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2:; function: Cangjie table code Drawing. ";" After, all are annotations.;
3:; input parameter: ds:si= codewords (1-2 yards), =0 for termination.;
4:; Bl=x1 bh=x2;
5:; Dl=y1 Dh=y2;
6:; cx= stroke thickness value.;
7:; output result: Dot matrix in Es:di.;
8:; Destroy the Register: all.;
9:;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
10:ccodin:; codewords input
11:LODSB; To draw a yard to make a drawing
12:mov Cl,al; Take weight value
13:inc AX; Adjust Code value
14:and Ax,001eh; 24 Valid double values
15:push BX; Reserved after use
16:push DX; Ditto
17:mov Si,ax; AX cannot be indirectly addressable
18:and cl,07h; Valid values
19:call Ccodtb[si]; Suppose Cs=ds
20:pop DX
21:pop BX
22:JMP Ccodin; The main process of the program
23:CCOD00:; Code for Yards
24:add sp,6; This program is a subroutine
25:ret; Code is 0 execution complete
26:CCOD06:; 06 for E,f
27:SHL cl,1; E,f Weight Value Double
28:CLFT02:; Left-pointing Horizontal
29:add BH,BL; 02 for input Code A,B
30:SHR bh,1; Midpoint value of BH from left
31:JMP CHOR00; HORizon Drawing Horizontal
32:CCOD08:; 08 for G,h
33:SHL cl,1
34:CLEF04:; 04 for C,d
35:add DH,DL
36:SHR dh,1; DH is midpoint value up
37:JMP CVER00; Vertical Draw Straight
38:CCOD0E:
39:SHL cl,1
40:CRGT0A:; Right pointing to Horizontal
41:add BL,BH; 0A for Code I,J
42:SHR bl,1; BL is midpoint value
43:JMP CHOR00
44:CCOD10:
45:SHL cl,1
46:CCOD0C:
47:add DL,DH
48:SHR dl,1; DL is midpoint value
49:JMP CVER00
50:CCOD16:
51:SHL cl,1
52:CCOD12:
53:JMP CHOR00
54:CCOD18:
55:SHL cl,1
56:CCOD14:
57:JMP CVER00
58:;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
59: The following is the module program of each code, the indirect addressable table;
60:;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
61:CCODTB DW CCOD00; End
62:DW CCOD02; Code a,b left transverse fine light
63:DW CCOD04; The code c,d on the straight and thin light
64:DW CCOD06; Code e,f left transverse heavy
65:DW CCOD08; Code g,h on straight and heavy
66:DW ccod0a; Code i,j right Transverse fine light
67:DW ccod0c; Code k,l under the straight light
68:DW ccod0e; Code M,n right Transverse heavy
69:DW CCOD10; Code o,p down Straight heavy
70:DW CCOD12; Code q,r long Transverse fine light
71:DW CCOD14; Code s,t long Straight fine Light
72:DW CCOD16; Code u,v long Transverse heavy
73:DW CCOD18; Code w,x long Straight heavy
The program is all over, the only horizontal and straight is not related to this topic, do not explain this. From this program, you can see that the original planning input code is not ideal, so that the need to add thickness everywhere, the reader may wish to study the improvement.
Program length of 88 characters, the common program has already been, this does not count.
In addition, the program repeats several instructions, there are many ways to streamline, but also to the reader to do.
As for the horizontal and straight subroutine CHOR00 and CVER00, the position of the distance also affects the way of writing, in this, and assume that within 128B, are short jump. Otherwise have to use their brains, try to omission.
Also, readers should note that there is no procedure for checking the error in this procedure because it is guaranteed to be correct when the code is processed. Generally, checking for errors is a necessary procedure.
The improvement of the method, Gu here a little guide, if encoded, four consecutive yards as from thin to coarse, and the position into six groups, is easier to remember, and the program can be reduced by 28 characters. This shows that there is still room for improvement as a result of the deficiencies in the data structure of such streamlined programmes.