Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

Question about how Z pointer works

Status
Not open for further replies.

Navid T

Full Member level 3
Joined
Jan 21, 2005
Messages
186
Helped
1
Reputation
2
Reaction score
0
Trophy points
1,296
Location
Iran
Activity points
1,385
Question about Z pointer

Hello
I wrote this code To test how pointer works. I want to Write $4 from Address $50. This Program works Properly But it doesn’t work when I write 50H in Z Register.!!!
Why should I use 1 bit shift left in Pointer register? (Z) I want to reade from 50H but its Twice in Z.
-----------------------------------------------------------------
#include "m32def.inc"
.ORG 0X0000
SETUP:
LDI R16,HIGH(RAMEND)
OUT SPH,R16
LDI R16,LOW(RAMEND)
OUT SPL,R16
LDI R16,$FF
OUT DDRB,R16
MAIN:
LDI R31,HIGH(0X50<<1)
LDI R30,low(0x50<<1)
LPM R16,Z
OUT PORTB,R16
RJMP MAIN
.ORG 0X50
.DB $4
-------------------------------------------------------------------
Best regards
 

Re: Question about Z pointer

It's because the program memory is organized on words - 2bytes, because this is the instruction format for AVR.
LPM will access the memory byte by byte, so the address should be multiplied by 2. LPM will address the LSB from an even (lower) address and MSB from odd (higher) address.
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top