This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

How to use LOW or HIGH in A51?

I am writing a 8051 assembly program and try to use LOW/HIGH. When i ran the following

MOV  R1,#LOW   (variable)

R1 = LSB address byte of the variable, not LSB byte of the variable. How can I get it?

Parents Reply Children
  • No, a quick look at the User Manaul says that will not work.

  • The name of a variable is the address where the variable lives, not the value at that address. LOW and HIGH return the LSB and MSB of that 16-bit address. These expressions are not executable code and do not themselves fetch data; they are just interpreted by the assembler.

    To move data from an address, you want to use the MOV instruction in some form.

    The # indicates "immediate addressing", which is to say that the address will be built into the instruction (as opposed to being in another register or somewhere in data memory).

    Assuming the 16-bit address means that your variable is located in xdata, you probably want code that looks something like:

        MOV DPTR, #variable
        MOVX A, @DPTR
        MOV R0, A
    

    (Fair warning: I don't do much in assembler and just typed that in off the top of my head without trying it...)

    If you really want to use LOW and HIGH, the code could look like:

        MOV DPL, #LOW(variable)
        MOV DPH, #HIGH(variable)
        MOVX A, @DPTR
        MOV R0, A
    


    But this is a slightly less efficient way to load the DPTR if you (the assembler) already knows the address. This form is more useful for a pointer parameter passed in registers (for example), in which case LOW and HIGH wouldn't be used.