[Ti ASM] z flag to carry flag

Got questions? Got answers? Go here for both.

Moderator: MaxCoderz Staff

Post Reply
User avatar
Timendus
Calc King
Posts: 1729
Joined: Sun 23 Jan, 2005 12:37 am
Location: Netherlands
Contact:

[Ti ASM] z flag to carry flag

Post by Timendus »

A question for all you optimization gurus: What is the fastest and easiest way to get the z flag to the carry flag? I currently do it like this, but I'm 100% sure it can be done easier, probably in one opcode :P

Code: Select all

ztoc:
	jp z,ztoc_zero
	ld a,$FF
	rla    ; rotate set bit in carry flag
	ret
ztoc_zero:
	xor a
	rla    ; rotate reset bit in carry flag
	ret
http://clap.timendus.com/ - The Calculator Link Alternative Protocol
http://api.timendus.com/ - Make your life easier, leave the coding to the API
http://vera.timendus.com/ - The calc lover's OS
User avatar
Timendus
Calc King
Posts: 1729
Joined: Sun 23 Jan, 2005 12:37 am
Location: Netherlands
Contact:

Post by Timendus »

update:

Code: Select all

ztoc:
   jp z,ztoc_zero
   scf
   ret
ztoc_zero:
   scf
   ccf
   ret
http://clap.timendus.com/ - The Calculator Link Alternative Protocol
http://api.timendus.com/ - Make your life easier, leave the coding to the API
http://vera.timendus.com/ - The calc lover's OS
CoBB
MCF Legend
Posts: 1601
Joined: Mon 20 Dec, 2004 8:45 am
Location: Budapest, Absurdistan
Contact:

Post by CoBB »

My first idea would be something along your second version, but I’d use or a to clear the carry.

EDIT: second idea:

Code: Select all

scf
ret z ; or nz if you want to invert it
ccf
ret
It has the nice property of preserving S, Z and P/V too.
User avatar
Timendus
Calc King
Posts: 1729
Joined: Sun 23 Jan, 2005 12:37 am
Location: Netherlands
Contact:

Post by Timendus »

Ah, yes, nice one :)
http://clap.timendus.com/ - The Calculator Link Alternative Protocol
http://api.timendus.com/ - Make your life easier, leave the coding to the API
http://vera.timendus.com/ - The calc lover's OS
Post Reply