Example of an assembler question for the cs2 exam
3 a) Explain briefly the
effect of the following instructions on a PIC microprocessor. [4]
i) bcf 2,3
ii) comf 21,1
iii) incf 11,0
iv) andlw
B'11001111'
Answer
i) clear bit 3 of register 2
ii) reg[21]:=
~ reg[21]
iii) w:= reg[11]+1
iv) w:=w and 207
b) Provide a
diagram of the datapaths and functional units in a
PIC microprocessor
labeling your buses.
[4]
reg
c) With reference to your diagram supplied for
part b, identify which
buses are
active for the following instructions [4]
i)
addwf 12,1
ii)
retlw 7
answer
i.
phase 1: const bus addresses
registers, r, a,b busses feed alu;
phase 2: const bus addresses registers, result bus goes to content of registers
ii.
const bus fed through b bus
to alu, then via result bus to w reg. Simultaneously
stack popped into pc
d) Translate
the following pseudo code into PIC assembler [8]
State
assumptions made about your parameter passing mechanism.
---
Return true if the array is sorted in ascending order
procedure isSorted(a:array[1..4] of byte):boolean;
variable
x:byte;
begin
x:= a[1];
for i:= 1 to 4 do
if a[i]<x then
return false
x:=a[i]
enddo
return
true
end
assume parameter passed in w
movwf a ; save parameter
movwf fsr
movfw indir
movwf x ; x:=a[i]
movlw 4
movwf I ;
initialise count
again
movfw indir ; get array element
subwf x,0
btfsc status,carry
retlw 0 ; if a[i]<x return false
incf fsr,1 ; address next array value
movfw indir
movwf x ; x gets
next array value
decfsz i
goto again
retlw 1 ; return
true