English Amiga Board


Go Back   English Amiga Board > Coders > Coders. General

 
 
Thread Tools
Old 14 September 2010, 16:11   #1
CmdrVimes
Badge 177
 
CmdrVimes's Avatar
 
Join Date: Aug 2010
Location: Mirfield / UK
Posts: 77
Memory addressing

Hi chaps,

Can someone explain the difference between:
Code:
LEA        mylabel,a1
and
Code:
MOVE.l    mylabel(PC),a1
please?
CmdrVimes is offline  
Old 14 September 2010, 16:51   #2
hitchhikr
Registered User
 
Join Date: Jun 2008
Location: somewhere else
Posts: 521
If mylabel would look like this:

mylabel: dc.l $12345678

Then in the 1st case a1 will contain the memory address of mylabel and in the 2nd case it's content as 32 bit word ($12345678), 2nd case is usually used for pointers.
hitchhikr is offline  
Old 14 September 2010, 16:58   #3
CmdrVimes
Badge 177
 
CmdrVimes's Avatar
 
Join Date: Aug 2010
Location: Mirfield / UK
Posts: 77
Quote:
Originally Posted by hitchhikr View Post
2nd case it's content as 32 bit word ($12345678), 2nd case is usually used for pointers.
So I would use the second one if I want to write something into it? e.g.
Code:
MOVE.l        mylabel(PC),a1
MOVE.w        #45,(a1)
Is that what you mean?
CmdrVimes is offline  
Old 14 September 2010, 18:32   #4
Thorham
Computer Nerd
 
Thorham's Avatar
 
Join Date: Sep 2007
Location: Rotterdam/Netherlands
Age: 48
Posts: 3,810
Quote:
Originally Posted by CmdrVimes View Post
Is that what you mean?
They probably mean that the second form is used for retrieving a stored pointer, where the label points to the pointer storage space.

Basically, lea mylabel,a1 doesn't read from memory, and it just sets a1 to mylabel, while move.l mylabel(PC),a1 reads a 32 bit number from mylabel(pc) and stores it in a1.
Thorham is offline  
Old 15 September 2010, 12:46   #5
phx
Natteravn
 
phx's Avatar
 
Join Date: Nov 2009
Location: Herford / Germany
Posts: 2,525
For example:
Code:
        move.l  #myLabel,a1
        lea     myLabel,a1
...have the same effect. You will load the address of myLabel into A1 (LEA = Load Effective Address).
So why does LEA exist at all? Because you can load any effective address, which the immediate form of MOVE can't do:
Code:
        lea     myLabel(pc),a1
        lea     128(a0),a1
Code:
        move.l  myLabel(pc),a1
        move.l  myLabel,a1
...have the same effect too. Both will read a longword starting at myLabel. The PC-relative form has the advantage that it is a bit faster and saves two bytes.
phx is offline  
Old 24 October 2010, 00:51   #6
Lonewolf10
AMOS Extensions Developer
 
Lonewolf10's Avatar
 
Join Date: Jun 2007
Location: near Cambridge, UK
Age: 44
Posts: 1,924
Ok, maybe I'm being stupid or too tired too think straight (I have been coding for about 7 hours straight), but there must be a better way to code this:

Code:
lea.l   square(pc),a0
lea.l   screen+3160(pc),a1
bsr     drawbob
lea.l   square(pc),a0
lea.l   screen+2840(pc),a1
bsr     drawbob
lea.l   square(pc),a0
lea.l   screen+2520(pc),a1
bsr     drawbob
...
It's a snippet of some code used to add some bobs to the title screen of my demo. I know there must be a better way to do it (a loop of some sort), but my attempts either result in crashes or simply not possible to do!!
Can anyone point me in the right direction, please?


Regards,
Lonewolf10
Lonewolf10 is offline  
Old 25 October 2010, 09:45   #7
StingRay
move.l #$c0ff33,throat
 
StingRay's Avatar
 
Join Date: Dec 2005
Location: Berlin/Joymoney
Posts: 6,863
Just create a table with the coordinates of the bob and read these coords in a loop. Eg. have a table like this:
COORDSTAB dc.w 3160, 2840, 2520
dc.w -1 ; end marker

and the create a loop where you read the coords from the table and call your "drawbob" routine.
StingRay is offline  
Old 25 October 2010, 22:20   #8
Lonewolf10
AMOS Extensions Developer
 
Lonewolf10's Avatar
 
Join Date: Jun 2007
Location: near Cambridge, UK
Age: 44
Posts: 1,924
Quote:
Originally Posted by StingRay View Post
Just create a table with the coordinates of the bob and read these coords in a loop. Eg. have a table like this:
COORDSTAB dc.w 3160, 2840, 2520
dc.w -1 ; end marker

and the create a loop where you read the coords from the table and call your "drawbob" routine.
That is what I was aiming for, but my attempts just kept on crashing. I have finally got it working. I did try using "move.l (a3,d0.w),a1" (with the 3 preceeding lines commented out), but that doesn't work with .w, and simply crashes with .l
Atleast I have my own working code, even if it is a little ugly!


Code:
    moveq    #25,d7            ;number of coords-1
title_sq:
    move.w    (a2)+,d0        ;next coord -> d0
    move.l    a3,d1            ;screen address -> d1
    add.w    d0,d1            ;add coord to screen address
    move.l    d1,a1            ;move new address -> a1
*    move.l    (a3,d0.w),a1        ;was .l (crashes), .w doesn't work
    bsr    drawbob            ;ummm....
    dbra    d7,title_sq

Regards,
Lonewolf10
Lonewolf10 is offline  
 


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools

Similar Threads
Thread Thread Starter Forum Replies Last Post
question on resourcing relative addressing ara Coders. Asm / Hardware 5 04 February 2012 23:42
Blizzard Turbo Memory - SMD memory chips doesn't work sanjyuubi Hardware mods 5 26 May 2010 15:40
[68000 ASM] Move memory to memory AmigaBoy Coders. General 7 08 December 2009 08:16
Memory Addressing Architecture Zetr0 support.Hardware 2 10 July 2007 16:55
Addressing modes BippyM Coders. General 17 03 February 2005 09:57

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +2. The time now is 22:08.

Top

Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.
Page generated in 0.12464 seconds with 13 queries