Compilation blind post

xiaoxiao2021-03-06  81

Writing this post is just let the classmates who have not gone will enter the door. In fact, my assembly technology is very poor. Many I don't know, I know I know, I have almost haven't sent the original post. , Embarrassment! Beginning a topic, the basic statement of compilation is often used. Code Segmentassume CS: Codein DB? Define Variable INBEGIN: MOV AH 01INT 21h calls DOS interrupt, this interrupt is used to read a number ASCII from the keyboard, store the SUB AL in Al, 30 Put the ASCII code -30, store BLMOV BL Almov AH, 01 Read the contents of the second character INT 21HSUB AL, 30ADD Al, BL Al, the content MOV IN, Al put the content of Al, MOV AH in the variable in, 4CHINT 21h, these two statements are called DOS interrupt, role: downtime, generally used for program end code endsend begin explanation: MOV: Data Movement Directive, Format: MOV Target Operation Action Operation. Put the contents of the original operands in an immediate operand. This MOV is very learned. Next special explanation of this MOV directive, the master should not read it. SUB: subtraction instruction format: SUB D, SD-S and put the result in D, which is D = D-SADD: add D, S with SUB is similar, d = d s About assembly language format (Under DOS) Code Segment Assume ... Defines variables ....... Begin: ....... Code endsend beginsegment and Ends must be paired, segment and ends are segments, Format: Segment name segment [Positioning Type] [Combination Type] ['Category']. . . . . . . . . . The role of the paradisassusuMe directive is to tell the assembler, and the relevant segment register will be set to which segment address register in the memory, and the true load of the segment address value must also be assigned the executive command to the segment register. carry out. To talk about the definition variables: Num DW 12 defines a DW type called NUM, the value of 12ABC DB 10 defines a DB type variable named ABC, and the value is 10Worker DD 1123 defines a named Worker. DD type variable, value of 1123dB: byte variable DW: word variable, (a word is equal to 2 bytes) DD: double word variable DQ: 4 words DT: 10 words are tired, tomorrow, you need to go to mechanical design lesson Software foundation, can you see God, (practicing fitness systemic pain) Finally, there are two instructions in the interrupt call usually two instructions in combination: MOV AH, 01INT 21h wherein the second one is called system call, AH = 1 Note that the call is 1 function, this interrupt is to read a number ASCII from the keyboard, store it in Al, (note that I don't write wrong, stocking in Al) Let us start.

Last time I use an example to give everyone a blurred concept, maybe you don't fully understand the way to go to the dragon, this doesn't matter, there is a knowledge, I think the biggest obstacle to learning compilation is the teaching method in the book. Scholars, even if there is a foundation, it is a bit confused. Since it is to make a self-beginning, this time we start us to warm up, and the last time is almost =========== ============================================================================================================================================================================================================= ===========; For the purpose: save the multiple characters (note that multi-character) entered (note that multi-character) to the variable inbuf composed of several memory cells to end the carriage return. Code segmentassume cs: Code Due to the no declared variable, no setup segment start: MOV BX, 00hagain: MOV AH, 01H call interrupt, don't say it, type a character to use ASCII to Al (note is a character) INT 21HCMP Al, 0DH If the value in Al is 0dh, JZ Stop; then go to the STOP label, execute MOV [Inbuf BX], Al; put the data of the Al, the address of the INBUF BX; bx = bx 1JMP Again; jump to the Again label to accept the next character until the user carries Stop: MOV AH, 4CHINT 21HCODE endsend start ===================== ============================================================================================================================================================================================================= ========= Procedure is not long, beginners are most afraid of a long period of program, I am afraid, now I am afraid, people are lazy. For this program, talk about MOV, and branch procedures. Pay attention, background music is good, it is recommended to use my mystery, why? Because I am listening. MOV instruction format: MOV destination operand, original operand description: 1, immediately, segment register CS, can not be used as a destination operand;

The following instructions are erroneous MOV 4H, BLMOV CS, AXMOV [1000H], [BX]; [] Indicates that the number of addresses, the number of operands, and the target operand must be consistent, ie the number of single-by-thirds, or the same as The number of double-bytes, when there is an operand in the instruction, the other operand is considered as the same type. You can define a memory operand as byte or word type with Byte PTR or Word PTR. When the memory operand is a word type, the register or immediately high byte corresponds to its high address, the low-byte corresponds to the low address. Explain that byte PTR is to define an operand as a BYTE type, Word PTR is similar, what does the last sentence in the C language () What do you mean? We know, one word = two bytes, in the computer, the storage of the word is in bytes, everyone knows the stack to follow the principle of "advanced", so it is necessary to change the high and low. Example: One word type, value: 1234h, in memory location: | 34h | 34 is the low position of the variable. | ------- || 12H | 12 is the high of the variable. | ------ || | Good, let's see this sentence, "When the memory operand is the word type, the register or immediately high byte corresponds to its high address, the low byte corresponds to the low address." For example, MOV [2000H], AX is represented by: | Memory | | ---------- | | Free AX Low Al | ---------- || Save AX High AH | ---------- | The branch is if ... Then, Goto, etc. These, of course, in the compilation, no these statements first look at the CMP instruction, format: CMP destination, original Operating count: According to the size of the two operands, the status flag value is generated, the JC / JNC instruction format: JC / JNC label: JC has a carry, that is, CF = 1 JNC reverse (what is CF? I will explain specifically Computer registers, don't worry) JP / jnpjp: 1 number is the number of even numbers (pf = 1), JNP opposite JZ / JNZJZ: Turn (zf = 1) JNZ: Converse JL / JGEJL: Small than Turns (sf <> of or zf = 0) JGE is greater than or equal to turning (SF <= OF or ZF = 1). . . . . . . . There are still many oh, don't write, check your information, don't be too lazy. There is also one of the most important, JMP unconditional jump instructions, don't explain it? That example is to look at it, I realized how to jump.

