How to use floating point kernal routines for 16 bit arithmetics such as: $1234*$ABCD or $1234/$ABCD ?
There's a great and much detailed description at the C64 Wiki (*1) describing the basic structures and workings, as well as all functions involved to use the ROM routines for floating point (*2)
GIVAYFto convert a 16 Bit number in A:Y into an FP in FAC
- If multiple numbers are involved, move FAC to memory using
- Repeat for all numbers
- Do whatever function is needed, like
FMULTfor multiplication (FAC times saved value)
FACINXto convert the result from FAC back into a 16 bit in A:Y
QINTif you expect the result to need a 32 bit integer - like with a 16x16 multiplication.
As usual, countless variations thereof are possible, depending on the task at hand and requirements set.
*1 - Thanks to JeremyP for that link
*2 - Which BTW are not part of the Kernel, but belong to BASIC as Wilson pointed out :))
Consider this an addendum to Raffzahn's answer. If you are going to accept one, accept his.
The code for your first multiplication might look like this (note I haven't tested this)
lda #$12 ldy #$34 jsr GIBAYF lda some_memory_loc_low_byte ldy some_memory_loc_highbyte jsr MOVEFM lda $AB ldy $CD jsr GIBAYF lda some_memory_loc_low_byte ldy some_memory_loc_highbyte jsr FMULT jsr FACINX ; Answer in A:Y
That's going to be a lot slower than doing the 16 bit multiplication directly though.