- Assembly Tutorial
- Assembly - Home
- Assembly - Introduction
- Assembly - Environment Setup
- Assembly - Basic Syntax
- Assembly - Memory Segments
- Assembly - Registers
- Assembly - System Calls
- Assembly - Addressing Modes
- Assembly - Variables
- Assembly - Constants
- Assembly - Arithmetic Instructions
- Assembly - Logical Instructions
- Assembly - Conditions
- Assembly - Loops
- Assembly - Numbers
- Assembly - Strings
- Assembly - Arrays
- Assembly - Procedures
- Assembly - Recursion
- Assembly - Macros
- Assembly - File Management
- Assembly - Memory Management
- Assembly Useful Resources
- Assembly - Quick Guide
- Assembly - Useful Resources
- Assembly - Discussion
Assembly - MOVS Instruction
The MOVS instruction is used to copy a data item (byte, word or doubleword) from the source string to the destination string. The source string is pointed by DS:SI and the destination string is pointed by ES:DI.
The following example explains the concept −
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
When the above code is compiled and executed, it produces the following result −
Hello, world!
assembly_strings.htm
Advertisements