Ich möchte eine 16-Bit-Nummer durch zwei teilen. Meine Lösung für das Problem war, wie untenWie teilt man 16-Bit-Nummer durch 2 in 6502 Asm?
lda $17 ;set high byte
ldx $32 ;set low byte
divide:
PHA ;push A to stack
TXA ;X > A
LSR ;divide low byte by 2
TAX ;A > X
PLA ;pull A from stack
LSR ;divide high byte by 2
BCC + ;C=0, skip
PHA ;while C=1
TXA ;add $80 to the lsb
ADC#$80
TAX
PLA
+
+printDecimal $0400+120
Alle PHA/PLA
Tricks ist, weil mein printDecimal
Makro MSB von A liest und LSB von X.
Wenn ich Alternativen online überprüfen, fand ich 4 Anweisung Alternative zu meiner bescheidenen Division Routine. Aber ich habe es nicht verstanden.
div2:
LDA counter_hi ;Load the MSB
ASL ;Copy the sign bit into C
ROR counter_hi ;And back into the MSB
ROR counter_lo ;Rotate the LSB as normal
LDA counter_hi
LDX counter_lo
+printDecimal $0400+40
Wie funktioniert das?
LSR = CLC + ROR – i486
diese. Multiplikation und Division durch (Vielfache von) Zwei sind nichts anderes als Bitverschiebungen nach links oder rechts. 'LSR hi-byte, ROR lo-byte' erreicht Ihr 16-bit-Divisionsziel ohne viele Schleifen, Register-Swaps usw. –
@ i486. Danke i486. Ich habe die Antwort bearbeitet. – Hoopje