Académique Documents
Professionnel Documents
Culture Documents
hello.x68
L2_1.x68
L2_2.x68
L2_3.x68
L2_4.x68
L2_5.x68
L2_6.x68
To illustrate the previous process, we will work with the infamous Hello World! program shown
below in Fig. 1.
MESSAGE
ORG
LEA
TRAP
TRAP
$8000
MESSAGE,A1
#2
#14
DC.B
DC.B
END
Hello World!
$0D,$0A,0
PROGRAM
To assemble the program; that is, to convert the assembly-language program to machinelanguage, first open a DOSBox window from Start Menu>All Programs>DOSBox, then
change into the directory H:\2030\L2 and enter the following command:
H:\2030\L2>asm68 hello
The previous command causes the assembler (asm68) to take the ASCII encoded source file
(hello.x68) and convert it into a binary (or object) file (hello.bin) that contains the binary code
produced by the assembler. Note: the assembler will only produce a binary file if there are
no syntax errors in the original source file.
3. The 68KMB expects the machine-language program to be encoded using Motorola SRecords before it is downloaded. To convert the binary file created in step 2 (hello.bin) to
Motorola S-Records (hello.txt) open a Windows Command Prompt from Start
Menu>All Programs>Accessories, change into directory H:\2030\L2 and
enter the
following command:
H:\2030\L2>srec hello
This will cause the file hello.txt to be created. This is the file that will be downloaded to
the 68KMB.
4. Following the procedure described in Lab 1 establish communication between the SunRay
and the 68KMB. Recall, you will need to run TeraTerm with the correct parameters, connect
the SunRay to the 68KMB by plugging the serial cable into the J3 socket on the 68KMB,
power up 68KMB, and press the RESET button on the board until the following prompt
appears on the TeraTerm terminal window:
MON68K
V4.4>
NOTE: If MON68K becomes unresponsive after a period of being idle, press the
MONITOR button, then press the RESET button to reboot the board.
5. Now that the board is communicating with the SunRay, we can download the program (from
step 3) to the 68KMB. To transfer a file, first enter the monitor command l (load). This
command will prepare the 68KMB to load an S-record file from the SunRay into the
68KMBs memory.
6. To transfer the file from the SunRay to the 68KMB, use the mouse to select the Send file
command from the File Menu. An Open File Dialog will appear. Select hello.txt
(generated in step 3) under the H:\2030\L2 directory. Click OK. (You can also drag and
drop the file into TeraTerm from Windows Explorer.)
7. When an entry message entry: 008000 appears on the screen, press ctrl+Z. The file
transfer is now completed. To run the program enter go 8000 at the monitor prompt. The
message Hello world should be displayed on your screen. If the message does not appear,
check to make sure the serial cable is connected to your computer, or ask the TA for help.
NOTE:
If Hello world0 is displayed go to the Setup menu and click Terminal. Change the Receive
value from CR to CR+LF, then click OK.
Below, you will find a summary of the previous steps. You will want to keep this summary
handy, at least until you become comfortable performing all of the steps
ORG
MOVE.B
MOVE.W
MOVE.L
MOVE
TRAP
END
$8000
D0,D1
D0,D2
D0,D3
D0,D4
#14
PROGRAM
3. Use the register dump command to help fill in the first column (Before Move) of the table
below with the current 32-bit values (expressed in hexadecimal) contained in D0 through
D3.
Before Move
After Move
D0
D1
D2
D3
D4
4. Now run the program by entering the monitor command GO 8000. Once the program
completes execution, fill in the second column (After Move) of the table above with the new
data-register values expressed in hexadecimal.
a) Why do data registers D1 through D3 hold different values, even though they are a
copy of D0? Be precise.
Rather than using the MON68Ks PERIOD command to initialize data registers prior to a
program running, it is possible to use the MOVE instruction to initialize registers at runtime. (In
fact, this is one of the most common uses of MOVE instructions.) This can be done by using the
MOVE instruction in combination with the immediate (or constant) address mode. Recall from
class that an immediate (constant) value can be specified in an instruction that supports immediate
addressing by placing a # before the numeric value. Numeric values can be specified either in
hexadecimal ($), binary (%), or decimal (nothing). Figure 3 shows how the previous program
(L2_1.x68) can be adapted so that D0 is now initialized using a MOVE instruction.
*L2_2.x68: Performs a series of moves involving data registers
PROGRAM
ORG
MOVE.L
MOVE.B
MOVE.W
MOVE.L
MOVE
TRAP
END
$8000
#$56781234,D0
D0,D1
D0,D2
D0,D3
D0,D4
#14
PROGRAM
5. Download the program (called L2_2.x68) from the course website and load it into the
68000s memory using the steps outlined in Part A. Then run the program and ensure that it
produces the same output as the previous program (L2_1.x68).
a) Below, rewrite the MOVE.L #$56781234,D0 instruction so that the source operand
(numeric value) is specified in binary rather than hexadecimal:
ORG
MOVE.L
ADD.B
ADD.B
ADD.B
TRAP
END
$8000
#$21,D0
#$57,D0
#$B9,D0
#$7D,D0
#14
PROGRAM
;D0
;D0
;D0
;D0
=
=
=
=
$21
$21 + $57
$21 + $57 + $B9
$21 + $57 + $B9 + $7D
until you find the cause of an error. Read about the how to use the TR command in
Appendix E, page 404 of your textbook.
Before using the TR command you must set the Program Counter (PC) to the address of the
first instruction in your program. This can be done using the PERIOD command:
V4.4>.PC 8000
In our case, the PC is set to 8000, as this is the hexadecimal address of the first instruction in
the current program (Fig. 4).
Once you have initialized the PC to hexadecimal 8000, enter the program can be traced by
entering the monitor command:
V4.4>.TR 1
Below, is the beginning output of the trace. (Note that the values in the registers (below)
may differ from what you might see on your own board.)
V4.4>.PC 8000
V4.4>TR 1
PC=00008002 SR=A700=TS7.. US=00008800 SS=0000BFD2
D0=00000021 D1=00000000 D2=00000000 D3=00000000
D4=00000000 D5=00000000 D6=00000000 D7=00000000
A0=00000000 A1=00000000 A2=00000000 A3=00000000
A4=00000000 A5=00000000 A6=00000000 A7=0000BFD2
---- 008002
06000057
ADD.B #87,D0
Notice that the program counter does not contain the hexadecimal address 8000, rather the
hexadecimal address 8002. This is because the trace command has already executed the first
instruction (MOVE.L #$21,D0) in the program, and now the PC is pointing at the next
program instruction in memory to be executed (located at hexadecimal address 8002). If you look
at the bottom line of the output, it shows both the hexadecimal memory address 008002 and the
name (or mnemonic) of the next instruction to be executed (ADD.B #87,D0).
Another very important piece of information that is provided by the trace facility is the status
of the Condition-Code Register (CCR) flags. As discussed in class, after the processor executes
an instruction the flags in the condition-code register are updated to reflect the nature of the result.
The CCR flags can be found in the lower byte of the Status Register (SR). If a particular bit in
the CCR is set to one, the first letter of the corresponding flag will be visible. For example,
consider the partial trace output given below. The N (negative) flag is currently set to 1 since the
letter N is showing. This implies that the result of the previous operation was, in fact, negative.
V4.4>.PC 9030
V4.4>TR 1
11
11
Returning to the program at hand, trace through the entire program (L2_3.x68) from start
to finish. (Remember, pressing the ENTER key at this point will step to the next instruction in
your program. If you want to stop the trace, type in . and hit ENTER.) After each instruction
executes, record the 32-bit hexadecimal values contained in data register D0 in the table below,
along with the value of the CCR flags.
Current Instruction
Data Register
D0
MOVE.L #$21,D0
ADD.B #$57,D0
ADD.B #$B9,D0
ADD.B #$7D,D0
a) Why does the first addition instruction (ADD.B #$57,D0) clear the C flag, but the
second addition instruction (ADD.B #$B9,D0) cause the C flag to be set?
b) Explain why the final value in D0 does not match the expected value?
c) How would you fix the previous program so that it computed the sum of the four bytes
correctly?
12
12
ORG
MOVE.B
ADD.B
ADD.B
SUB.B
SUB.B
TRAP
END
$8000
#$77,D0
#3,D0
#9,D0
#1,D0
#4,D0
#14
PROGRAM
Perform a single-step trace of the program. After each instruction executes, write down the
resulting 32-bit value (expressed in hexadecimal) in register D0 and the current status of each
flag in the CCR. Remember to initialize the PC to 8000 before issuing the TR command.
Instructions
Value in D0
CCR Flags
Z
V
MOVE.B #$77,D0
ADD.B
#3,D0
ADD.B
#9,D0
SUB.B
#1,D0
SUB.B
#4,D0
Recall from class that an operand may be interpreted as either signed or unsigned. Lets assume
that the lower byte in D0 is a signed integer. This means that the most-significant bit (MSB)
should be interpreted as a sign bit, where 0 means positive and 1 means negative. Using the
information collected in the previous table, after each instruction executes identify if a sign
change does or does not occur and explain why by making reference to the flags in the CCR.
13
13
Now lets assume that the lower byte in D0 is an unsigned integer. Is a borrow required when
performing the last subtraction instruction (SUB.B #4,D0)? Your explanation should make
reference to the appropriate flag in the CCR.
The SWAP instruction is used to swap the upper and lower words of a given register. This
comes in handy when you want to examine the remainder of a division result. (Before proceeding
carefully review the SWAP instruction on pages 86 and 358 of your textbook.)
The CLR instruction is used to set to zero the contents of a register or memory location.
(Before proceeding carefully review the CLR instruction on page 292 of your textbook.)
Download the following program (called L2_5.x68) from the course website and load it into the
68000s memory using the steps outlined in Part A.
14
14
MOVE.W
MOVE.B
MULS
EXT.W
DIVS
CLR.L
MOVE.W
MOVE.L
CLR.W
SWAP
TRAP
END
$8000
#9,D2
#-2,D3
D2,D2
D3
D3,D2
D1
D2,D1
D2,D0
D0
D0
#14
PROGRAM
Figure 5: Program illustrates use of MULS, DIVS, EXT, and SWAP instructions.
Perform a single-step trace of the program. After each instruction executes, write down the
resulting 32-bit value (expressed in hexadecimal) in the registers. Remember to initialize the PC
to 8000 before issuing the TR command.
Instructions
Value in D0
Value in D1
MOVE.W #9,D2
MOVE.B #-2,D3
MULS D2,D2
EXT.W D3
DIVS.W D3,D2
CLR.L D1
MOVE.W D2,D1
MOVE.L D2,D0
CLR.W D0
SWAP D0
a) What does this program do? Be concise!
15
15
Value in D2
Value in D3
Now it is your turn. Using the formula below as a guide, write a 68000 assembly-language
program to convert Celsius (C) to Fahrenheit (F):
F = (C 9)/5 + 32
where C is a 16-bit signed value stored in data register D0, and constants 5, 9 and 32 are all 16bit values that are specified using immediate addressing; that is, the literal values appear in the
instructions that use them preceded by a # sign. The result F should be stored in data register
D1.
A template for creating your program can be found on the course website with the name
L2_6.x68. This template is shown in Fig. 6. Make sure to put your code where instructed.
*L2_6.x68: Template
ORG $8000
*Put Code Here
TRAP
END
#14
$8000
As a result of completing this lab you should have a working knowledge of how to assemble,
download into RAM, and run a program on the 68KMB; you should also have a basic
understanding of the 68000s main data movement and arithmetic instructions; and how to trace
through a program instruction by instruction.
16
16