LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
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.

Notices


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

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

Original Poster
Rep: Reputation: 1
I got solution as,
[CODE]

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

[CODE]
 
  


Reply

Tags
array, assembly, byte, nasm



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
nasm assembler; output numbers? infinity42 Programming 4 05-26-2018 01:22 PM
[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 Assembly Tutorials NCC-1701&NCC-1701-D Programming 2 06-29-2005 06:46 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

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

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