
218 Assembly Language Programming for the 68000 Family
movem.l (sp)+,dl-d2
rts
restore registers
return
The following subroutine to output a decimal number perforins this
operation by successively dividing the number by ten to pick off the
digits. These digits are pushed onto the stack. When the number
has been converted, the digits are popped from the stack and output.
A double precision divide is needed to accommodate a 32 bit number.
outdec: movem.l d0-d3,-(sp)
move.w #-l,-(sp)
tst.l dO
beg outdecz
* divide by ten to pick up digit value
* keep doing this until number is zero
outdecOi
! tSt.l dO
beq
outdecl
move.w
d0,d2
clr .w
dO
swap
dO
divu
110,dO
move.w
d0,d3
move.w d2,d0
divu
*10,dO
swap dO
move.w
dO,-(sp)
move.w
d3,d0
swap
dO
bra outdecO
*we now
output th« number
outdecl:
:move.w (sp)+,dO
bmi
outdec2
and.l
««llll,dO
outdecz
:add.b
#’0',d0
jsr
putc
bra
outdecl
outdec2
:movem.l
(sp)+,d0-d3
*
rts
cr:
equ
?0d
If:
equ
$0a
newline
rmove.l
dO,-(sp)
move.b
#cr,d0
jsr
putc
move.b
#lf,d0
jsr
putc
move.1
rts
(sp)+,dO
save reg. values
push -1 onto stack
zero value?
yes, make sure we output a 0
as remainder
finished?
yes, output the number
save low order word in d2
clear low order word
get high order word in low order word
divide by ten
save remainder in d3
get low order word back
divide by ten
swap quotient and remainder words
save remainder as digit value
get old remainder in low order word
fix up so result is full 32 bit quotient
divide by ten again
get a digit from the stack
terminate on -1
mask
make digit into ascii char
output
continue to next digit
restore registers
return
ascii car ret
ascii line feed
save reg. dO
output a car ret
output a line feed
restore dO
return
end
Komentáře k této Příručce