Compilation Blind Post by SSSA2000

zhaozj2021-02-16  98

[Original] Compilation Blind Posts 1 by SSSA2000 Write this post purpose is just to let the classmates who have not gotten into the door, in fact, my assembly technology is very poor, and many I don't know, I know I know, I have to write, come so long. I have almost haven't sent original post, embarrassing!

Start the topic one, compile common basic statements

We don't talk from the statement, first look at an example. Code Segment Assume CS: Code In DB?; Defining Variable INBEGIN: MOV AH 01 INT 21H; call DOS interrupt, this interrupt is used to read a number ASCII from the keyboard, deposit SUB AL, 30; ASCII code - 30, deposit BL MOV BL, Al Mov AH, 01; read the contents of the second character INT 21H SUB Al, 30 Add Al, BL; Al; Al; Al; put the content of Al; MOV AH, 4CH INT 21H in IN; these two statements are calling DOS interrupts, effect: downtime, generally used for the end of the program Code Ends end begin

explain:

MOV: Data Movement Directive, Format: The number of MOV target operates. 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-S

Add: add D, S with SUB is similar, d = D S

About the format of assembly language, (DOS)

Code segment assume ... Define variables ....... Begin: ....... code ends end begin

Segment and Ends must be paired, Segment and Ends are segments, format: Segment name Segment [Positioning Type] [Combination Type] ['Category']. . . . . . . . . . Segment name ENDS

The role of Assume directives tells the assembler that the relevant segment register will be set to the address register of which segment in memory, and the true load of the segment address value must also be completed by assigning an execution instruction to the segment register.

To talk about a few examples of definition variables: NUM DW 12 defines a DW type called NUM, the value is 12 ABC DB 10 defines a DB-type variable called ABC, and the value is 10WORKER DD 1123 defines a named Worker. DD type variable, value is 1123

DB: byte variable DW: word variable, (a word equal to 2 bytes) DD: double word variable DQ: 4 word DT: 10 words

It's so tired, tomorrow, I have to go to the mechanical design class and software foundation. I can see God, (practicing fitness systemic pain) Finally, there are two instructions in the input and output in the usual assembly. Common depiction: MOV AH, 01 INT 21h, the second one is called system call, AH = 1 Description Call is the first function, this interrupt is to read a number ASCII from the keyboard, deposits in Al, (note that I don't write wrong, is in Al Ok, if you have any needs, tell me.

Compilation Tutorial 2 by sssa2000

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, you can.

I think that the biggest obstacle to learning compilation is that the teaching method in the book is not suitable for beginners. Even if there is a foundation, it is a bit confused. Since it is to start from the actual start, we will start our example warm up, and The last time is almost

============================================================================================================================================================================================================= =====================================================================================================================================================

OBJECTIV: To save the multi-character (note that multi-character) entered (note is multi-character) to the variable inbuf composed of several memory cells to end the carriage return.

Code segment

Assume cs: code; no data segment is required because there is no declaration

Start: MOV BX, 00h

Again: MOV AH, 01H; call the interrupt, don't say it, type a character to be ASCII to Al (note is a character)

Int 21h

CMP Al, 0DH; if the value in Al is 0DH,

JZ Stop; turn it to the STOP label

MOV [Inbuf BX], Al; puts Al's data to the address of Inbuf BX

Inc bx; bx = bx 1

JMP Again; jump to the Again Number to accept the next character until the user carries

Stop: MOV AH, 4CH

Int 21h

Code ends

End Start

============================================================================================================================================================================================================= ===================================================================================================================================================================================================== I am also 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

Explanation: 1. Immediately, the paragraph register CS cannot be used as a destination operation;

2. The original operands and destination operands cannot be the same as the number of memory operands. The following instructions are wrong

MOV 4H, BL

MOV CS, AX

MOV [1000H], [BX]; [] indicates the address

3, the number of original operands and destination operands must be consistent, the same as the number of single-by-thirds, or the same number of double-bytes, when there is a type of operand in the instruction, the other operand is considered as the same Types of. 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 the force defined by an operand as a BYTE type, Word PTR is similar, similar to C language ()

What does the last sentence 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: A word type, the value is: 1234h, in memory location:

| 34h | 34 is the low position of the variable.

| ------- |

| 12H | 12 is the high of the variable.

| --------

| | |

Ok, let's see this sentence. "When the memory opera is a word type, the register or the high-character high byte corresponds to its high address, the low-byte corresponds to the low address." For example,

MOV [2000H], AX

