[TI ASM] Optimizations

Got questions? Got answers? Go here for both.

Moderator: MaxCoderz Staff

User avatar
Jim e
Calc King
Posts: 2457
Joined: Sun 26 Dec, 2004 5:27 am
Location: SXIOPO = Infinite lives for both players
Contact:

Post by Jim e »

Man, now I wanna know what dwedit said. anyway, this a clearscreen routine, it was said somewhere else in prgm help. I figure it's good to put here too.

Code: Select all

;instead of

	ld hl,gbuf
	ld (hl),0
	ld de,gbuf+1
	ld bc,767
	ldir

; try this

Clearbuf:
	di	 	 ;becuase so many of you don't believe me when
	ld hl,0	; I say it is safe to have interrupts enabled.
	ld d,h
	ld e,l
	add hl,sp
	ld b,32
	ld sp,gbuf+768
CBloop:
	push de
	push de
	push de
	push de 
	push de
	push de
	push de
	push de
	push de
	push de
	push de
	push de
	djnz CBloop
	ls sp,hl
	ret
The ret can be removed if you are only clearing the screen once in you prgram, but if not call it to clear the screen.
Image
Kalimero
Regular Member
Posts: 130
Joined: Fri 17 Dec, 2004 1:47 pm

Post by Kalimero »

To check if a 16 bit value equals zero:

Code: Select all

ld a,h
or l
CoBB
MCF Legend
Posts: 1601
Joined: Mon 20 Dec, 2004 8:45 am
Location: Budapest, Absurdistan
Contact:

Post by CoBB »

Comparing two 16-bit values without destroying them:

Code: Select all

ld a,L1
sub L2
ld a,H1
sbc a,H2
This will also work with less arithmetic-friendly register pairs like BC and DE.
User avatar
MissingIntellect
Regular Member
Posts: 102
Joined: Tue 21 Dec, 2004 2:46 pm
Location: Santa Clarita, California
Contact:

Post by MissingIntellect »

Jim e wrote:anyway, this a clearscreen routine, it was said somewhere else in prgm help. I figure it's good to put here too.
I believe that it's CoBB's routine, though I may be mistaken. Quite ingenious.
CoBB
MCF Legend
Posts: 1601
Joined: Mon 20 Dec, 2004 8:45 am
Location: Budapest, Absurdistan
Contact:

Post by CoBB »

I use 8 pushes in mine, but it's indeed practically the same.
User avatar
Jim e
Calc King
Posts: 2457
Joined: Sun 26 Dec, 2004 5:27 am
Location: SXIOPO = Infinite lives for both players
Contact:

Post by Jim e »

I don't who first came up with it, but i know I've used that for more than 3 or 4 years.
Image
CoBB
MCF Legend
Posts: 1601
Joined: Mon 20 Dec, 2004 8:45 am
Location: Budapest, Absurdistan
Contact:

Post by CoBB »

I guess lots of people. It's not the most original idea around, really...
Gambit
Sir Posts-A-Lot
Posts: 252
Joined: Mon 21 Feb, 2005 5:34 am
Location: Laveen, Arizona

Post by Gambit »

Normally, you would use the following to increment a variable:

Code: Select all

ld a,(var)
inc a
ld (var),a
But if hl is not tied up and all you do is check flags, use indirection:

Code: Select all

ld hl,var
inc (hl)
ld a,(hl)   ;Optional
@AndySoft: I think you were confusing immediate numbers and addresses... well, here is how I keep it straight:

Code: Select all

ld hl,$5647     ;loads $56 -> h and $47 into l

Code: Select all

ld hl,86*256+71 ;also loads $56 -> h and $47 into l
Straight and simple. But lets say you want to store 0 -> (penCol) and 56 -> (penRow) with a 16-bit register; what I do is "reverse" them by imagining an X was drawn. So, by drawing the 'X', penCol should be first in the formula:

Code: Select all

ld hl,56*256+0         ;56 comes first
       \   /
        \ /
         X
        / \
       V   V
ld (penCol),hl
It would also be handy to remember that penCol comes before penRow and curRow comes before curCol. Hope this helps anyone who gets confused :)
"If SOURCE is outlawed, only outlaws will have SOURCE."
User avatar
benryves
Maxcoderz Staff
Posts: 3087
Joined: Thu 16 Dec, 2004 10:06 pm
Location: Croydon, England
Contact:

Post by benryves »

Gambit wrote:

Code: Select all

ld hl,86*256+71 ;also loads $56 -> h and $47 into l
Note that TASM will NOT compile that - you'd need to do it like this:

Code: Select all

ld hl,(86*256)+71 ;also loads $56 -> h and $47 into l
User avatar
Jim e
Calc King
Posts: 2457
Joined: Sun 26 Dec, 2004 5:27 am
Location: SXIOPO = Infinite lives for both players
Contact:

Post by Jim e »

I never had problems doing that. Though I know tasm doesn't do order of operations, it just goes in order from first to last.
Image
User avatar
benryves
Maxcoderz Staff
Posts: 3087
Joined: Thu 16 Dec, 2004 10:06 pm
Location: Croydon, England
Contact:

Post by benryves »

I'm using TASM 3.2, and it won't parse it correctly for me...
User avatar
Jim e
Calc King
Posts: 2457
Joined: Sun 26 Dec, 2004 5:27 am
Location: SXIOPO = Infinite lives for both players
Contact:

Post by Jim e »

so am i.
Tasm wrote:Version 3.2b Feb, 2000
Image
DarkerLine
Calc Wizard
Posts: 526
Joined: Tue 08 Mar, 2005 1:37 am
Location: who wants to know?
Contact:

Post by DarkerLine »

Gambit wrote:

Code: Select all

ld hl,$5647     ;loads $56 -> h and $47 into l

Code: Select all

ld hl,86*256+71 ;also loads $56 -> h and $47 into l
But the opcode for that is $21 $47 $56, not $21 $56 $47, for those of us who are on-calc-inclined.
just try to be nice to people.
_________________
My TI Blog - http://mpl.unitedti.org/
Stickmanofdoom
Regular Member
Posts: 86
Joined: Fri 17 Dec, 2004 8:20 pm
Contact:

Post by Stickmanofdoom »

You might want to check out http://www.shiar.org/ticalcs/z80optim.php for many optimizations.

Fast ways to divide A by powers of 2:

Code: Select all

div_2:
srl a
ret

div_4:
rra
rra
and %00111111
ret

div_8:
rra
rra
rra
and %00011111
ret

div_16:
rra
rra
rra
rra
and %00001111
ret

div_32:
rlca
rlca
rlca
and %00000111
ret

div_64:
rlca
rlca
and %00000011
ret

div_128:
rlca
and %00000001
ret
Thanks to CoBB for pointing out the div_8 to me.
koolmansam375
Extreme Poster
Posts: 479
Joined: Fri 17 Dec, 2004 11:09 pm
Contact:

Post by koolmansam375 »

Yea i didnt know the ordering :-/ . You might have to switch it around to make it work correctly :p

well another optimization! : if you need to do (in either direction

Code: Select all

 ld h,d
ld l,e
instead use

Code: Select all

 ex hl,de
also a useful instruction if you use either in a routine and need to save the other.
Image

Pongwars shall live!

blog is down atm. :-(
Post Reply