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