how to traverse byte array in assembly using nasm as assembler?
hello, I am trying to learn assembly using nasm as assembler. I did not found example related to string operation. I had following example code,
global asm_strlen section .data section .bss section .text asm_strlen: push ebp ; remember base pointer mov ebp, esp ; init current base pointer mov eax,0 mov ecx, [ebp + 8] ; get pointer to string check: movsb edx,[ecx] ; first byte cmp edx,0 je out inc ecx inc eax jmp check out: pop ebp ; pop return address in ebp ret my problem is at highlighted line, I am not getting how to copy a byte into 4 byte reg. rather what is syntax of mov instruction to mov byte to WORD DWORD etc. if possible please give some example, and alternative solution if known. |
from: http://en.wikibooks.org/wiki/X86_Assembly/Data_Transfer
"he movsb instruction copies one byte from the location specified in esi to the location specified in edi." so you, i think, can't use it with edx and ecx, that's your problem. |
Thanks for reply, I got solution as bellow,
movzx edx,byte [ecx] ; move single byte I can use byte, WORD, DWORD keywords to move 1 2 4 bytes. after this I got stuck that how to move byte to a byte pointer, I mean, if I have two byte pointers how can I copy them, as u explained I can do that with esi and edi, can u give some code example how to do this ? |
I got solution as,
[CODE] mov dh, byte [edi] ;copy byte to reg mov [esi], dh ; copy byte to mem [CODE] |
All times are GMT -5. The time now is 09:22 AM. |