The asciz directive will null terminate the string for you. The ascii directive requires you put in your own null.
so there .ascii then. Good to know
Incidentally, your copy function always copies 12 bytes, regardless of how long the string is, instead of copying until it finds a null character. Is that what you wanted/were required to do?
Yeah that's what I wanted, but when I got the seg fault. I changed the base case (%ebx) to be 12.
As for your print code, you have the right system calls for linux: System Call Table. The code works fine for me. Is that mixed in with your copy function? Did you somehow overflow into your hello label? Try the following:
Code:
movl $6, %edx
movl $0, %ebx
movl $hello, %ecx
movl $4, %eax
int $0x80
movl $1, %eax
int $0x80
That still doesn't work.
This is the modified code..It still prints "ello" instead of "World"
Code:
.section .data
stringVar:
.string "Hello World"
copyString:
.byte 12
hello:
.string "World"
.section .text
.global _start
_start:
movl $stringVar, %esi
movl $copyString, %edi
movl $0,%ebx
copyLoop:
cmpl $12,%ebx
je exit
movb (%esi), %cl
movb %cl, (%edi)
incl %esi
incl %edi
incl %ebx
jmp copyLoop
exit:
movl $5, %edx
movl $0, %ebx
movl $hello, %ecx
movl $4, %eax
int $0x80
movl $1, %eax
int $0x80
Thanks.