Calculator Community > ASM

Assembly Coding Optimization

(1/7) > >>

Halifax:
Ok I have compiled this code from MaxCoderz and figured it would be useful for some ASM programmers over here. You all can post your own routines and optimized stuff here too.


Optimization 1 - Loading 0 into A
----------------------------------
Unoptimized
c1-->CODE ec1
ld a,0
c2ec2
to
c1-->CODE ec1
xor a

or

sub a,a
c2ec2

ld a,0 is unoptimized because it takes more bytes and tstates than both "xor a" and "sub a,a". They both do the same as ld a,0
------------------------------------


Optimization 2 - Comparing the value 0
------------------------------------
Unoptimized
c1-->CODE ec1
cp 0
c2ec2
to
c1-->CODE ec1
or a
c2ec2

same with above. "or a" takes less space and tstates than "cp 0" and does the same thing.
-------------------------------------


Optimization 3 - Loading numbers into register pairs
-------------------------------------
Unoptimized
c1-->CODE ec1
ld b,$88
ld c,$45
c2ec2
to
c1-->CODE ec1
ld bc,$8845
c2ec2

the first one takes 14 tstates while "ld bc,$8845" only takes 10 tstates. It is self-explanatory that what goes in B comes first and C comes after.
---------------------------------------


Optimization 4 - Loading a Pic onto the screen (SPEED OPTIMIZATION)
---------------------------------------
Unoptimized
c1-->CODE ec1
ld hl,gbuf
ld de,pic
ld bc,768
ldir
c2ec2
to
c1-->CODE ec1
ld hl,gbuf
ld de,pic
ld bc,768

copyfast:
 

Fallen Ghost:
For #5:

Why should interrupts be enabled?

If an interrupt triggers, it will return correctly (lets suppose) and let the stack at the same value, therefore not modifying the bytes you are going to have when you push, so the result is the same.
But as we know, interrupts can trigger anytime. If it happens that the interrupt is triggered when b=1 and there is only a couple pushes to do, then if in the interrupt routine, there are more pushes than the number remaining in your routine, then whatever data was before the buffer will be erased/modified, so it is no a good idea, therefore interrupts disabled.

Halifax:
Fallen_Ghost none of those routines belong to me. They were copied right from Maxcoderz. I just pasted them in here as I stated in the top of my post up there

QUOTE
Ok I have compiled this code from MaxCoderz and figured it would be useful for some ASM programmers over here. You all can post your own routines and optimized stuff here too.

calc84maniac:
If you don't want the flags affected use ld a,0 instead of xor a

Jon:
Here's a simple size optimization for direct input:
Instead of:
c1-->CODE ec1
out (1),a
nop
nop
in a,(1)
c2ec2

Use:
c1-->CODE ec1
out (1),a
ld a,(de)
in a,(1)
c2ec2

LD A,(DE) creates the same delay as 2 NOP's, but it takes 1 byte instead of 2

Navigation

[0] Message Index

[#] Next page

Go to full version