User Tools

Site Tools


base:signed_8bit_16bit_addition

To add a signed 8-bit delta to a 16-bit value, we need to sign-extend the delta to a full 16 bits. We hold the high byte of the delta in .X and set it to $00 or $ff based on its sign:

 ldx #$00  ; implied high byte of delta
 lda delta
 bpl :+
  dex      ; high byte becomes $ff to reflect negative delta
:clc
 adc value ; normal 16-bit addition
 sta value
 txa
 adc value+1
 sta value+1

White Flame

base/signed_8bit_16bit_addition.txt · Last modified: 2017-10-26 07:30 by white_flame