Chapter 5: Building Assembler Programs

Download Report

Transcript Chapter 5: Building Assembler Programs

Assembler Exercises
Chapters 4-6
Dr. Gheith Abandah
1
Exercise 1
z = x + y;
Dr. Gheith Abandah
2
Exercise 1
movf
addwf
movwf
x, 0
y, 0
z
Dr. Gheith Abandah
3
Exercise 2
z = x + y;
//16-bit numbers
Dr. Gheith Abandah
4
Exercise 2
movf
addwf
movwf
x_lo, 0
y_lo, 0
z_lo
btfsc
incf
status, C
x_hi, 1
movf
addwf
movwf
x_hi, 0
y_hi, 0
z_hi
Dr. Gheith Abandah
5
Exercise 3
sum = 0;
for (i=0; i<10; i++)
sum += A[i];
Dr. Gheith Abandah
6
Exercise 3
Loop
A
equ
20
movlw
movwf
movlw
movwf
clrw
addwf
incf
decfsz
goto
movwf
0a
counter
A
fsr
indf,0
fsr
counter
Loop
sum
Dr. Gheith Abandah
7
Assignment
• Study Section 5.9: The ping-pong program
Dr. Gheith Abandah
8
Exercise 4
z = (x + y) - q;
Dr. Gheith Abandah
9
Exercise 4
movf
addwf
movwf
movf
subwf
x,
y,
z
q,
z,
0
0
0
1
Dr. Gheith Abandah
10
Exercise 5
z = x-3;
Dr. Gheith Abandah
11
Exercise 5
movlw
subwf
movwf
3
x, 0
z
Dr. Gheith Abandah
12
Exercise 6
z = x<<3;
Dr. Gheith Abandah
13
Exercise 6
bcf
rlf
bcf
rlf
bcf
rlf
movwf
status, C
x, 1
status, C
x, 1
status, C
x, 0
z
Dr. Gheith Abandah
14
Exercise 7
z = x && 0x0f;
Dr. Gheith Abandah
15
Exercise 7
movlw
andwf
movwf
0f
x, 0
z
Dr. Gheith Abandah
16
Exercise 8
z = x * 4;
Dr. Gheith Abandah
17
Exercise 8
bcf
rlf
bcf
rlf
movwf
status, C
x, 1
status, C
x, 0
z
Dr. Gheith Abandah
18