Lec 7
Lec 7
39
40
1
07-Oct-23
RISC Approach
LOAD A, 2:3
LOAD B, 5:2
PROD A, B
STORE 2:3, A
41
CISC RISC
Emphasis on hardware Emphasis on software
42
2
07-Oct-23
44
3
07-Oct-23
45
46
4
07-Oct-23
Example 3.1 : Write a program to (a) clear R20, then (b) add 3 to R20 ten
times, and ( c) send the sum to PORTB. Use the zero flag and BRNE.
What is the maximum number of times that the loop in Example 3-1 can
be repeated?
0xFF = 255
47
48
5
07-Oct-23
49
50
6
07-Oct-23
51
52
7
07-Oct-23
Example3-5: Find the sum of the values 0x79, 0xF5, and 0xE2.
Put the sum into R20 (low byte) and R21 (high byte).
LDI R21, 0 ;clear high byte (R21 = 0)
LDI R20, 0 ;clear low byte (R20 = 0)
LDI Rl6, 0x79
ADD R20, R16 ;R20 = 0 + 0x79 = 0x79, C = 0
BRSH N1 ;if C = 0, add next number
INC R21 ;C = 1, increment (now high byte = 0)
N1: LDI Rl6, 0xF5
ADD R20, Rl6 ;R20 = 0x79 + 0xF5 = 0x6E and C = 1
BRSH N2 ;branch if C = 0
INC R21 ;C = 1, increment (now high byte = 1)
N2: LDI Rl6, 0xE2
ADD R20, Rl6 ;R20 = 0x6E + 0xE2 = 0x50 and C = 1
BRSH OVER ;branch if C = 0
INC R21 ;C = 1, increment (now high byte = 2)
OVER: ;now low byte = 0x50, and high byte 02
53
54