Representation:

| Memory |

| ----------

| 存 a 的 低 低

| ----------

| High AX of AX AH

| ----------

Branch program

It is if ... Then, Goto, etc. Of course, in the assembly, there is no such statement

Let's take a look at the CMP instruction.

Format: CMP destination, original operand

Role: According to the size relationship of the two operands, the status flag value is generated.

JC / JNC Directive

Format: JC / JNC label

Role: JC has a carry, that is, CF = 1 JNC reverse (what is CF? I will specifically explain the computer's register, don't worry) JP / JNP

The number of JP: 1 is even if the number is turned (pf = 1), the JNP is opposite

JZ / JNZ

JZ: Turn to zero, (zf = 1) JNZ: opposite

JL / JGE

JL: Small than turning (sf <> of or zf = 0) JGE is greater than or equal to turn (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 be harvested ~~

Not addiction? Go another process,

============================================================================================================================================================================================================= =====================================================================================================================================================

Seeking absolute value of X-Y

DSEG segment

X dB 40h

Y db 73h

Z DB?

DSEG Ends

SSEG segment stack; setup stack segment

DB 80H DUP (0)

SSEG Ends

CSEG segment

Assume DS: DSEG, SS: SSEG, CS: CSEG; Is it feeling different from previous? Oh, realize

Start:

MOV AX, DSEG

Mov Al, X

CMP AL, Y; Generate Status Sign according to X-Y

JL XL; Sign number is jumping

SUB Al, Y;

MOV Z, Al; Z = X-Y

XL: MOV BL, Y

SUB BL, Al

MOV Z, BL; Z = Y-X

OK:

MOV AH, 4CH

Int 21h

CSEG Ends

End Start

============================================================================================================================================================================================================= ===========================

Ok, should there be no problem? 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. Ok, Class Over! Compilation Tutorial 3-Upgrade BY SSSA2000 After the study of 2 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. AH is two 4 digits, Al is two 4 digits, so AX is 16 bits, and the rest is pushed

4 16-bit pointer register ______________________________ | bp base pointer | _____________________________ | sp stack pointer is used to make the top of the stack pointer | _____________________________ | si source index register | ________________ sometimes used to make these two index devices, store data And the results of the operation | DI target register | ____________________________

4 16-bit internal registers:

______________________________ | cs: code segment register | _____________________________ | ds: data segment register | _____________________________ | es: additional segment register | _____________________________ | ss: stack segment register | _____________________________

Sign Register:

____________________________ ip instruction pointer | ___________________________ | flagsh | flagsl | _____________ | _____________ | status flag of the flag register 16, only nine of which flags, each state flag 6, the three control flags.

FH: ________________ | of | DF | IF | TF | ___ | __ | __ | __ | __ |

FL: ___________________________ | sf | ZF | Empty | AF | Air | PF | Empty | CF | | __ | __ | _ | __ | _ |

Every sign of specific signs, I simply tell, if you want to program it, you have to look at the book CF: carry flag, carry / borrow, CF = 1 PF: parity, when the command execution results are 8 digits When there is an even number of 1, PF = 1, f otherwise 0 AF: Auxiliary carry flag, the low-byte of the result of the addition and subtraction method, the low byte of the 5-bit, and the borrowing position 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, the operand is hidden in the instruction, for example, DAA, the operands are hidden in Al

2. Immediately addressed to represent constants, for example: MOV AX, 9; 9 is the immediate MOV AX 1234H; 1234h is immediate,

3, register addressing, for example: MOV AX, CX Perform AX = 9602H, CX = 2081H After execution, AX = 2081H.

4, the memory addressing this mode, the operands are typically the data segments, stack segments, and the memory cells, or expressions given in the memory cells given outside the code segment. 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 operands are given by the instructions, 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 the BX, Si, DI used in the instruction is used as the 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.

I will be a bit complicated in the future, pay attention,

STS Address: Format: Offset [BX or BP] For example: MOV Al, 80H [BP] set BP content = 2040h, why is the content of the 20c0 unit of the stack section to 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 of the number of MOV Al, [80H BP] operands

Index Address Format: Offset [Si or Di] Operations 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

Ok, it's so much, it's a little headache. If you don't understand, I will reply, I have to draw, I stole it. The beginner will slowly look, read more, don't think about it, you have a confidence! Next chapter we speak circulating statements, ok, go to sleep, maybe it is to name tomorrow. 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, 69 Result 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 21H Code 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-13190.html

New Post(0)