Skip to content

Instantly share code, notes, and snippets.

@thebird
Created November 16, 2010 03:02
Show Gist options
  • Save thebird/701355 to your computer and use it in GitHub Desktop.
Save thebird/701355 to your computer and use it in GitHub Desktop.
ORG $3000
hex ds.w 1 ; $3000-01
div ds.w 1 ; $3002-03
temp ds.b 1 ; $3004-05
ORG $3010
bcd ds.w 3 ; $3010-13
ORG $3020
asc ds.w 3 ; $3020-25
; code section
MyCode: SECTION
main:
_Startup:
Entry:
; load initial variables
MOVW #$000A,div ; load 10 into div
LDX div ; load div into X
; convert to bcd
LDD hex ; load hex into D
LDY bcd ; reference asc in Y
IDIV ; divide D by X, result in X, remainder in D
STAB temp ; store temp variable for digit correction
TFR X,D ; place result X back into D
LDX div ; reload X with 10 (div)
IDIV ; divide D by X, result in X, remainder in D
LDAA #$10 ; load $10 for digit correction
MUL ; multiply $10 times division result
ADDB temp ; add to prev temp variable
STAB $3012 ; ?,Y ; store in manual position 3
TFR X,D ; place result X back into D
LDX div ; reload X with 10 (div)
IDIV ; divide D by X, result in X, remainder in D
STAB temp ; store temp variable for digit correction
TFR X,D ; place result X back into D
LDX div ; reload X with 10 (div)
IDIV ; divide D by X, result in X, remainder in D
LDAA #$10 ; load $10 for digit correction
MUL ; multiply $10 times division result
ADDB temp ; add to prev temp variable
STAB $3011 ; ?,Y ; store in manual position 3
TFR X,D ; place result X back into D
LDX div ; reload X with 10 (div)
IDIV ; divide D by X, result in X, remainder in D
STAB temp ; store temp variable for digit correction
TFR X,D ; place result X back into D
LDX div ; reload X with 10 (div)
IDIV ; divide D by X, result in X, remainder in D
LDAA #$10 ; load $10 for digit correction
MUL ; multiply $10 times division result
ADDB temp ; add to prev temp variable
STAB $3010 ; ?,Y ; store in manual position 3
TFR X,D ; place result X back into D
LDX div ; reload X with 10 (div)
; convert to ascii
LDY asc ; reference asc in Y
LDAA #$00 ; load temp value 00 in A
STAA $3025 ; 5,Y ; store 00 in last position of asc
LDD hex ; reload hex into D - after calculations with A
IDIV ; divide D by X, result in X, remainder in D
ADDD #$30 ; add 30 to D
STAB $3024 ; 4,Y ; store remainder and last addition into pos 4 of asc
TFR X,D ; place result X back into D
LDX div ; reload X with 10 (div)
IDIV ; identical to previous 5 steps but store in pos 3
ADDD #$30
STAB $3023 ; 3,Y
TFR X,D
LDX div
IDIV ; identical to previous 5 steps but store in pos 2
ADDD #$30
STAB $3022 ; 2,Y
TFR X,D
LDX div
IDIV ; identical to previous 5 steps but store in pos 1
ADDD #$30
STAB $3021 ; 1,Y
TFR X,D
LDX div
IDIV ; identical to previous 5 steps but store in pos 0
ADDD #$30
STAB $3020 ; 0,Y
TFR X,D
LDX div
endmain BRA endmain
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment