Author Topic: create a signed 16 bit offset from 8 bit  (Read 767 times)

0 Members and 1 Guest are viewing this topic.

Offline BSC

  • CPC6128
  • ****
  • Posts: 276
  • Country: de
  • CPC 464 aspirant
    • my (Android) mobile game
  • Liked: 377
  • Likes Given: 307
create a signed 16 bit offset from 8 bit
« on: 18:29, 26 March 14 »
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:

Code: [Select]
    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

Offline TFM

  • Visit the mysteries of the CPC at www.futureos.de
  • Supporter
  • 6128 Plus
  • *
  • Posts: 9.899
  • Country: aq
  • Space Chicken for FutureOS is free!
    • index.php?action=treasury
    • FutureOS - The revolution on CPC!
  • Liked: 1983
  • Likes Given: 4650
Re: create a signed 16 bit offset from 8 bit
« Reply #1 on: 18:59, 26 March 14 »
Is there a faster way to do that? If not: :-P


Yes...


Code: [Select]
   
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
« Last Edit: 19:04, 26 March 14 by TFM »
TFM of FutureSoft
Also visit the CPC and Plus users favorite OS: FutureOS - The Revolution on CPC6128 and 6128Plus

Offline BSC

  • CPC6128
  • ****
  • Posts: 276
  • Country: de
  • CPC 464 aspirant
    • my (Android) mobile game
  • Liked: 377
  • Likes Given: 307
Re: create a signed 16 bit offset from 8 bit
« Reply #2 on: 22:14, 26 March 14 »

Yes...

Code: [Select]
   
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 ..

Offline TFM

  • Visit the mysteries of the CPC at www.futureos.de
  • Supporter
  • 6128 Plus
  • *
  • Posts: 9.899
  • Country: aq
  • Space Chicken for FutureOS is free!
    • index.php?action=treasury
    • FutureOS - The revolution on CPC!
  • Liked: 1983
  • Likes Given: 4650
Re: create a signed 16 bit offset from 8 bit
« Reply #3 on: 23:07, 26 March 14 »
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