flat assembler
Message board for the users of flat assembler.

Index > Main > Comparing two words in memory

Author
Thread Post new topic Reply to topic
Trinitek



Joined: 06 Nov 2011
Posts: 257
Trinitek 06 Nov 2011, 22:38
Excuse me if I sound like I don't know what I'm doing, but I'm having a bit of trouble with comparing two words stored in memory. I'm trying to compare a BMP's magic number, which is stored as a word at the very beginning of the file (424Dh), and the same hexadecimal value stored in a variable called "magic".

Code:
MOV     BX,image
CMP     word [BX],[magic]
magic   DW 424Dh
image   FILE '..\snowym~1.bmp'    


I've tried every combination in the book. With brackets, without, using an immediate value, everything!
Post 06 Nov 2011, 22:38
View user's profile Send private message Reply with quote
magicSqr



Joined: 27 Aug 2011
Posts: 105
magicSqr 06 Nov 2011, 22:51
you can't compare 2 memory values, you need to place one in a register first.

Code:

mov ax, [bx]
cmp ax, [magic]

    


or, since you know the value you're looking for...

Code:
cmp   word [magic], 0x424D
    


Quote:

Code:
MOV     BX,image            <------ ???
CMP     word [BX],[magic]
magic   DW 424Dh
image   FILE '..\snowym~1.bmp'    


Not sure what you're trying to do at the arrowed part tho ¿

You need to open the file for reading, read the first word from the file, then compare it to 0x424D.

magic²
Post 06 Nov 2011, 22:51
View user's profile Send private message Reply with quote
Trinitek



Joined: 06 Nov 2011
Posts: 257
Trinitek 07 Nov 2011, 01:00
Oh. Laughing Nevermind. I forgot that it swaps the placement of the bits when I got the word from the image header.

Thanks for telling me that I had to put the value into a register first. I completely forgot about that as well.

Everything seems to be in working order as of now...
Post 07 Nov 2011, 01:00
View user's profile Send private message Reply with quote
Madis731



Joined: 25 Sep 2003
Posts: 2139
Location: Estonia
Madis731 07 Nov 2011, 18:28
and FASM also allows you to do this:
Code:
cmp word[bx],"BM" ; Now there's no "magic", just constant Smile
    
Post 07 Nov 2011, 18:28
View user's profile Send private message Visit poster's website Yahoo Messenger MSN Messenger Reply with quote
Trinitek



Joined: 06 Nov 2011
Posts: 257
Trinitek 08 Nov 2011, 00:07
Madis731 wrote:
and FASM also allows you to do this:
Code:
cmp word[bx],"BM" ; Now there's no "magic", just constant Smile
    


Thanks Madis, but I already figured it out. Laughing Apparently, there's a problem with how I load the binary file using FILE. I'll have to look into that, but it's working as of now.
Post 08 Nov 2011, 00:07
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.