initial import
[staff/goc4/2018bti7061.git] / asm-8-strings / examples / movestring / movestring6repmovsb.asm
1 ; Executable name : movestring4movsb
2 ; Version : 1.0
3 ; Created date : 3/11/2014
4 ; Last update : 3/11/2014
5 ; Author : Emmanuel Benoist
6 ; Description : A simple program in assembly for Linux, using NASM 2.05,
7 ; demonstrating the way to copy a string using MOVSB instruction
8 ;
9 ; Build using these commands:
10 ; nasm -f elf64 -g -F stabs movestring4movsb.asm
11 ; ld -o movestring2stosbreset movestring4movsb.o
12 ;
13
14 SECTION .data ; Section containing initialised data
15
16 InitString db "Hello World",10
17 INITLEN equ $-InitString
18
19 TargetString db "------------------------",10
20 TARGETLEN equ $-TargetString
21
22 SECTION .bss ; Section containing uninitialized data
23
24
25 SECTION .text ; Section containing code
26
27 global _start ; Linker needs this to find the entry point!
28
29 _start:
30 nop ; This no-op keeps gdb happy...
31
32 ;; Init registers to start the copy
33 mov rcx, INITLEN ; The counter receives the length of the string
34 mov rsi, InitString ; The source index points to the address of InitString
35 mov rdi, TargetString ; The destination index receives the address of Target String
36
37 rep movsb ; Loop move data from [RSI] into [RDI] INITLEN times
38
39 ;; In the end TargetStings points to a copy of
40 ;; InitString
41 nop ;To keep gdb happy
42 Output: mov eax,4 ; Specify sys_write call
43 mov ebx,1 ; Specify File Descriptor 2: Standard Error
44 mov ecx,TargetString ; Pass offset of the error message
45 mov edx,INITLEN ; Pass the length of the message
46 ;;(we only copied initlen chars)
47 int 80H ; Make kernel call
48
49 Exit: mov eax,1 ; Code for Exit Syscall
50 mov ebx,0 ; Return a code of zero
51 int 80H ; Make kernel call