[Reserved] CPU instructions basic concept

xiaoxiao2021-03-05  36

The most common instructions of the CPU are set values, such as setting a value of a buffer, a number of addresses. The following example demonstrates how to set the value of the buffer AX to 9: First execute Debug, enter the instructions of Chinese MOV AX, 9 at address 100H: C: /> Debug-a1001358: 0100 MOV AX, 91358: 0103 - Debug R instructions show the value of "Rapture": -RAX = 0000 bx = 0000 cx = 0000 dx = 0000 sp = ffee bp = 0000 Si = 0000 di = 0000ds = 1358 ES = 1358 ss = 1358 cs = 1358 IP = 0100 NV UP EI PL NZ NA PO NC1358: 0100 B80900 MOV AX, 0009 Pay attention to the value of IP, if you find it not 100 before executing the instruction, then play RIP, then play 100, set IP to 100 . With T command, execute a CPU instruction there in address 100H: -Tax = 0009 bx = 0000 cx = 0000 dx = 0000 sp = ffee bp = 0000 Si = 0000 di = 0000ds = 1358 ES = 1358 ss = 1358 cs = 1358 IP = 0103 NV UP EI PL NZ NA PO NC1358: 0103 0000 ADD [BX Si], Al DS: 0000 = CD- After performing MOV AX, 9 instructions, the value of the buffer AX becomes 0009. When jumping to the CPU execution instruction, it is performed by one, in fact, the CPU also has some instructions that "jump" (JUMP), can jump to a memory address, execute the instructions. -A1001358: 0100 JMP 1051358: 0105 MOV AX, 91358: 0105 MOV AX, 11358: 0108-JMP is the "jumping" instruction, JMP 105 means that the memory address 105, where the instruction is MOV AX, 1 . -RAX = 0000 bx = 0000 cx = 0000 dx = 0000 sp = ffee bp = 0000 Si = 0000 di = 0000DS = 1358 ES = 1358 ss = 1358 cs = 1358 IP = 0100 NV Up EI PL NZ NA PO NA PO NC1358: 0100 EB03 JMP 0105-TAX = 0000 bx = 0000 cx = 0000 dx = 0000 sp = ffee bp = 0000 si = 0000 di = 0000DS = 1358 ES = 1358 ss = 1358 cs = 1358 IP = 0105 NV UP EI PL NZ NA PO NC1358: 0105 B80100 MOV AX, 0001 - The result skips the address 102 The MOV AX, 9 instructions.

Pay attention to the JMP 105 machine code, you will find EB 03, what is the 03 here? Why jump to address 105, mechanical code 郄 is 03, do the two do not have a relationship? In fact, 105 and 03 are related, 03 here is actually equal to 105 minus 102, and 102 is just the address of the next instruction of JMP 105. Simply, EB 03 can imagine "3 addresses before jump", when you play JMP 105 instructions, DEBUG calculates how much the address of the address 105 and the JMP 105 instruction, then translate JMP 105 into EB 03 machine code . The "jump" instruction before the condition is unconditionally jumped, ie, one of the execution that instruction will jump. This section describes some "conditional jump", that is, if you meet a certain condition, you will not jump, and you will not be jumped, continue to execute the next instruction. -A1001358: 0100 MOV AX, 91358: 0103 CMP AX, 91358: 0106 JZ 1001358: 0108 MOV AX, 11358: 010B - That CMP AX, 9 instructions in address 103, meaning "Compare AX's value and 9", JZ 100 indicates "If you are equal to zero, you jump to 100" "Jump to 100 if Zero", why is it clear about 9 comparison, is it close to zero? In fact, you can imagine "to minimize the value of the AX 9, if it is equal to zero jump". Therefore, the meaning of these two instructions is actually "if the AX is equal to 9, it will continue to perform the next instruction." -RAX = 0000 bx = 0000 cx = 0000 DX = 0000 sp = ffee bp = 0000 si = 0000 di = 0000DS = 1358 ES = 1358 ss = 1358 cs = 1358 IP = 0100 NV UP EI PL NA PO NA PO NA PO NC1358: 0100 B80900 MOV AX = 0000 cx = 0000 dx = 0000 sp = ffee bp = 0000 Si = 0000 di = 0000ds = 1358 ES = 1358 ss = 1358 cs = 1358 ip = 0103 NV UP EI PL NZ NA PO NC1358: 0103 3D0900 CMP AX, 0009-TAX = 0009 bx = 0000 cx = 0000 dx = 0000 SP = ffee bp = 0000 Si = 0000 di = 0000ds = 1358 ES = 1358 ss = 1358 cs = 1358 ip = 0106 NV Up EI PL ZR NA PE NC1358: 0106 74F8 JZ 0100-TAX = 0009 bx = 0000 cx = 0000 dx = 0000 sp = ffee bp = 0000 Si = 0000 di = 0000DS = 1358 ES = 1358 ss = 1358 cs = 1358 ip = 0100 nv UP EI PL ZR NA PE NC1358: 0100 B80900 MOV AX, 0009- After the JZ 100 is executed, the results jump to 100.

