flat assembler
Message board for the users of flat assembler.

Index > Windows > moving bytes

Author
Thread Post new topic Reply to topic
jacko221



Joined: 12 Nov 2005
Posts: 22
jacko221
Hey everyone... i wanted to create a simple application which output the letter of the number at of a string.

Code:
format PE GUI 4.0
entry start

include '%fasminc%\win32ax.inc'

section '.data' data readable writeable
  hexarray db 'ABCDEFGHIJKLMN'
  caption db 2
  message db 'doesnt work'

section '.code' code readable executable

  start:
     mov dl,5   ;5 used as an example
     mov cl,byte [hexarray+dl]  ;i want the 5th byte (E) to be put into cl
     mov byte [caption],cl ;now put ecx into caption
     invoke MessageBox,0,caption,caption,0 ;now display answer



section '.idata' import data readable writeable

  include '%fasminc%\apia\kernel32.inc'
  include '%fasminc%\apia\user32.inc'
  include '%fasminc%\apia\advapi32.inc'

                                                        


The problem is with this line:
mov cl,byte [hexarray+dl]
Fasm with give me an error saying
Error: Reserved word used as symbol

I would really appreciate some help in solving this problem.
Thanks in advance, Jack
Post 27 Jun 2006, 08:16
View user's profile Send private message Reply with quote
zhak



Joined: 12 Apr 2005
Posts: 490
Location: Belarus
zhak
you cannot use 8- or 16-bit registers for addressing.
Try

mov cl, byte [hexarray+edx]

but don't forget to XOR EDX, EDX at the beginning
Post 27 Jun 2006, 10:02
View user's profile Send private message Reply with quote
jacko221



Joined: 12 Nov 2005
Posts: 22
jacko221
thanks... that got rid of the "Error: Reserved word used as symbol" but now it gives me this "memory could not be "read"" error. Sad oh well... ill try something different.
Thanks again, Jack
Post 27 Jun 2006, 10:46
View user's profile Send private message Reply with quote
0x4e71



Joined: 25 Feb 2004
Posts: 50
0x4e71
did you zero extend edx
Post 27 Jun 2006, 17:15
View user's profile Send private message Reply with quote
jacko221



Joined: 12 Nov 2005
Posts: 22
jacko221
Quote:

did you zero extend edx


I do not understand... im still new to asm. So please help me.
Post 28 Jun 2006, 00:06
View user's profile Send private message Reply with quote
zhak



Joined: 12 Apr 2005
Posts: 490
Location: Belarus
zhak
you should insert

xor edx, edx

instruction at the very beginning of your program. Before

mov dl, 5

EDX register contains non-zero value when your application starts.
You'are using not only DL part of EDX, but the whole register for addressing. That's why higher bytes should be cleared first.
'xor edx, edx' instruction will clear EDX register.[/code]
Post 28 Jun 2006, 06:29
View user's profile Send private message Reply with quote
jacko221



Joined: 12 Nov 2005
Posts: 22
jacko221
Thanks both for your help... really appreciate it Smile
Post 28 Jun 2006, 08:15
View user's profile Send private message Reply with quote
ChrisLeslie



Joined: 04 Jun 2006
Posts: 50
Location: Australia
ChrisLeslie
zhak

Quote:
you should insert

xor edx, edx

instruction at the very beginning of your program. Before

mov dl, 5


Should not "mov edx,5" zero the high bits more easily?

Chris
Post 28 Jun 2006, 09:57
View user's profile Send private message Reply with quote
vid
Verbosity in development


Joined: 05 Sep 2003
Posts: 7105
Location: Slovakia
vid
ChrisLeslie wrote:
zhak
Quote:
you should insert
xor edx, edx
instruction at the very beginning of your program. Before
mov dl, 5

Should not "mov edx,5" zero the high bits more easily?
Chris

mov edx,5 can be encoded only as mov r32, imm32 eg. with 32bit immediate. that's 2 bytes for mov r32, imm32 and 4 bytes for value of imm32.

xor edx, edx takes two bytes, mov dl,5 takes 2 bytes, that's 4 bytes. so you save 2 bytes. in reality, it doen't matter very much in handwritten assembly code, this habit just remained to asm programmmers from old times when resources weren't wasted
Post 28 Jun 2006, 10:16
View user's profile Send private message Visit poster's website AIM Address MSN Messenger ICQ Number Reply with quote
LocoDelAssembly
Your code has a bug


Joined: 06 May 2005
Posts: 4633
Location: Argentina
LocoDelAssembly
Actually mov edx, imm is 5 bytes (one byte for the opcode "mov edx, imm").
Post 28 Jun 2006, 17:11
View user's profile Send private message Reply with quote
0x4e71



Joined: 25 Feb 2004
Posts: 50
0x4e71
Yeah, pity there is no movzx r32, imm8
Again, not that it matters that much anymore.

The 68000 had MOVEQ imm8,r32 (2 bytes)
and SUBQ/ADDQ for values 1-8, these were very very useful, well, back then anyway Rolling Eyes

/L
Post 28 Jun 2006, 18:24
View user's profile Send private message Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  


< Last Thread | Next Thread >
Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Copyright © 1999-2020, Tomasz Grysztar.

Powered by rwasa.