LDS command in Atmega32 using ATMEL STUDIO 7 Assembly

To start with LDS command in Atmega32 using ATMEL STUDIO 7 Assembly .Loads a single byte into a register from the data space. The Register File, I/O memory, and internal SRAM (and external SRAM if appropriate) make up the data space for components that have SRAM. The register file is the only component in the data space for components that don’t have SRAM. The address space of the EEPROM is distinct.

There must be a 16-bit address provided. There is only 64KB of memory available at this time for data segment access. To access memory larger than 64KB, the LDS instruction makes use of the RAMPD Register. In devices with more than 64KB of data capacity, a change must be made to the RAMPD in register located in the I/O area in order to access another data segment.

Let us understand this command through a program in assembly language.

Firstly, we will include a header file.

CODE:

.INCLUDE “M32DEF.INC”

If you do not know how to include it, you can check by clicking here.

LDS command is used to load the value in general purpose register. For example we have some location and we want to check which value is placed there or we want to apply any manipulation and arithmetic operation on that value, for this purpose we need to load the value in the general purpose register using the LDS command.

LDI R20,0XA                                           // r20=0xA
STS 0X400,R20                                     //0x400=0xA

First, we load the hex A (in decimal it is 10) value in the general purpose register R20 using the LDI command. Then we used STS command which is used to store the general purpose register’s value in some memory location. 

LDS R2,0X400                                      //r2=0xA
LDI R21,0X55                                      // r21=0x55
ADD  R21,R2                                       // r21=r21+r2
BREAK

Now we want to load the value which was placed in 0X400 memory location in some general purpose register. As this is not the immediate value this value is stored in memory location so we will use the LDS command. In LDS command, the limit of the general purpose register is from R0 to R31. That A value will be loaded in R2.  

In the next step we loaded the immediate value 0X55 value in the general purpose register R21. And at the last step we added the R21 in the R2 that final result will be stored in R21.

Now we will build and debug our solution.

Debug:

Below you can see 0x0A has been loaded in the R20.

You can see that that 0x0A value has been loaded in the R2 location. Hence means that LDS command has loaded the value from memory location to general purpose register. 

The 0x55 value has been loaded in the general purpose register R21.

And at the end we have the sum of the two values in the general purpose register R21. 

Conclusion

If you made it this far, congrats. It was plenty to process in one sitting. If nothing else, at least you should know now what kinds of operations may be done with the general purpose work registers. You might need to read this several times to really get it.

For Complete Trial Watch the Video: LDS command in Atmega32 using ATMEL STUDIO 7 Assembly

For more blogs explore the website: https://ninjatech.live/

Leave a Comment

Your email address will not be published. Required fields are marked *