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 27 Jun 2006, 08:16
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: 501
Location: Belarus
zhak 27 Jun 2006, 10:02
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 27 Jun 2006, 10:46
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 27 Jun 2006, 17:15
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 28 Jun 2006, 00:06
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: 501
Location: Belarus
zhak 28 Jun 2006, 06:29
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 28 Jun 2006, 08:15
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 28 Jun 2006, 09:57
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 28 Jun 2006, 10:16
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: 4624
Location: Argentina
LocoDelAssembly 28 Jun 2006, 17:11
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 28 Jun 2006, 18:24
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-2024, Tomasz Grysztar. Also on GitHub, YouTube.

Website powered by rwasa.