FACULTY OF ELECTRICAL ENGINEERING UNIVERSITI TEKNOLOGI MARA ________________________________________________________________ MICROPROCESSOR SYSTEMS LABORATORY (ECE365) EXPERIMENT 3 ARITHMETIC AND LOGIC INSTRUCTIONS 1.0 OBJECTIVES i) To understand the 68HC12 instructions of performing arithmetic and logic operations. ii) To determine the contents inside the CPU registers and memory. iii) To write a proper programming for arithmetic and logic instructions. iv) To understand the functions of CCR. 2.0 LIST OF REQUIREMENTS 2.1 Equipments 1. Personal Computer 2. Software J2RE 3. Software MiniIDE 4. Software HC12SIM 5. Power supply 2.2 Depth understanding of : 1. Lab 1 Addressing Modes 2. Lab 2 Data Transfer and Manipulation Instructions 3. Topic on Arithmetic and Logic Instructions
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
In this procedure, the instruction sequence is about to multiply the unsigned 16-bit number.
We used it to multiply the unsigned 16-bit number located at memory locations $800~$801
by the 16-bit unsigned number stored at memory locations $802~$803, and store the product
at memory locations $900~$903. The next instructions are to divide the unsigned 16-bit
number stored at accumulator D by the 16-bit unsigned number stored at index register X, and
store the quotient and remainder at $904~$905 and $906~$909. We used the emul and idiv
instruction, an specific instuction to multiply in divide in btween 16-bit number.
7.0 PROCEDURE 4 Extended Bits of Multiplication
1. Program in Figure 7.0 is instruction sequence to multiply the 32-bit unsigned integersstored at M~M+3 and N~N+3, respectively and store the product at memory locationsP~P+7.Write this program in MiniIDE with comments, translate to the list file andmachine file.
org $800
M: dc.l $13281250 ; holds the multiplicand
N: dc.l $321F1030 ; holds the multiplier
P: rmb 8 ; reserved to hold the product
org $900
ldd M+2 ; place ML in D
ldy N+2 ; place NL in Y
emul ; compute MLNL
sty P+4 ; save the upper 16 bits of the partial product MLNL
std P+6 ; save the lower 16 bits of the partial product MLNL
ldd M ; place MH in D
ldy N ; place NH in Y
emul ; compute MHNH
sty P ; save the upper 16 bits of the partial product MHNH
std P+2 ; save the lower 16 bits of the partial product MHNH
ldd M ; place MH in D
ldy N+2 ; place NL in Y
emul ; compute MHNL
; the following seven instructions add MHNL to memory locations P+2~P+5
addd P+4 ; add the lower half of MHNL to P+4~P+5
std P+4 ;
tfr y,d ; transfer Y to D
adcb P+3
stab P+3
adca P+2
staa P+2
; the following six instructions propagate carry to the most significant byte
ldaa P+1
adca #0 ; add C flag to location P+1
staa P+1 ;
ldaa P
adca #0 ; add C flag to location P
staa P
; the following three instructions compute MLNH
ldd M+2 ; place ML in D
ldy N ; place NH in Y
emul ; compute MLNH
; the following seven instructions add MLNH to memory locations P+2~P+5
addd P+4 ; add the lower half of MLNH to P+4~P+5
std P+4 ;
tfr y,d ; transfer Y to D
adcb P+3
stab P+3
adca P+2
staa P+2
; the following six instructions propagate carry to the most significant byte
ldaa P+1
adca #0 ; add C flag to location P+1
staa P+1
ldaa P
adca #0 ; add C flag to location P
staa P
end
Figure 7.0
2. Load the machine file to the HC12SIM (B32 Single Chip Mode), set PC to $900, clear all
the registers and CCR, and then use Go execution to observe the executions of overall
instructions affected to the contents of the memory. Refer to Appendix 12.0.
3. Write a discussion regarding to this procedure.
Solution
: =00000800 org $800
2: 0800 13281250 M: dc.l $13281250 ; holds the multiplicand
3: 0804 321F1030 N: dc.l $321F1030 ; holds the multiplier
4: 0808 +0008 P: rmb 8 ; reserved to hold the product
5:
6: =00000900 org $900
7: 0900 FC 0802 ldd M+2 ; place ML in D
8: 0903 FD 0806 ldy N+2 ; place NL in Y
9: 0906 13 emul ; compute MLNL
10: 0907 7D 080C sty P+4 ; save the upper 16 bits of the partial product
MLNL
11: 090A 7C 080E std P+6 ; save the lower 16 bits of the partial product
MLNL
12: 090D FC 0800 ldd M ; place MH in D
13: 0910 FD 0804 ldy N ; place NH in Y
14: 0913 13 emul ; compute MHNH
15: 0914 7D 0808 sty P ; save the upper 16 bits of the partial product
MHNH
16: 0917 7C 080A std P+2 ; save the lower 16 bits of the partial product
MHNH
17: 091A FC 0800 ldd M ; place MH in D
18: 091D FD 0806 ldy N+2 ; place NL in Y
19: 0920 13 emul ; compute MHNL
20: ; the following seven instructions add MHNL to memory locations
P+2~P+5
21: 0921 F3 080C addd P+4 ; add the lower half of MHNL to P+4~P+5
22: 0924 7C 080C std P+4 ;
23: 0927 B7 64 tfr y,d ; transfer Y to D
24: 0929 F9 080B adcb P+3
25: 092C 7B 080B stab P+3
26: 092F B9 080A adca P+2
27: 0932 7A 080A staa P+2
28: ; the following six instructions propagate carry to the most
significant byte
29: 0935 B6 0809 ldaa P+1
30: 0938 89 00 adca #0 ; add C flag to location P+1
31: 093A 7A 0809 staa P+1 ;
32: 093D B6 0808 ldaa P
33: 0940 89 00 adca #0 ; add C flag to location P
34: 0942 7A 0808 staa P
35: ; the following three instructions compute MLNH
36: 0945 FC 0802 ldd M+2 ; place ML in D
37: 0948 FD 0804 ldy N ; place NH in Y
38: 094B 13 emul ; compute MLNH
39: ; the following seven instructions add MLNH to memory locations
P+2~P+5
40: 094C F3 080C addd P+4 ; add the lower half of MLNH to P+4~P+5
41: 094F 7C 080C std P+4 ;
42: 0952 B7 64 tfr y,d ; transfer Y to D
43: 0954 F9 080B adcb P+3
44: 0957 7B 080B stab P+3
45: 095A B9 080A adca P+2
46: 095D 7A 080A staa P+2
47: ; the following six instructions propagate carry to the most
significant byte
48: 0960 B6 0809 ldaa P+1
49: 0963 89 00 adca #0 ; add C flag to location P+1
50: 0965 7A 0809 staa P+1
51: 0968 B6 0808 ldaa P
52: 096B 89 00 adca #0 ; add C flag to location P
53: 096D 7A 0808 staa P
54: end
Symbols:
m *00000800
n *00000804
p *00000808
Discussion
In this procedure, extended bits is involved. The is instruction sequence to multiply the 32-bit unsigned integers stored at M~M+3 and N~N+3, respectively and store the product at memory locations P~P+7. Extended bits is involved in this procedure. We use combination of instruction such as addd P+4 which to add lower half of MNHL. All the instuction in this procedure is more complicated than the other procedures.
8.0 PROCEDURE 5 Boolean Logic and Shift
1. Program in Figure 8.0 is instruction sequence to perform Boolean logic and shift/rotate
operations. Write this program in MiniIDE with comments, translate to the list file and
machine file.
org $800
ldaa #89
ldab #$FE
anda $800
staa $850
orab $802
stab $851
eora $804
staa $852
nega
staa $853
comb
stab $854
asla
staa $855
asrb
stab $856
rola
staa $857
rorb
stab $859
end
2. Load the machine file to the HC12SIM, set PC to $0800, clear all the registers and CCR,
and then use step execution to observe the contents of the CPU registers include CCR
and memory. Refer to Appendix 12.0.
3. Write a discussion regarding to this procedure.
Solution
1: =00000800 org $800
2: 0800 86 59 ldaa #89 ; load data and save into accumulator A
immediatelly
3: 0802 C6 FE ldab #$FE ;load data and store in accumulator B
4: 0804 B4 0800 anda $800 ;AND accumulator A with memory
5: 0807 7A 0850 staa $850 ;store data in A
6: 080A FA 0802 orab $802 ;logical OR accumulator B with memory
7: 080D 7B 0851 stab $851 ;store accumulator B to memory
8: 0810 B8 0804 eora $804 ; exclusive OR accumulator A with memory
9: 0813 7A 0852 staa $852 ;store accumulator A to memory
10: 0816 40 nega ;negate accumulator A
11: 0817 7A 0853 staa $853 ;store accumulator A to memory
12: 081A 51 comb ;complement accumulator B
13: 081B 7B 0854 stab $854 ;store accumulator B to memory
14: 081E 48 asla ;arithmetic shift left accumulator A
15: 081F 7A 0855 staa $855 ;store accumulator A to memory
16: 0822 57 asrb ;arithmetic shift right accumulator B
17: 0823 7B 0856 stab $856 ;store accumulator B to memory
18: 0826 45 rola ;rotate accumulator A left through carrry
19: 0827 7A 0857 staa $857 ;store accumulator A to memory
20: 082A 56 rorb ;rotate accumulator B through carry
21: 082B 7B 0859 stab $859 ;store accumulator B to memory
22: end
Discussion
This procedure is about using instruction sequence to perform Boolean logic and shift/rotate
operations. This programming used logic gate to do operation such as OR and EXOR gate.
New instruction such as eora, nega, comb, asla, asrb, rola and rorb are used. Instructon like
eora $804 is used to insert exclusive OR accumulator A with memory and rola is to rotate
accumulator A left through carrry.
9.0 QUESTIONS
Answer all the questions.
1. Write an instruction sequence to add the two 24-bit numbers stored at $800-$802 and
$803-$805, and save the sum at $900-$902.
Solution
ORG $0800
LDD $0801
ADD $0804
STD $0901
LDAA $0800
ADCA $0803
STAA $0900
END
2. Write an instruction sequence to subtract the 6-byte number stored at $800-$805 from
the 6-byte number stored at $806-$80B and save the sum at $900-$905.
Solution
ORG $0800
LDD $0804
SUBD $0804
STD $0904
SBCA $0803
STAA $0901
LDAA $0800
SBCA $0806
STAA $0900
END
3. Write a program to multiply two 3-byte numbers that are store at $800-$802 and $803-
$805, and save the product at $900-$905.
Solution
ORG $0800
LDD $0801
LDY $0803
EMUL
STY $0900
STD $0804
LDD #33000
LDX #2000
IDIV
STX $0906
STY $0908
END
4. Write a program to shift the 8-byte number located at $800-$807 to the left four places.
ORG $0800
LDD $0801
LDY $0803
ASLA
END
Result
Conclusion
-From this experiment,we manage to achieve the objectives stated. We slowly to understand
the 68HC12 instructions of performing arithmetic and logic operations by using the listed
instruction. We also learnt to determine the contents inside the CPU registers and memory.
We now know to write a proper programming for arithmetic and logic instructions and
understand the functions of CCR.
11.0 REFERENCES[1] S. F. Barret and D. J. Pack. (2005). Embedded Systems : Design and Application withthe 68HC12 and HCS12. Available:[2] M. G, "Experiment 2 Arithmetic and Logic Instruction," in KEC346, ed: FKE UiTM, Aug2006.[3] H.-W. Huang. (2009). Introduction to the 68HC12 Microcontroller.[4] D. T. Li, "EEL 4744C lecture 5 68HC12 Instruction Set," ed.[5] H.-W. Huang. (2009). 68HC12 Assembly Programming.