Assembly-programming-assembly-movs-instruction

提供:Dev Guides
移動先:案内検索

アセンブリ-MOVS命令

MOVS命令は、ソース文字列から宛先文字列にデータ項目(バイト、ワード、またはダブルワード)をコピーするために使用されます。 ソース文字列はDS:SIによって指され、宛先文字列はES:DIによって指されます。

次の例では、概念を説明します-

section .text
   global _start        ;must be declared for using gcc

_start:                 ;tell linker entry point
   mov  ecx, len
   mov  esi, s1
   mov  edi, s2
   cld
   rep  movsb

   mov  edx,20          ;message length
   mov  ecx,s2          ;message to write
   mov  ebx,1           ;file descriptor (stdout)
   mov  eax,4           ;system call number (sys_write)
   int  0x80            ;call kernel

   mov  eax,1           ;system call number (sys_exit)
   int  0x80            ;call kernel

section .data
s1 db 'Hello, world!',0 ;string 1
len equ $-s1

section  .bss
s2 resb 20              ;destination

上記のコードをコンパイルして実行すると、次の結果が生成されます-

Hello, world!