initial import
[staff/goc4/2018bti7061.git] / asm-8-strings / examples / movestring / movestring2stosbreset.asm
1 ; Executable name : movestring2stosbreset
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 errase a string using STOSB instruction
8 ;
9 ; Build using these commands:
10 ; nasm -f elf64 -g -F stabs movestring2stosbreset.asm
11 ; ld -o movestring2stosbreset movestring2stosbreset.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, TARGETLEN ; The counter receives the length of the string
34 mov rsi, InitString ; The source index receives Initial String
35
36 mov rdi, TargetString ; The destination index receives the address of Target String
37
38 dec rcx ; We will not errase the last char, which is a \n
39 .loopcopystring:
40 mov bl,'m' ; Move a char containing "space" into BL
41 mov byte [rdi], bl ; The element in BL is copied into memory at RDI
42 inc rdi ; We go forward in strings
43 dec rcx ; The counter is decremented
44 jnz .loopcopystring ; Loop as long as RCS is not 0
45
46 ;; In the end TargetStings points to a copy of
47 ;; InitString
48 nop ;To keep gdb happy
49 Output: mov eax,4 ; Specify sys_write call
50 mov ebx,1 ; Specify File Descriptor 2: Standard Error
51 mov ecx,TargetString ; Pass offset of the error message
52 mov edx,TARGETLEN ; Pass the length of the message
53 int 80H ; Make kernel call
54
55 Exit: mov eax,1 ; Code for Exit Syscall
56 mov ebx,0 ; Return a code of zero
57 int 80H ; Make kernel call