Will there be harvested ~~ not addiction? Again, ============================================== =========================== Quality absolute value DSEG SEGMENTX DB 40HY DB 73HZ DB? DSEG Endssseg Segment Stack Set the stack segment DB 80H DUP (0) SSEG Endscseg Segmentassume DS: DSEG, SS: SSEG, CS: Is CSEG What did you think is different from previous? Oh, I realized Start: MOV AX, DSEGMOV DS, AXMOV AL, XCMP Al, Y; According to XY Generation Status Sign JL XL Sign Number, Jump Sub Al, Y Mov Z, Al Z = X-YXL: MOV BL, YSUB BL, Almov Z, BL Z = Y-Xok: MOV AH, 4CHINT 21HCSEG Endsend start ============================== =============================================== Ok, What should I have? I still want to talk about some addressing methods. The next chapter needs to tell the basic knowledge, avoid can't avoid it, but now, your understanding of the compilation should be a bit deep, and the compilation is not difficult, is it? If you have this feeling, then my purpose is also reached, and next, we explain the registers, and addressed. Do not speak. After studying the two tutorials, I should have a profound impact on the assembler? So can't teach blind posts, you can upgrade, but before upgrading, you should not help some things about some things. First, the CPU's internal registers: four 16-bit general-purpose registers: _____________________________ | __ah ________ | ____ al _________ | ax | __bh ________ | ____ bl _________ | bx | __ch ________ | ____ cl _________ | cx | __dh ________ | ____ dl _________ | dx where: In general, AX as multiplication and division The accumulator in the method, the BX can store the address, or the pointer register.

