Compilation Tutorial 2 by sssa2000

zhaozj2021-02-12  144

Compilation Tutorial 2 by sssa2000

There is a contradiction with my girlfriend, or the computer is good, you can let me be quiet.

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

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

The procedure is not long, the initiator is most afraid of a long period of procedure, I am also 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

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 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,

============================================================================================================================================================================================================= ======================= XY absolute value

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!

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

New Post(0)