Skip to main content
gamedev.net
🔒 Locked

ASM problem

Started by Rudan 4 replies 300+ views
Original Post
Rudan
Rudan
I''m playing around with NASM, and I''ve got a problem. I use this to declare some initialized data: test dw ''1'',''2'',''3'',''4'',''5'',''$'' then, I want to compare the first byte with the content in AX, and to do that I try to copy the first byte to BX, but I can''t get it to work properly. I tried with this: mov al, test but that didn''t work, because if I then put 1 in AX and compare AX and BX, I get a not equal result. Sorry if this is a stupid question, but I''ve tried to fix it for hours now, and I''m stuck. Any help is appreciated.
-----------------------------Reporter: Are they slow-moving, chief?Sheriff: Yeah, they're dead. They're all messed up.-Night of the living dead
burp
burp

Is this what you''re doing?

test dw ''1'',''2'',''3'',''4'',''5'',''$''
mov al,test
cmp ax,bx

1. a dw is a word, or 2 bytes long
2. mov al,test, loads a byte
3. cmp ax,bx, is comparing words

Try this...

test db ''1'',''2'',''3'',''4'',''5'',''$''

mov al,test ''loads byte from the address at test
cmp al,''1'' ''compares the byte in al to ''1''

ax is made up of two registers

al - Accumulator low
ah - Accumulator high

1. if you just mov al,test
2. ah is not reset it still contains a value

You really need to find yourselve a book, or a web tutorial...






NickB
NickB
okay - right, from your description, you want to copy data into BX ? and then you compare it to AX ??? I dunno if it''s a typo...but what you''ve written ("mov al, test") copies the data into AX - ie the value of BX is random because you haven''t initialised it....

I would suggest that as you are loading a byte, but comparing a word that you may need to clear the upper part of the BX register, vis:


xor bx, bx
mov ax, TestCompareValue ; whatever you want to use
mov bl, test
cmp ax, bx


Hopefully this might help you

NickB
Rudan
Rudan
Ops, sorry about that, that al thing is a typo. It should be like this:
mov ax, test

I've already tried using bytes and the high and low registers. Didn't work either.

NickB: Sorry, you're right, I did another typo there. What I want to do is to put the value from test in AX and compare it to BX where I already got another value.

I'll just print the whole thing again:

test dw '1','2','3','4','5','$'

mov bx, 1
mov ax, test
cmp ax, bx

//Edit: Ok, I messed up this post too with typos. I probably need some sleep. Well, now it should be correct.


Edited by - Rudan on November 30, 2001 7:03:49 PM
-----------------------------Reporter: Are they slow-moving, chief?Sheriff: Yeah, they're dead. They're all messed up.-Night of the living dead
Rudan
Rudan
AP: Thanks a lot. You''re right, it seems to be working now
-----------------------------Reporter: Are they slow-moving, chief?Sheriff: Yeah, they're dead. They're all messed up.-Night of the living dead

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.