Reputation: 19
I have to Write a code in 6502 assembly language that divides 256-bit numbers by 64-bit numbers using basic bit shift operations, and arithmetic and logic operations. i just don't know how to write 256 and 64 bit number in assembly 6502.
Upvotes: 1
Views: 643
Reputation: 39166
i just don't know how to write 256 and 64 bit number in assembly 6502.
You would store these as strings of 32 and 8 bytes respectively.
In memory, the qword number $1122334455667788 would look like these 8 bytes:
$88, $77, $66, $55, $44, $33, $22, $11
Similar and 4 times longer for a 256-bit number.
To get an idea of how to work with multibyte numbers. This is the addition of a couple of 16-bit numbers.
If NumA is $1122 and NumB is $3344, then the sum will be Res:
CLD
CLC
LDA NumA ; -> A = $22
ADC NumB ; -> A = $22 + $44 = $66
STA Res
; The carry propagates to the higher order addition
LDA NumA+1 ; -> A = $11
ADC NumB+1 ; -> A = $11 + $33 = $44
STA Res+1
Res now holds the sum $4466.
Working with very big numbers will require a loop. Next is the addition of two qwords:
CLD
CLC
LDY #8 ; Qwords have 8 bytes
LDX #0
Loop:
LDA NumA,X
ADC NumB,X
STA Res,X
INX ; INX and DEY don't clobber the carry
DEY ; and thus it can propagate
BNE Loop
Upvotes: 3