Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Sign In with Facebook Sign In with Google Sign In with OpenID

Categories

We have migrated to a new platform! Please note that you will need to reset your password to log in (your credentials are still in-tact though). Please contact lee@programmersheaven.com if you have questions.
Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

Numbers in registers assembly

Hello, I have a problem, if I do the following, it works fine for what I need to do:

[code]
mov bx,0
mov vector[bx],1
[/code]

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


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

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

Best regards


Comments

  • BitByBit_ThorBitByBit_Thor Posts: 2,444Member
    : Hello, I have a problem, if I do the following, it works fine for
    : what I need to do:
    :
    : [code]:
    : mov bx,0
    : mov vector[bx],1
    : [/code]:
    :
    : But if I want to put a variable instead the number 1, like this:
    :
    :
    : [code]:
    : mov bx,0
    : mov ah, offset variable
    : mov vector[bx],ah
    : [/code]:
    :
    : 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:
    [code]
    mov ah, [leftbr]offset variable[rightbr]
    mov [leftbr]vector[rightbr], ah
    [/code]

    Best Regards,
    Richard

    The way I see it... Well, it's all pretty blurry
  • karma4561karma4561 Posts: 13Member
    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,
  • BitByBit_ThorBitByBit_Thor Posts: 2,444Member
    : 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
  • karma4561karma4561 Posts: 13Member
    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:

    [code]mov vector[bx],1[/code]

    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.

  • BitByBit_ThorBitByBit_Thor Posts: 2,444Member
    : 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:
    :
    : [code]: mov vector[bx],1[/code]:
    :
    : 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
Sign In or Register to comment.