Assembler Developer

Moderators: None (Apply to moderate this forum)
Number of threads: 964
Number of posts: 1756

This Forum Only
Post New Thread
Single Post View       Linear View       Threaded View      f

Report
Numbers in registers assembly Posted by karma4561 on 5 Oct 2008 at 8:41 AM
Hello, I have a problem, if I do the following, it works fine for what I need to do:

mov bx,0
mov vector[bx],1


But if I want to put a variable instead the number 1, like this:


mov bx,0
mov ah, offset variable
mov vector[bx],ah


It doesn't works as I want. Someone know how to resolve this?

Best regards


Report
Re: Numbers in registers assembly Posted by BitByBit_Thor on 5 Oct 2008 at 9:04 AM
: Hello, I have a problem, if I do the following, it works fine for
: what I need to do:
:
:
: 
: mov bx,0
: mov vector[bx],1
: 
:
:
: But if I want to put a variable instead the number 1, like this:
:
:
:
: 
: mov bx,0
: mov ah, offset variable
: mov vector[bx],ah
: 
:
:
: It doesn't works as I want. Someone know how to resolve this?
:
: Best regards
:
:
:

A variable in assembly is actually a label that is translated as an address literal during compile.
Therefore, you need to tell the Assembler that you are using it as an address. Knowing this, your code above simplifies to:
mov ah, [offset variable]
mov [vector], ah


Best Regards,
Richard

The way I see it... Well, it's all pretty blurry
Report
Re: Numbers in registers assembly Posted by karma4561 on 5 Oct 2008 at 1:10 PM
Hi Richard. Thanks for the answer.

It was not possible to made what I want. I added:

mov al, byte ptr[offset variable]

because if I put

mov al,[offset variable]

I get an error that says that the constant is too large, I fixed it using the byte ptr, however it is still not working yet.

Best regards,
Report
Re: Numbers in registers assembly Posted by BitByBit_Thor on 5 Oct 2008 at 1:50 PM
: Hi Richard. Thanks for the answer.
:
: It was not possible to made what I want. I added:
:
: mov al, byte ptr[offset variable]
:
: because if I put
:
: mov al,[offset variable]
:
: I get an error that says that the constant is too large, I fixed it
: using the byte ptr, however it is still not working yet.
:
: Best regards,
:

Hmmm... what assembler are you using? The code I gave works for NASM, but if you have something like MASM then it might need to be slightly altered.

But, what's not working? Are you getting a compile error, or is your program not behaving as expected?
Best Regards,
Richard

The way I see it... Well, it's all pretty blurry
Report
Re: Numbers in registers assembly Posted by karma4561 on 5 Oct 2008 at 2:20 PM
If I do not add the byte ptr, I got an assembler error, that is, "constant too large"

And yes, the program does not behave as expected, it works ok if I put a number, for example:

mov vector[bx],1


But as soon as I try to use a variable, the program does not behave as I want.

By the way, I am using TASM, with Tlink as the linker.

Thanks for your help

Best regards.

Report
Re: Numbers in registers assembly Posted by BitByBit_Thor on 6 Oct 2008 at 3:19 PM
: If I do not add the byte ptr, I got an assembler error, that is,
: "constant too large"

Must be TASM specific (demanding you to say it's a PTR).

:
: And yes, the program does not behave as expected, it works ok if I
: put a number, for example:
:
:
: mov vector[bx],1
:
:
: But as soon as I try to use a variable, the program does not behave
: as I want.
:
: By the way, I am using TASM, with Tlink as the linker.
:
: Thanks for your help
:
: Best regards.
:

The problem is most likely somewhere else in your code. Could you post the whole piece of code, along with the input you give it and the output it gaves (and also the output you expect)?

Best Regards,
Richard

The way I see it... Well, it's all pretty blurry



 

Recent Jobs

Official Programmer's Heaven Blogs
Web Hosting | Browser and Social Games | Gadgets

Popular resources on Programmersheaven.com
Assembly | Basic | C | C# | C++ | Delphi | Flash | Java | JavaScript | Pascal | Perl | PHP | Python | Ruby | Visual Basic
© Copyright 2011 Programmersheaven.com - All rights reserved.
Reproduction in whole or in part, in any form or medium without express written permission is prohibited.
Violators of this policy may be subject to legal action. Please read our Terms Of Use and Privacy Statement for more information.
Operated by CommunityHeaven, a BootstrapLabs company.