But for it to work for all 2-complement coded values we need to ensure that the MSB is copied back into itself to keep the value the same sign, which can be done with another shift.
; Divide a signed 16-bit value by 2
LDA MEM+1 ;Load the MSB
ASL A ;Copy the sign bit into C
ROR MEM+1 ;restore MSB
ROR MEM+0 ;Rotate the LSB
It's a bunch of cycles but nothing compared to a generic division.
ROL rotate left
ROR rotate right
ASL arithmetic shift left
LSR logic shift right
But for it to work for all 2-complement coded values we need to ensure that the MSB is copied back into itself to keep the value the same sign, which can be done with another shift.
; Divide a signed 16-bit value by 2
It's a bunch of cycles but nothing compared to a generic division.