ROM calls and other tricks

Basic and Machine Language

Moderator: Moderators

User avatar
J.E.E.K.
Vic 20 Drifter
Posts: 23
Joined: Wed Jan 25, 2017 12:31 pm
Website: http://klasek.at/8bit
Location: AT

Re: ML Optimization tips and tricks

Post 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.
Last edited by Mike on Sat Oct 24, 2020 2:34 pm, edited 1 time in total.
Reason: (near) full-quote shortened. Please refer to the OP by following the blue arrow link.
User avatar
bjonte
Vic 20 Hobbyist
Posts: 110
Joined: Sun Jan 22, 2017 5:47 am
Location: Gothenburg

Handy toggle

Post 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
User avatar
MrSterlingBS
Vic 20 Enthusiast
Posts: 174
Joined: Tue Jan 31, 2023 2:56 am
Location: Germany,Braunschweig

Re: ROM calls and other tricks

Post 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.
wimoos
Vic 20 Afficionado
Posts: 348
Joined: Tue Apr 14, 2009 8:15 am
Website: http://wimbasic.webs.com
Location: Netherlands
Occupation: farmer

Re: Handy toggle

Post 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.
VICE; selfwritten 65asmgen; tasm; maintainer of WimBasic
Post Reply