In addition to JZ, there are other Conditional Jump instructions, and the use method is similar: 1. JZ - If you are equal to zero jump (JUMP if Zero / Equal) 2. JNZ - if it is not equal to zero jump (Jump if not Zero / Equal 3. JG - If the JUMP IF Greater Than 4. JL - if it is less than zero hop 5. JGE - if it is greater than or equal to zero jump (Jump if Greater Than or equal to) 6. Jle - If less than or equal to the zero hop (Jump if less or equal ", you can repeatedly execute a certain directive 10 times, you can use the loop instruction without having to repeat 10 times. -A1001358: 0100 MOV CX, 21358: 0103 MOV AX, 91358: 0106 LOOP 1031358: 0108 MOV AX, 11358: 010B- This loop directive is very special, because it is used in conjunction with the CX buffer, you only need to repeat The number is placed in the CX buffer, where the CX is set to 2, indicating that 2 times to repeat, and the LOOP 103 means to jump to address 103.

The following demonstration LOOP instructions do the effect: -Rax = 0009 bx = 0000 cx = 0000 dx = 0000 sp = ffee bp = 0000 si = 0000 di = 0000ds = 1358 ES = 1358 ss = 1358 cs = 1358 IP = 0100 NV UP EI PL NZ NA PO NC1358: 0100 B90200 MOV CX, 0002-TAX = 0009 bx = 0000 cx = 0002 DX = 0000 SP = FFEE BP = 0000 Si = 0000 Di = 0000DS = 1358 ES = 1358 SS = 1358 CS = 1358 ip = 0103 NV UP EI PL NZ NA PO NC1358: 0103 B80900 MOV AX, 0009-TAX = 0009 bx = 0000 cx = 0002 DX = 0000 SP = ffee bp = 0000 Si = 0000 di = 0000ds = 1358 ES = 1358 SS = 1358 cs = 1358 ip = 0106 NV UP EI PL NZ NA PO NC1358: 0106 E2FB LOOP 0103-TAX = 0009 bx = 0000 cx = 0001 dx = 0000 sp = ffee bp = 0000 Si = 0000 di = 0000ds = 1358 ES = 1358 ss = 1358 cs = 1358 ip = 0103 NV UP EI PL NZ NA PO NC1358: 0103 B80900 MOV AX = 0009 bx = 0000 cx = 0001 DX = 0000 sp = ffee bp = 0000 Si = 0000 di = 0000ds = 1358 ES = 1358 SS = 1358 CS = 1358 ip = 0106 NV Up EI PL NZ NA PO NC1358: 0106 E2FB LOOP 0103-TAX = 0009 bx = 0000 CX = 0000 DX = 0000 SP = FFEE BP = 0000 Si = 0000 di = 0000ds = 1358 ES = 1358 ss = 1358 CS = 1358 IP = 0108 NV UP EI PL NZ NA PO NC1358: 0108 B80100 MOV AX, 000 1 Pay attention to each time the LOOP 103 is executed, the value of the CX will be reduced. So, this LOOP 103 means "If the CX is reduced by 1, it will jump to 103, otherwise continue the next instruction." The call subscriber sometimes needs to perform the same paragraph instruction at different times. At this time, you can use the CALL instruction, in turn, in order to call it, so you don't have to write this instruction.

-A1001358: 0100 MOV AX, 91358: 0103 Call 1091358: 0106 MOV AX, 11358: 0109 MOV AX, 31358: 010C RET1358: 010D-Call 109 denotes "call address 109", in fact it seems that JMP 109 will jump to address 109, RET represents "Return", after executing the RET instruction, the next address of the instruction Call 109 that is previously made before, is 106. -RAX = 0000 bx = 0000 cx = 0000 DX = 0000 sp = ffee bp = 0000 si = 0000 di = 0000DS = 1358 ES = 1358 ss = 1358 cs = 1358 IP = 0100 NV UP EI PL NA PO NA PO NA PO NC1358: 0100 B80900 MOV AX = 0000 cx = 0000 dx = 0000 sp = ffee bp = 0000 Si = 0000 di = 0000ds = 1358 ES = 1358 ss = 1358 cs = 1358 ip = 0103 NV UP EI PL NZ NA PO NC1358: 0103 E80300 CALL 0109-TAX = 0009 bx = 0000 cx = 0000 DX = 0000 SP = FFEC BP = 0000 Si = 0000 di = 0000ds = 1358 ES = 1358 ss = 1358 cs = 1358 ip = 0109 NV UP EI PL NZ Na PO NC1358: 0109 B80300 MOV AX, 0003-TAX = 0003 bx = 0000 cx = 0000 DX = 0000 SP = FFEC BP = 0000 Si = 0000 di = 0000ds = 1358 ES = 1358 IP = 010c NV Up EI PL NZ NA PO NC1358: 010C C3 RET-TAX = 0003 bx = 0000 cx = 0000 DX = 0000 SP = FFEE BP = 0000 Si = 0000 Di = 0000DS = 1358 ES = 1358 SS = 1358 CS = 1358 IP = 0106 NV UP EI PL NZ NA PO NC1358: 0106 B80100 MOV AX, 0001 - This effect is that the JMP instruction cannot be done, because the CPU will remember the address of the Call, so RET will return the address of the previous CALL.

One of the main uses of mathematics is counting, the following is a sample-by-one calculation of the number of times: calculation 1 2 = 3: -A1001358: 0100 MOV AX, 11358: 0103 MOV BX, 21358: 0106 Add Ax, BX1358: 0108-RAX = 0003 bx = 0002 cx = 0000 dx = 0000 SP = ffee bp = 0000 Si = 0000 di = 0000ds = 1358 ES = 1358 ss = 1358 cs = 1358 ip = 0100 NV UP EI PL NZ NA PE NC1358: 0100 B80100 MOV AX 0001-TAX = 0001 bx = 0002 cx = 0000 dx = 0000 SP = ffee bp = 0000 Si = 0000 di = 0000DS = 1358 ES = 1358 ss = 1358 cs = 1358 IP = 0103 NV UP EI PL NZ NA PE NA PE NC1358: 0103 BB0200 MOV BX, 0002-TAX = 0001 BX = 0002 CX = 0000 DX = 0000 SP = ffee bp = 0000 Si = 0000 di = 0000DS = 1358 ES = 1358 SS = 1358 CS = 1358 IP = 0106 NV Up EI PL NZ NA PE NC1358: 0106 01D8 Add Ax, BX-TAX = 0003 bx = 0002 CX = 0000 DX = 0000 sp = ffee bp = 0000 Si = 0000 di = 0000ds = 1358 ES = 1358 SS = 1358 CS = 1358 IP = 0108 NV UP EI PL NZ NA PE NC1358: 0108 0000 Add [BX Si], Al DS: 0002 = FFADD AX, BX means plus AX to add BX, then put the result in AX, and the result AX is equal to 3.

Calculate 3-2 = 1: -A1001358: 0100 MOV AX, 31358: 0103 MOV BX, 21358: 0106 SUB AX, BX1358: 0108-RAX = fff BX = 0002 CX = 0000 DX = 0000 sp = ffee bp = 0000 si = 0000 di = 0000ds = 1358 ES = 1358 ss = 1358 CS = 1358 ip = 0100 NV Up EI Ng NZ AC PE CY1158: 0100 B80300 MOV AX, 0003-TAX = 0003 bx = 0002 CX = 0000 DX = 0000 sp = ffee bp = 0000 Si = 0000 di = 0000DS = 1358 ES = 1358 ss = 1358 cs = 1358 ip = 0103 NV UP EI NG NZ AC PE CY1158: 0103 BB0200 MOV BX, 0002-TAX = 0003 bx = 0002 CX = 0000 DX = 0000 SP = ffee bp = 0000 Si = 0000 di = 0000DS = 1358 ES = 1358 ss = 1358 cs = 1358 ip = 0106 NV UP EI Ng NZ AC PE CY1158: 0106 29D8 SUB AX, BX-TAX = 0001 bx = 0002 CX = 0000 DX = 0000 SP = ffee bp = 0000 Si = 0000 di = 0000ds = 1358 ES = 1358 ss = 1358 CS = 1358 ip = 0108 NV UP EI PL NZ NA PO NC1358: 0108 0000 Add [BX Si], Al DS : 0002 = FF-SUB AX, BX means minus AX to subtract BX, then put the result in AX, and the result is equal to 1.

Calculate 2 * 3 = 6: -A1001358: 0100 MOV AX, 21358: 0103 MOV BX, 31358: 0106 MUL BX1358: 0108-RAX = 0006 bx = 0003 CX = 0000 DX = 0000 sp = ffee bp = 0000 Si = 0000 di = 0000DS = 1358 ES = 1358 ss = 1358 cs = 1358 ip = 0100 NV UP EI PL NZ NA PO NC1358: 0100 B80200 MOV AX, 0002-TAX = 0002 bx = 0003 CX = 0000 DX = 0000 sp = ffee bp = 0000 Si = 0000 di = 0000DS = 1358 ES = 1358 ss = 1358 cs = 1358 IP = 0103 NV UP EI PL NZ NA PO NC1358: 0103 BB0300 MOV BX, 0003-TAX = 0002 bx = 0003 CX = 0000 DX = 0000 SP = Ffee bp = 0000 Si = 0000 di = 0000DS = 1358 ES = 1358 ss = 1358 cs = 1358 IP = 0106 NV Up EI PL NA PO NC1358: 0106 F7E3 MUL BX-TAX = 0006 bx = 0003 CX = 0000 DX = 0000 Sp = ffee bp = 0000 Si = 0000 di = 0000DS = 1358 ES = 1358 ss = 1358 cs = 1358 IP = 0108 NV UP EI PL NZ NA PO NC1358: 0108 0000 Add [BX Si], Al DS: 0003 = 9f -Mul bx indicates that the AX is multiplied by BX and then put the result in AX, and the result is equal to 6.

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

New Post(0)