understanding copying a string using movsb? - Programmers Heaven

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!


Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

understanding copying a string using movsb?

[b]Edit, nevermind I figured out that movsb automatically adjusts ESI and EDI[/b]

Hi all,
I just started coding assembly so please excuse my ignorance.

Below is some sample code to copy "hello world" from one variable to another.

I have built and linked this code with no issues and checked that it is working in gdb and it works fine.

My question is, if movsb moves 1 byte at a time and it copies and does not remove the characters from the original HelloWorld buffer, how does this code know it should point to the next byte in the string, when it repeats the movsb?

Look forward to hearing your responses.


.section .data
.ascii "Hello World"
.section .bss
.lcomm Destination, 50
.section .text
.globl _start
movl $HelloWorld,%esi
movl $Destination, %edi
movl $11, %ecx
rep movsb
movl $1, %eax
movl $0, %ebx
int $0x80

Sign In or Register to comment.