Compilation Tutorial 4 - learn to solve problems

zhaozj2021-02-12  140

Compilation Tutorial 4 - Learn to solve the problem is really busy recently, it is C #, and it is Java, Robocode, and Win32ASM, it is busy, but the tutorial can't be delayed, after all, I wrote, have everyone gave me Encourage, very content. I don't know how you look like it? I don't understand, I don't have the relationship. I will experience it. I will see a lot of registers, signatures, and I still spend a lot of time.

Question.

First, the loop structure: 1 cycle instruction. Format: LOOP instruction label function: minimize the value of the register CX 1. Then it is determined that if CX <> 0, this transfer command to the label. Otherwise follow-up instructions continue. Equivalent to the following two instructions: DEC CX JNZ command label, so determine the number of cycles before the cycle, place in CX. Note: Do not change CX in the cyclic body, as for the reason I don't have to say more.

A program: 10 data, 12, 0, -6, 44, 69 statistics of the variable var, 0, 3, 51, 98, 69 statistical number of 0.

Now we have been analyzing, unlike previous key understanding statements. 10 data, each occupied one byte, then how do we implement data statistics? A cycle should be used. There are several questions: How to read data one by one? From a variable. How is the number of statistics after comparing? Will you repeat statistics? Solved this procedure this program will come out. The first question, for the readings of multiple data in a variable, the previous chapter, this is equivalent to an array, the most common method is to use BX to address. The second question, with a special register, statistics 0, the third problem, is actually very simple, the key is not to make this program and the algorithm of the bubbling method, this program is only looped for all the data. Yes.

OK, write planning, this is very important, just learning is best to write, especially compilation, decent register error. It's hard to find out.

Al: Save data BX read from variables: Indirect Addressing CX: Cyclic DL: Counters, statistics 0.

Data segment var DB 12, 0, -6, 44, -54, 0, 3, 51, 98, 69RESULT DB? DATA ENDS

Code Segment Assume CS: Code, DS: Data Start: MOV AX, DATA MOV DS, AX MOV BX, 0 MOV DL, 0 MOV CX, 10; The above, a bunch of MOV is to initialize Again: MOV Al, [BX VAR ] CMP Al, 0 JNZ Lab; if it is not equal to 0, turn Lab INC DL; if the number read is 0, DL Lab: Inc BX loop Again Mov Result, DL

MOV AH, 4CH INT 21HCODE Ends End START

IT IS A Easy Job, isn't? There is a problem here, because I said before, 10 data, each occupied one byte, why don't the loop count does not use CL or CH? This will not waste, don't Forgot, the default operation object of the loop instruction is CX and cannot be modified. When designing programs, pay more attention to the use of registers, beginners tend to use it to use it.

Below, a procedure for bubbling method, I don't explain, I don't understand.

Data Segment Var DB -1, -10, -100, 27H, 0AH, 47H N EQU $ -VAR Data Ends

Code Segment Assume CS: Code, DS: Data B Mov AX, Data MoV DS, AX MOV CX, N-1 MOV DX, 1

AG: Call Subp; Calling Subplit Inc DX Loop Ag Mov AH, 4CH INT 21h ****************; Subprint starts Subp Proc PUSH CX MOV CX, N SUB CX, DX MOV SI, 0 RECMP: MOV Al, Var [Si] CMP Al, Var [Si 1] Jle Noch Xchg Al, Var [Si 1] XCHG Al, Var [Si] Noch: incn; replan; return subp endp *********************************** CODE ENDS END B

It's a bit difficult, but I will see it will want to pass, consolidate, it will be deeper in the future.

2003 November 29th 1:33 SSSA2000

转载请注明原文地址:https://www.9cbs.com/read-6356.html

New Post(0)