Talk:X86 Assembly/Data Transfer

From Wikibooks, the open-content textbooks collection

Jump to: navigation, search

[edit] First Example is Confusing Me

Can someone explain the first example in more detail. A few of the lines really confuse me:

1) following _start, in the second mov instruction... I understand that value == 6 because eax was set to 6 previously, but I don't see how in the fifth mov instruction that ebx can equal 2, since value was set to 6 in the second line. 2) And could someone explain what is going on here in the last instruction of _start:

  movw   value(, %ebx, 1), %bx

Am I missing something from the previous sections in this book?

Regarding your first question, I'm guessing that the author forgot he'd reset **value** to 6, after initially setting it to 2 in the data section. That's my best guess, anyway.
For number 2, I haven't a bloody clue. 74.131.20.28 (talk) 02:48, 17 June 2008 (UTC)

[edit] Last example

In the last example, it says "due to endianess, the resulting mystr2 would be aAbBcC\0a". This seems wrong because the endianess should be the same during read AND write. Just to confirm, I tried to compile this with nasm :

 section .code
 global _start
 _start:
 ; copy mystr into mystr2
 mov esi, mystr
 mov edi, mystr2
 cld
 mov ecx, 4
 rep movsw
 
 mov edx,8
 mov ecx,mystr2
 mov ebx,1
 mov eax,4
 int 0x80
 
 mov ebx, 0
 mov eax, 1
 int 0x80
 
 section .bss
 mystr2: resb 8
 
 section .data
 mystr db "AaBbCca", 0x0

And in fact, it prints AaBbCca. Am I right or is it because of my architecture (amd64) or something like that ?