Sie sind auf Seite 1von 2

Universiti Tenaga Nasional

College of Engineering
EEEB373 Microprocessor Systems
Tutorial 2 Solution
1. Write an instruction sequence to swap the contents of data registers at 0x300 and 0x200.
Answer: We can use the WREG instruction as holding register to perform the swap of these two
registers. The instruction sequence is as follows:
movff
movff
movff

0x200,WREG
0x300,0x200
WREG,0x300

; copy data register at 0x200 to WREG


; copy data register at 0x300 to 0x200
; transfer the contents of 0x200 to 0x300

2. Write an instruction sequence to load the value of 0x39 into data memory locations 0x1000x103.
Answer: The instruction sequence that performs the storing operation is as follows:
movlw 0x39
movff WREG,0x100
; use register to register move instruction to
movff WREG,0x101
; avoid bank switching
movff WREG,0x102
;
movff WREG,0x103 ;
3. Write an instruction sequence to subtract 10 from data memory locations 0x30-0x34.
Answer: The instruction sequence that carries out the subtraction is as follows:
movlw 0x0A
subwf 0x30,F,A
subwf 0x31,F,A
subwf 0x32,F,A
subwf 0x33,F,A
4. Write an instruction to store the contents of the WREG register in the data register located at
0x25 of bank 4.
Answer: The instruction sequence is as follows:
movlb 0x04
movwf 0x25,BANKED
The same operation can also be performed by the following instruction:
movff WREG,0x425

5. Write an instruction sequence to copy the contents of data memory at 0x100-0x103 to 0x2000x203 using the post increment addressing mode.

Answer: The following instruction sequence can carry out the desired copy operation:
lfsr
FSR0,0x100
lfsr
FSR1,0x200
movff POSTINC0,POSTINC1
movff POSTINC0,POSTINC1
movff POSTINC0,POSTINC1
movff POSTINC0,POSTINC1
6. Write an instruction sequence to copy the contents of data memory at 0x100-0x103 to 0x2030x200, that is, in the reverse order by combining the use of postincrement and postdecrement
modes.
Answer: The instruction sequence is as follows:
lfsr
FSR0,0x100
lfsr
FSR1,0x203
movff POSTINC0,POSTDEC1
movff POSTINC0,POSTDEC1
movff POSTINC0,POSTDEC1
movff POSTINC0,POSTDEC1
7. Write an instruction sequence to add 5 to data registers at 0x300-0x303.
Answer: The following instruction sequence will add 5 to data registers 0x300-0x303.
movlb 0x03
; switch to bank 3
movlw 0x05
;
addwf 0x00,F,BANKED ; Add 5 to 0x300
addwf 0x01,F,BANKED ; Add 5 to 0x301
addwf 0x02,F,BANKED ; Add 5 to 0x302
addwf 0x03,F,BANKED; Add 5 to 0x303
8. Write an instruction sequence to add the contents of the data registers at 0x10 and 0x20 and
store the sum at 0x30.
Answer: The following instructions perform the desired addition operations:
movf
0x10,W,A
addwf 0x20,W,A
movwf 0x30,A
9. Write an instruction sequence to subtract the contents of the data register at 0x20 from that of
the data register at 0x30 and store the difference in the data register at 0x10.
Answer: The following instruction sequence performs the subtraction and save the difference at
0x10.
movf
0x20,W,A
subwf 0x30,W,A
movwf 0x10,A

Das könnte Ihnen auch gefallen