assembly - why does movsw instruction increments the si and di registers by2 while movsb instruction increments the si and di registers by 1? -


i working movsb , movsw instruction in assembly language using flat assembler. now, noticed when movsb instruction executed si , di register incremented 1 while movsw instruction increments si , di register 2. bit confused why? can explain me reason. adding codes below both instruction comments. please me out. thanks!

using movsb instruction(flat assembler)

cld ;clear direction flag  lea si,[val]  ;the memory address of source loaded in source register  lea di,[v];the memory address of destination loaded in destination register  mov cx,5 ; counter executes number of characters in array  rep movsb ; repeats instruction 5 times  val:      db 'a'       db 'b'      db 'c'      db 'd'      db 'e'  v db 5 dup(?) 

using movsw instruction(flat assembler)

cld    ;clear direction flag  lea si,[a];load address of in source ;register lea di,[b] ;load address of b in destination ;register mov cx,3 rep movsw  ;copy each word source ;destination , increment source register ;by 2 , destination register 2  a:    dw '1'   dw '2'   dw '3'  b dw 3 dup(?) 

movsw, movsb, movsd, movsq instructions used copy data source location ds:(er)si destination location es:(er)di.

they useful because there no mem-to-mem move instruction in ia32e.

they meant used in cycles (for example using rep prefix), besides moving data increments (if df flag, direction flag, 0) or decrements (if df flag 1) pointers source , destination locations, i.e. (er)si , (er)di registers.

from assembly programmer perspective memory byte-addressable, means each address store 1 byte.

  • movsb moves byte, register incremented/decremented 1.
  • movsw moves word (2 bytes), register incremented/decremented 2.
  • movsd moves dword (double word, 2 word, 4 bytes), register incremented/decremented 4.
  • movsq moves qword (quad word, 4 words, 8 bytes), register incremented/decremented 8.

Comments

Popular posts from this blog

javascript - Karma not able to start PhantomJS on Windows - Error: spawn UNKNOWN -

Nuget pack csproj using nuspec -

c# - Display ASPX Popup control in RowDeleteing Event (ASPX Gridview) -