Page 3 of 3
Re: ML Optimization tips and tricks
Posted: Sat Oct 24, 2020 9:02 am
by J.E.E.K.
wimoos wrote: ↑Wed Dec 12, 2012 4:27 amRemove NOP’s
[...]
This list could be extended by
- Hold flag in bit 7 of a location, so you can check the flag by "BIT flag" followed by "BMI/BPL destination" keeping A untouched, clear the flag with "LSR flag". If carry is set by an condition before, use "ROR flag" to set the flag.
- Operations without temporarily save the accumulator to memory:
- To subtract the value in A from location's value ( (mem)-A ) use EOR #$FF; SEC; ADC mem (negate A with two's complement and simply add).
- Merge some bits from A into a memory location using EOR mem; AND #mask_bits_taken_from_acc; EOR mem; STA mem.
Handy toggle
Posted: Mon Jul 04, 2022 2:34 pm
by bjonte
Sometimes you want to toggle a memory location between two values. This can be done using EOR. The value to use for EOR can be constructed with eor in the assembler (operator ^ in this example).
Code: Select all
// constants to toggle between
const value1 = 55
const value2 = 170
// set initial value
lda #value1
sta memaddr
// toggle
lda memaddr
eor #value1 ^ value2
sta memaddr
Re: ROM calls and other tricks
Posted: Sat Feb 03, 2024 12:19 pm
by MrSterlingBS
Sometimes I used
STY $ZP
… some code
LDY $ZP
instead of
TYA
PHA
… some code
PLA
TAY
A little bit faster and shorter code if you have some ZP registers free.
Re: Handy toggle
Posted: Mon Feb 05, 2024 1:50 am
by wimoos
bjonte wrote: ↑Mon Jul 04, 2022 2:34 pm
Sometimes you want to toggle a memory location between two values. This can be done using EOR. The value to use for EOR can be constructed with eor in the assembler (operator ^ in this example)
To elaborate on this, consider the following code snippet that I used in WimBasic:
Code: Select all
EOR #$82 ; token NEXT ?
BEQ LA3D6
EOR #$9C ^ $82 ; token CLR
BEQ LA3F3
EOR #$8E ^ $9C ; token RETURN
BEQ LA46C
JMP $CF08 ; ?SYNTAX ERROR
;
LA3D6 TAY ; clear Y
...
LA46C
The code is entered with a tokenized value in A, that needs to be checked against three possible values. The code, following the selection benefits from having a value of zero in A (or could benefit from the carry-flag not having been changed).
Regards,
Wim.