Help answer threads with 0 replies.
Go Back > Forums > Non-*NIX Forums > Programming
User Name
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.


  Search this Thread
Old 06-16-2010, 02:15 AM   #1
LQ Newbie
Registered: Apr 2010
Posts: 17

Rep: Reputation: 1
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
push ebp ; remember base pointer
mov ebp, esp ; init current base pointer
mov eax,0
mov ecx, [ebp + 8] ; get pointer to string
movsb edx,[ecx] ; first byte
cmp edx,0
je out
inc ecx
inc eax
jmp check
pop ebp ; pop return address in ebp

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.
Old 06-17-2010, 02:32 AM   #2
Senior Member
Registered: Mar 2008
Location: Cyberspace
Distribution: Dynebolic, Ubuntu 10.10
Posts: 1,340

Rep: Reputation: 62

"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.
1 members found this post helpful.
Old 06-21-2010, 03:45 AM   #3
LQ Newbie
Registered: Apr 2010
Posts: 17

Original Poster
Rep: Reputation: 1
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 ?
Old 06-25-2010, 01:18 AM   #4
LQ Newbie
Registered: Apr 2010
Posts: 17

Original Poster
Rep: Reputation: 1
I got solution as,

mov dh, byte [edi] ;copy byte to reg
mov [esi], dh ; copy byte to mem



array, assembly, byte, nasm

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] Byte array conversion yaplej Programming 9 09-23-2009 01:44 PM
NASM assembler code, why is it outputting a letter? Omelas0469 Programming 2 03-15-2007 11:37 PM
Simple mathmatics written in Assembly code using nasm amon Programming 3 01-24-2007 12:31 PM
nasm assembler; output numbers? infinity42 Programming 3 11-15-2005 01:02 PM
NASM Assembly Tutorials NCC-1701&NCC-1701-D Programming 2 06-29-2005 06:46 AM > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 04:27 PM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration