Assembly instructions of STOS, REP

Disclaimer: This article is a blogger original article, reproduced, please attach the original source link and this statement. 23: 28: 13,23: 28: 19
of the female heart and the ups and downs By ----- ---- blog Park

STOS instructions: speaking Al / AX / EAX value stored in the [EDI] memory cell designated

  STOS BYTE PTR ES: [EDI] abbreviation STOSB

  STOS WORD PTR ES: [EDI] abbreviation STOSW

  STOS DWORD PTR ES: [EDI] abbreviation STOSD

Specifically AL / AX / EAX it depends on how much the specific width, STOS command bits D similarly affected (Direction Flag), when the D bit is 1, the value of EDI will be reduced, when the D bit is 0 the value of EDI will be added in front of the posts have talked about, MOVS instruction is also subject to the impact position D

Before writing something to the memory address, are used in DS :, here when used EDI, uniform use of ES, segment registers, not involved, for the time being the first so remember

  MOV EAX,12345678

  MOV EDI,18FF8C

  DWORD PTR ES faro [EDI]

  ES stosic WORD PTR [EDI]

  HESE BYTE PTR ES: [EDI]

 

 Pressing the F8, the instruction execution STOSD careful observations of EDI

 

It can be seen in the implementation of STOSD After instruction, the address number inside EAX value to EDI in writing represented, minus the value of EDI 4, look at STOSW, STOSB

 

It can be seen after you execute STOSW instruction, the lower 16 bits of EAX in the lower 16 bits of memory to EDI numbers represented in writing, minus the value of EDI 2, due to the continuous execution of our code, this step EDI value of the step value is decremented after the EDI 4, i.e. 0x18FF88

Let's look at STOSB command, and then press F8 to go down the code

 

Here it can be seen that, after subtracting the value of EDI 0x18FF86 a byte becomes 0x18FF85, then writing the value of AL in the EDI

 

Disclaimer: This article is a blogger original article, reproduced, please attach the original source link and this statement. 23: 28: 13,23: 28: 19
of the female heart and the ups and downs By ----- ---- blog Park 

 

 We will change the Direction Flag value is 0, the following code is executed

   MOV EAX,12345678

   MOV EDI, 12FFC4

   HESE BYTE PTR ES: [EDI]

   ES stosic WORD PTR [EDI]

   DWORD PTR ES faro [EDI]

 

After performing the first step, the second step the following code:

 

Do not forget that before the implementation of the D position to 0, I forgot to add the code of the time, when executed STOSB change back , then perform STOSB, carefully observe the following:

 

Through observation, we see the value of EDI plus 1, the value is written to the AL 0x18FF70, the Note: Only the lower 8 bits are written! ! !


Execution STOSW

 

We observed that, after the value from the EDI 0x18FF71 plus 2, becomes 0x18FF73, 0x18FF70 observation memory area can be seen, 0x18FF71,0x18FF72 written, the two values ​​56, 78

 Instruction execution STOSD

 

EDI value from 0x18FF73 after 4 plus turns 0x18FF77, form if you do not understand why the reader is written in the form shown in the figure, I suggest that you put the memory split open, with a byte by byte to see and then draw a map, I believe you will understand that you can have 0x18FF73 starting point for the beginning, 4 bytes 4 bytes re-draw a map of their own, this time behind the memory number will be 0x18FF77,0x18FF7B, 0x18FF7F

 

 REP instruction: Press count register (the ECX) is repeatedly executed the number of times specified in the instruction string

  REP instruction count register according to the value specified in ECX times repeatedly executed instructions Note: The following code MOV ECX, 10, 10 represented by hexadecimal 10, 16 in decimal

   MOV EC, 10

   REP MOVSD

   REP STOSD

 

 

版权声明:本文为博主原创文章,转载请附上原文出处链接和本声明。23:28:13,23:28:19
作者By-----溺心与沉浮----博客园

 

执行前两步代码后如下:

 

执行REP STOSD

 

执行完REP STOSD之后,ECX里的值归0了,因为每执行一次,ECX里的值都会减1直至为0,观察图中内存区域,数一下,一共是写入了16次0x12345678,EDI的值也变为了EDI + ECX * 4。

接着看REP MOVSD

执行前两步代码如下

 

执行REP MOVSD,啊哦,有点尬,还剩3次执行完的时候,我堆栈已经走到底了,,,

 

我重新打开一遍0D,执行一下REP MOVSD

 

版权声明:本文为博主原创文章,转载请附上原文出处链接和本声明。23:28:13,23:28:19
作者By-----溺心与沉浮----博客园

 

执行REP MOVSD指令

 

ESI与EDI都增加了ECX * 4,64个字节0x40,大家有兴趣可以将D位更改为1,尝试一下,REP STOSD,REP STOSW,REP STOSB, REP MOVSD,REP MOVSW,REP MOVSB指令

 

 1、用MOVS指令分别移动5个字节、5个字、5个双字

 2、用STOS指令分别存储5个字节、5个字、5个双字

 3、使用REP指令重写第1、2题

 嗯,这些都是本节将的指令相关内容,这三个题,博文中也有写,只不过,最多就写了2次,3次,大家可以用MOVS,STOS多写写,代替REP,等到写吐了,也就理解了REP了,这三题就不写了。

 

 版权声明:本文为博主原创文章,转载请附上原文出处链接和本声明。23:28:13,23:28:19
作者By-----溺心与沉浮----博客园

Guess you like

Origin www.cnblogs.com/Reverse-xiaoyu/p/11415739.html