The CX can store the number of cycles, and the DX can store the I / O number. 4 is ah two, two of Al 4, therefore, is a 16-bit AX, so the remaining four 16-bit pointer register ______________________________ | bp base pointer | _____________________________ | sp stack pointer is used to make top of the stack pointer | _____________________________ | si source index register | ________________ sometimes used to make these two index devices, to store data and calculation result | DI destination register | _____________________________ 4 16-bit internal registers: ______________________________ | cs: code segment register | _____________________________ | ds: data segment register | _____________________________ | es: additional segment register | _____________________________ | ss: stack segment register | _____________________________ flag register: ____________________________ ip instruction pointer | ___________________________ | flagsh | flagsl | _____________ | _____________ | 16-bit flag status flag register Only 9 of the nine sign bits, 6 respective status flags, and 3 control flags. FH: ________________ | | | _____ | __ | __ | __ | fl: ___________________________ | sf | ZF | Air | AF | Air | PF | Air | CF | | __ | | __ | Each sign of specific signs I simply tell me, if you want to program it yourself, you have to look at the book cf: carry mark, carry / borrow, CF = 1 PF: parity mark When the low 8 bits of the command execution result contains even numbers 1, PF = 1, f otherwise 0 AF: the secondary input mark, the low-byte of the result of the decrease method, the low byte of the 5-digit / borrowed time AF = 1. ZF: 0 logo. When the calculation result is 0, the zf = 1 sf: symbol flag, the highest bit of his and computing results. The negative number is 1, the positive number is 1 of: overflow flag, the completion of the completion of the completion of 1 is 1 status flag, the following is the control mark: DF: direction flag, control data string operation instructions IF: Interrupt Allow flag TF: Tracking Sign, setting up for debugging, people who like cracking should pay special attention to this second, addressing method: this thing is not guilty, no way, understand it, I try to say clearly! 1, fixed addressing this way, hidden in the instruction, for example, DAA, the operands are hidden in Al 2, immediately address the constant, for example: MOV AX, 9 9 is immediate MOV AX 1234H 1234h is an immediate number, 3, register addressing, for example: MOV AX, CX execution AX = 9602H, CX = 2081H After execution AX = 2081H. 4. In this way, the memory is usually the code segment. The data segment, the stack segment, the storage unit in the additional segment, the address or expression of the memory cell given by the instruction. In general, the number of destination operands and the original operand cannot be the same as the memory operand.

Memory addressing is divided into five types: direct addressing: The valid address of the operand is given directly by the instruction, which is a constant or variable with square brackets. Physical address PA = 16 * (DS) offset address NN, for example: MOV Al, [1000h] transmits the content of the 1000H unit of the DS segment to Al, pay attention to the difference between square brackets and non-plug. MOV AX, [1000h] transmits the contents of the DS segment to AX, pay attention to the contents of AH, Al. In addition, don't ignore physical addresses, this is very important information, cracking or programming, you must take this thing. MOV Al, ES: [2000H] indicates that the contents of the ES segment is passed to Al, which is called the prefix. Register indirect addressing: Format: [BX, BP, Si or Di]. Address by the base register or the index register If BX, Si, DI is used in the instruction, using DS as a segment address PA = 16 * ( DS) (BX / Si / DI) For example: MOV Al, [BX] sets BX content to 1000 hours, then transmits content of the DS segment to Al If you use BP, use the SS address PA = 16 * (SS) (BP) This addressing method is generally used to operate a continuous memory unit for a one-dimensional array operation, change the value of the registers such as BX. It is a bit more complicated, paying attention, the base address: format: offset [BX or BP], for example: MOV Al, 80H [BP] set BP content = 2040h, the contents of the 20c0 unit of the stack segment Why is Al why? Because the 2040h 80H = 20c0h is not believed in the Windows Calculator in the Windows Calculator. In fact, this statement is equivalent to the effective address EA = (bx) / (bp) offset index address format: Offset [Si or Di] operand Is the address EA = (Si) / (dI) offset is similar to the above? Let's take an example of an operand: Mov AX, Array1 [Si] MOV Array2 [Di], is AX understand? Why can't Mov Array2 [DI] Array1 [Si]? Because the two operands cannot be variables. Don't worry, here I have not given physical address of these two ways, and I will give you a topic, it is easy, think about it! The base address address is actually the above two combination format: offset [BX / BP Si / Di] PA = 16 * DS (BX / BP Si / DI offset) or 16 * SS ( BX / BP SI / DI Offeter) Note that the BX and BP selection are different. The segment address will be different. The former uses DS, the latter uses SS, so there are so many headaches, what do you understand Just reply asked me, I was going to draw, I stole lazy. The beginner will slowly look, read more, don't think about it, you have a confidence! 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, and 69 statistics of the variable var. 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 Endscode Segmentassume CS: Code, DS: DataStart: Mov AX, Datamov DS, Axmov BX, 0MOV DL, 0MOV CX, 10 A bunch of MOVs is to initialize again: MOV Al, [BX VAR] CMP Al, 0 jnz Lab If not equal to 0, turn Labinc DL If the number of reads is 0, DL lab: Inc BXLOOP AGAINMOV Result, DLMOV AH, 4CHINT 21HCODE Endsend Startit Is A Easy Job, isn't? There is a problem, because I said before, 10 data, each occupied one byte, why is the loop count not CL or CH? This will not waste, don't forget, the default operation object of the loop command is CX, 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.

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

New Post(0)