2019-03-21 14:59:45 +00:00
|
|
|
; mul20.s
|
|
|
|
;
|
|
|
|
; This file is part of
|
|
|
|
; cc65 - a freeware C compiler for 6502 based systems
|
|
|
|
;
|
|
|
|
; https://github.com/cc65/cc65
|
|
|
|
;
|
|
|
|
; See "LICENSE" file for legal information.
|
|
|
|
;
|
|
|
|
;
|
2019-03-29 21:36:01 +00:00
|
|
|
; unsigned int __fastcall__ mul20(unsigned char value);
|
2019-03-21 14:59:45 +00:00
|
|
|
;
|
|
|
|
; REMARKS: Function is defined to return with carry-flag cleared
|
|
|
|
|
|
|
|
|
|
|
|
.importzp tmp4
|
2019-03-29 21:36:01 +00:00
|
|
|
.export _mul20
|
2019-03-21 14:59:45 +00:00
|
|
|
|
2019-03-29 21:36:01 +00:00
|
|
|
.proc _mul20 ; = 30 bytes, 41/46 cycles
|
2019-03-21 14:59:45 +00:00
|
|
|
|
|
|
|
sta tmp4 ; remember value for later addition...
|
|
|
|
ldx #0 ; clear high-byte
|
|
|
|
asl a ; * 2
|
|
|
|
bcc mul4 ; high-byte affected?
|
|
|
|
ldx #2 ; this will be the 1st high-bit soon...
|
|
|
|
|
2019-03-29 21:36:01 +00:00
|
|
|
mul4: asl a ; * 4
|
2019-03-21 14:59:45 +00:00
|
|
|
bcc mul5 ; high-byte affected?
|
|
|
|
inx ; => yes, apply to 0 high-bit
|
|
|
|
clc ; prepare addition
|
|
|
|
|
|
|
|
mul5: adc tmp4 ; * 5
|
|
|
|
bcc mul10 ; high-byte affected?
|
|
|
|
inx ; yes, correct...
|
|
|
|
|
|
|
|
mul10: stx tmp4 ; continue with classic shifting...
|
|
|
|
|
|
|
|
asl a ; * 10
|
2019-03-29 21:36:01 +00:00
|
|
|
rol tmp4
|
2019-03-21 14:59:45 +00:00
|
|
|
|
2019-03-29 21:36:01 +00:00
|
|
|
asl a ; * 20
|
2019-03-21 14:59:45 +00:00
|
|
|
rol tmp4
|
|
|
|
|
|
|
|
ldx tmp4 ; deliver high-byte in X
|
|
|
|
rts
|
|
|
|
|
|
|
|
.endproc
|