Example on 68000 programming

Example 10.8

Write a 68000 assembly language program that will perform : 5 x X+ 6 x Y + [Y/8] [ D l.L] where X is an unsigned 8-bit number stored in the lowest byte of D0 and Y is a 16-bit signed number stored in the upper 16 bits of D I.Neglect the remainder of Y/8.

Solution

imageExample 10.9

Write a 68000 assembly language program to convert temperature from Fahrenheit to Celsius using the following equation: C = [(F- 32)/9] x 5 ; assume that the low byte of D0 contains the temperature in Fahrenheit. The temperature can be positive or negative. Store result in D0.

Solution

image

Example 10.10

Write a 68000 assembly language program at address $4000 to add four 32-bit numbers stored in consecutive locations starting at address $3000. Store the 32-bit result onto the user stack. Assume that no carry is generated due to addition of two consecutive 32-bit numbers and A7 is already initialized.

Solution

image

Example 10.11

Write a subroutine in 68000 assembly language to implement the C language assignment statement: p = p + q; where addresses p and q hold two 16-digit (64-bit) packed BCD numbers (Nl and N2). The main program will initialize addresses p and q to $002000 and $003000 respectively. Address $002007 will hold the lowest byte ofNl with the highest byte at address $002000 while Address $003007 will contain the lowest byte of N2 with the highest byte at address $003000. Also, write the main program at address $004000 which will perform all initializations including address p (pointer AO to $002000), address q (pointer AI to $003000), l00p count (D1 to 7), and then call the subroutine at $008000 and stop. The subroutine will accomplish the task with the initialized values of AO, A I, and D1 in the main program. Use ABCD.B for BCD addition with predecrement mode. Assume supervisor mode. Note that the 68000 supervisor stack pointer is initialized upon hardware reset.

Solution

image

Examule 10.12

Write a 68000 assembly program to multiply an 8-bit signed number in the low byte ofDI by a 16-bit signed number in the high word ofD5. Store the result in D3.

Solution

imageExamule 10.13

Write a 68000 assembly language program at address $2000 to add ten 32-bit numbers stored in consecutive locations starting at address $502040. Initialize A6 to $00200504 and use the low 24 bits of A6 as the stack pointer to push the 32-bit result. Use only ADDX instruction for adding two 32-bit numbers each time through the l00p. Assume that no carry is generated due to the addition of two consecutive 32-bit numbers; this will provide the 32-bit result. This example illustrates use of the 68000 ADDX instruction.

Solution

 

image

image

Note that ADDX adds the contents of two data registers or the contents of two memory locations using predecrement modes.

Example 10.14

Write a 68000 assembly language program at address $2000 to subtract two 32-bit packed BCD numbers. The BCD number 1 is stored at the locations starting from $003000 through $003003, with the least significant byte at $003003 and the most significant byte at $003000. Similarly, the BCD number 2 is stored at the locations starting from $004000 through $004003, with the least significant byte at $004003 and the most significant byte at $004000. The BCD number 2 is to be subtracted from BCD number 1. Store the packed BCD result at addresses $005000 (Lowest byte of the result) through $005003 (Highest byte of the result). In the program, first initialize l00p counter D7 to 4, source pointer AO to $003000, source pointer A I to $004000, destination pointer A3 to $005000, and then write the program to accomplish the above using these initialized values.

Solution

image

Note that SBCD subtracts the contents of two data registers or the contents of two memory locations using predecrement modes.

Example 10.15

Write a 68000 assembly program at address $1000 which is equivalent to the following C language segment:

image

Assume that the arrays, x[i] and y[i] contain unsigned 16-bit numbers already stored in memory starting at addresses $3000 and $4000 respectively. Store the 32-bit result at address $5000.

image

Leave a comment

Your email address will not be published. Required fields are marked *