Dead Hackers Society
Other BBSes »
 
 
Demoscene   Coding   CT60   Buy/sell

Atari demoscene BBS
 
Re: 68000 assembler
Posted by: ray Jun,14.2003-21:45 

ok, i hope the bbs-script doesn't screw it...i've quickly made up this basic hack for you, to show you the "principle" ;) - hopefully this helps



;========================================
;=
;= Percentage calculator
;=
;= by ray//.tSCc. 2k3
;========================================

opt p=68000 ; Just to make sure that i typed
section text ; valid 68000 code :)

; 1,2, this is just a test
move.w #475,d0 ; 475 of 8343 should be ~5.69%
move.w #8343,d1 ; according to my calculator
bsr.s CalcPercentage

bsr.s WordToBCD ; Better than having to convert
; a hex-number, manually :)

illegal ; Use a debugger to view the content
; of d1.l here



;========================================
;=
;= CalcPercentage(portion:d0.w,entirety:d1.w)
;= returns percentage:d0.w
;=
;========================================


CalcPercentage mulu.w #100<<8,d0
divu.w d1,d0 ; Percentage in 8.8 fixed
rts ; Well that's it


;========================================
;=
;= d1.l WordToBCD(d0.w)
;=
;= Convert an 8.8 fixedpoint number into
;= a handy 4.4-digit BCD format
;=
;= Kills d2.l
;========================================

WordToBCD move.w d0,d2
lsr.w #8,d2 ; Magnitude
andi.w #$ff,d0 ; Fraction
mulu.w #100,d0

ext.l d2 ; Prepare for division

; Convert magnitude
moveq.l #0,d1

divu.w #100,d2
move.b d2,d1
lsl.w #4,d1

clr.w d2
swap.w d2 ; Remainder
divu.w #10,d2
or.b d2,d1
lsl.w #4,d1
swap.w d2
or.b d2,d1

swap.w d1
moveq.l #0,d2

; Convert fraction and remove leading 0s (sloppy version)
divu.w #100<<8,d0
move.b d0,d1
bne.s .l1
addq.w #4,d2 ; Count leading 0s
.l1 lsl.w #4,d1

clr.w d0
swap.w d0
divu.w #10<<8,d0
tst.b d0
bne.s .l2
tst.b d2
bne.s .l2

addq.w #4,d2
.l2 or.b d0,d1

lsl.w #4,d1
rol.l #8,d0
tst.b d0
bne.s .l3
tst.b d2
bne.s .l3
addq.w #4,d2
.l3 or.b d0,d1

addq.w #4,d2
lsl.w d2,d1 ; Left align fraction
rts







[All messages in this thread]    [Start new thread]

Topic Posted by  Date 
68000 assembler Bod/STAX Jun,14.2003-18:03
  Re: 68000 assembler ray Jun,14.2003-21:45
    Re: 68000 assembler Bod/STAX Jun,14.2003-22:12
      Re: 68000 assembler ray Jun,15.2003-14:32


Reply to this message
Name:
Topic:
Anti-troll code:

Message:

What's the anti-troll code?
That's your personal code to be able to add comments and messages on the dhs.nu site.
Don't have a code or forgot it? Fix it here.
© 1994-2025 Dead Hackers Society Contact: Anders Eriksson