Re: 68K/68332 Assembly/Binary Problem
- From: Herbert Kleebauer <klee@xxxxxxxxx>
- Date: Sat, 31 Mar 2007 08:29:44 +0200
kevinor@xxxxxxxxx wrote:
Is there a way to convert decimal to binary/hex and back without
needing large division and multiplication commands? I've considered
manually coding division and multiplication subroutines but after
designing a multiplication algorithm which takes way too many clock
cycles; is there another way to proceed?
We already had this last week. Here a x86 version, but maybe
it looks more familiar to a 68k programmer than to a x86 programmer.
@=$100
size=16 ; size in 32 bit words must be >=2
move.l #dec_ascii,r3
bsr.l atoi
bsr.l dec_dump
rts.w
atoi: move.l #result,r6
move.l #size,r2
eor.l r0,r0
rep_r2 move.l r0,(r6)+-{s1}
move.l #10,r6
_20: movu.bl (r3),r2
inc.l r3
cmp.b #'9',r2
bhi.l _done
sub.b #'0',r2
bcs.l _done
move.l #result,r5
eor.l r4,r4
_10: move.l (r5,r4*4),r0
mulu.l r6,r0,r1|r0
add.l r2,r0
addcq.l #0,r1
move.l r0,(r5,r4*4)
move.l r1,r2
inc.l r4
cmp.l #size-1,r4
bls.b _10
br.b _20
_done: rts.l
dec_ascii: dc.b "1234567890123456789011223344556677889900111222333444555",0
dec_dump:
move.l #10,r3
move.l #text_out_end,r6
_20: move.l #result,r5
move.l #size-1,r4
eor.l r1,r1
eor.l r2,r2
_10: move.l (r5,r4*4),r0
divu.l r3,r1|r0
move.l r0,(r5,r4*4)
or.l r0,r2
dec.l r4
bpl.b _10
add.b #'0',r1
dec.l r6
move.b r1,(r6)
tst.l r2,r2
bne.b _20
subq.l #4,r6
move.l #$0a0d0a0d,(r6)
move.b #$40,m0
move.w r6,r1
move.l #text_out_end,r2
sub.w r1,r2
move.w #1,r3
trap #$21
rts.l
even 4
result: blk.l size
tmp: blk.l size
text_out: blk.b size*10+10
text_out_end:
.
- References:
- 68K/68332 Assembly/Binary Problem
- From: kevinor
- 68K/68332 Assembly/Binary Problem
- Prev by Date: Re: cFASM (calling FASM as a C function)
- Next by Date: Re: newbie: MUL product
- Previous by thread: Re: 68K/68332 Assembly/Binary Problem
- Index(es):