News:

Printed Amstrad Addict magazine announced, check it out here!

Main Menu
avatar_BSC

create a signed 16 bit offset from 8 bit

Started by BSC, 17:29, 26 March 14

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

BSC

Just wanted to have some Z80 NOP squeezing chit chat :)

I am doing this to convert a signed 8 bit value in A into a signed 16 bit value in DE:


    ld e,a      ; 1 copy lo-byte
    rlca        ; 2 rotate sign into carry flag
    ld a,0      ; 4 subtract from 0 ..
    sbc a       ; 5 with carry, effectively subtracting the carry flag from 0 => a is either 0 or -1
    ld d,a      ; 6 copy as hi-byte
    ; => signed offset value in de


Is there a faster way to do that? If not: :-P
** My SID player/tracker AYAY Kaeppttn! on github **  Some CPC music and experiments ** Other music ** More music on scenestream (former nectarine) ** Some shaders ** Some Soundtrakker tunes ** Some tunes in Javascript

My hardware: ** Schneider CPC 464 with colour screen, 64k extension, 3" and 5,25 drives and more ** Amstrad CPC 6128 with M4 board, GreaseWeazle.

TFM

#1
Quote from: BSC on 17:29, 26 March 14
Is there a faster way to do that? If not: :-P


Yes...


   
ld   e,a    ; 1 copy lo-byte   
rlca        ; 2 rotate sign into carry flag   
sbc  a,a    ; 3 with carry, effectively subtracting the carry flag from 0 => a is either 0 or -1     
ld   d,a    ; 4 copy as hi-byte    ; => signed offset value in de
TFM of FutureSoft
Also visit the CPC and Plus users favorite OS: FutureOS - The Revolution on CPC6128 and 6128Plus

BSC

Quote from: TFM on 17:59, 26 March 14

Yes...

   
ld   e,a    ; 1 copy lo-byte   
rlca        ; 2 rotate sign into carry flag   
sbc  a,a    ; 3 with carry, effectively subtracting the carry flag from 0 => a is either 0 or -1     
ld   d,a    ; 4 copy as hi-byte    ; => signed offset value in de



It seems that you are right ..
** My SID player/tracker AYAY Kaeppttn! on github **  Some CPC music and experiments ** Other music ** More music on scenestream (former nectarine) ** Some shaders ** Some Soundtrakker tunes ** Some tunes in Javascript

My hardware: ** Schneider CPC 464 with colour screen, 64k extension, 3" and 5,25 drives and more ** Amstrad CPC 6128 with M4 board, GreaseWeazle.

TFM

Auch ein blindes Huhn trinkt mal einen Korn oder so  ;)

TFM of FutureSoft
Also visit the CPC and Plus users favorite OS: FutureOS - The Revolution on CPC6128 and 6128Plus

Powered by SMFPacks Menu Editor Mod