Page 1 of 2

[TI ASM] Asm Help

Posted: Mon 20 Dec, 2004 3:51 pm
by L-Man
well ionlargesprite uses the adress of ix to find the sprite right? well why cant you load the adress somewhere else like this:

Code: Select all

ld hl,TempSprite
ld (hl),MarioSprite
is there some way to do this?

Posted: Mon 20 Dec, 2004 3:56 pm
by kv83
yes, you can store the adress in hl... if you want to to retrieve to get the adress from hl to ix, you can do that by simply:

Code: Select all

push hl
pop ix
I am not sure if that's what you asking though

umm

Posted: Tue 21 Dec, 2004 5:08 pm
by L-Man
no not really!
k i want to load the adress of a sprite MarioRight in to a temporary variable called TempSprite so i can call ionlargesprite with
ld ix,TempSprite
and having tempsprite have the adress of MarioRight so when i call ionlargesprite it loads MarioRight Sprite.

Thats my question

Posted: Tue 21 Dec, 2004 5:25 pm
by kv83
than you need two variables, because a adress is a 16bit register.

storing the adress (located in hl) would go like

Code: Select all

ld a,h
ld (tempSpriteAdress),a
ld a,l
ld (tempSpriteAdress+1),a
and I think you can guess how loading goes... :)

to use it with the ion routine, you have to load it of course... it's not just simply ix,tempspriteadress... there is a difference between loading data and loading a pointer :)

Posted: Wed 22 Dec, 2004 10:57 am
by tr1p1ea
If you want to store it in HL you would have to do something akin to:

Code: Select all

ld a,(hl)
inc hl
ld h,(hl)
ld l,a

Posted: Wed 22 Dec, 2004 11:48 am
by kv83
I don't think what you are trying to do is possible tr1p...

Code: Select all

ld a,(hl) 
inc hl 
ld h,(hl) 
ld l,a
would be rather:

Code: Select all

ld a,(hl) 
ld b,a
inc hl
ld a,(hl)
ld h,a
ld l,b

Posted: Wed 22 Dec, 2004 12:55 pm
by CoBB
You're wrong, Vincent, and tr1p is right. Also, referring to your previous post, LD (ArbitraryAddress), HL is also possible. Check out my LD table if you don't believe me. ;) BTW you have some endianness problem there, the high byte comes after the low byte in the Z80.

Posted: Wed 22 Dec, 2004 2:20 pm
by kv83
CoBB wrote:You're wrong, Vincent, and tr1p is right. Check out my LD table if you don't believe me. ;)
Hmmm... I already was afraid, that my thoughts would be wrong ;) ... Don't worry, how couldn't I believe one of the z80 gods :P
CoBB wrote:Also, referring to your previous post, LD (ArbitraryAddress), HL is also possible.
so if you do LD (ArbitraryAddress),HL where will it go? It doesn't fit in a 8bit register I suppose, so it most likely will use both (ArbitraryAddress) and (ArbitraryAddress+1),right? and does that mean that LD HL,(Arbitrary Adress) does also work?
CoBB wrote:BTW you have some endianness problem there, the high byte comes after the low byte in the Z80.
endianness problem? I don't get it... :oops:

Posted: Wed 22 Dec, 2004 4:24 pm
by CoBB
As stated in my previous post: the low byte goes to Address, the high byte to Address+1. And yes, it's possible the other way around, too.

Endianness is exactly the specification of byte order. Z80 and Intel CPUs are little endian, i. e. numbers are stored with their lowest byte first. As opposed to this, Motorola CPUs are bigendian, storing everything in the exact opposite order.

Posted: Wed 22 Dec, 2004 8:58 pm
by tr1p1ea
Yes so if you were to store say $FEBC at your ArbitraryAddress (on a z80), in memory it would look like:

(ArbitraryAddress) = $BC
(ArbitraryAddress+1) = $FE

Is this right?

Posted: Wed 22 Dec, 2004 11:07 pm
by L-Man
so if im understanding correctly from you guys i can do this:

Code: Select all

ld hl,MarioSprite
ld (TempSprite),hl
....
....
...
ld ix,TempSprite
call ionlargeSprite
call ionfastcopy
right or am i not using inderection? or something else
thanks

Posted: Thu 23 Dec, 2004 1:35 am
by CalcKing
Since you stored hl (the pointer) to the memory location TempSprite, you will have to use indirection to get the pointer data into ix.

Code: Select all

ld hl,MarioSprite
ld (TempSprite),hl
....
....
...
ld ix,(TempSprite)
call ionlargeSprite
call ionfastcopy

Posted: Thu 23 Dec, 2004 10:57 am
by CoBB
Actually, it's not that hard to see how it works. All you have to understand is that every symbol (labels you defined) is turned into a number. If TempSprite is $9000 and MarioSprite $9876 for instance, the resulting code will be:

Code: Select all

ld hl,$9876
ld ($9000),hl
Now obviously, if you want to retrieve the value stored at $9000, you shouldn't write

Code: Select all

ld ix,$9000
since that sets ix to $9000 by definition.

Code: Select all

ld ix,($9000)
does the job, ix will be $9876 unless you overwrote the byte at $9000 or $9001 in the meantime.

THANKS!

Posted: Thu 23 Dec, 2004 6:19 pm
by L-Man
You guys are awesome!!!!!! I get it now! :D :D :D

Posted: Thu 30 Dec, 2004 3:51 pm
by tr1p1ea
You know that you can also do:

Code: Select all

ld hl,TempSprite
push hl
pop ix
This is only if you want to get whats in hl to ix ... which i dont know if this is what you want or not?