Motorola M68000 User's Guide Page 67

  • Download
  • Add to my manuals
  • Print
  • Page
    / 256
  • Table of contents
  • BOOKMARKS
  • Rated. / 5. Based on customer reviews
Page view 66
Getting Started 53
SPA CE: EQU
$2 0
*
MOVEW
# 3 0 ,D1
MLOOP:
MOVE•L
EXP,DO
JS R
OUTDEC
ADDQ.L
# 1 ,E X P
MOVE•B
# SPACE,DO
JS R
PUTC
MOVEL
POWER,DO
JS R
OUTDEC
AD D.L DO, DO
MOVE. L
DO,POWER
JS R
NEWLINE
DBRA
Dl,M LOOP
*
E X P :
D C .L 1
POWER:
D C .L
2
A S C II SPACE
SET UP LOOP COUNT
GET CURRENT EXPONENT
OUTPUT
INCREMENT EXPONENT
OUTPUT A SPACE
n
GET CURRENT POWER
OUTPUT
DOUBLE IT
AND SAVE
GO TO A NEW LIN E
LOOP UNTIL DONE
WE CONTINUE HERE
Figure 7 Program to output powers of two.
Putting It All Together
Figure 7 shows a complete program that will output a table of the
powers of 2 from 21 to 231. As you learned in Chapter 1, 231 is the largest
power of 2 that can be represented with a 32-bit unsigned number. The
program is written as one counting loop. The D1 register is initialized
to 30, which is the number of powers that we wish to output minus one.
MLOOP is the label referenced by the DBRA instruction, which is the last
instruction of the program prior to the return to the operating system. We
also declared two variables, EXP and POWER, to represent the current
exponent and the actual power of 2 for the value of EXP. These two
variables are initialized prior to entering the main loop. Each successive
power is computed by doubling the previous power with the ADD.L
DO,DO instruction. Since the DO register is used for several functions,
POWER and EXP are updated after their new values are computed.
Formatting of the output lines is accomplished by inserting a space
after outputting the exponent, and an advance to the next line after
outputting the power. The ASCII character value for the space character
is 20 in hexadecimal. The standard procedure, PUTC, is called with this
value in the DO register. The output from this program should look like
the following:
Page view 66
1 2 ... 62 63 64 65 66 67 68 69 70 71 72 ... 255 256

Comments to this Manuals

No comments