Pogledao sam fajl, i mislim da ce za PIC16 seriju biti najteze realizovati operacije sa oznacenim brojevima, jer jednostavno u PIC16 seriji ne postoje instrukcije koje ih podrzavaju. Ostale strukture ne bi trebale predstavljati problem. U principu mogu se odraditi i oznaceni brojevi, ali uz duzi kod.
Evo (za pocetak) primera za testiranje W sa konstantom.
Radi lakseg razumevanja uzeo sam da se registar inkrementuje ako je uslov ispunjen, da se dekrementuje ako nije, i jednu praznu instrukciju (nop) pri nastavku programa.
if W > konstante 50 then inc else dec
Code:
if W > 50 then
begin
incf [49],W;
end
else
begin
decf [49],W;
end
nop;
$0100 : sublw $32;
$0101 : btfsc STATUS,C;
$0102 : goto $0105;
$0103 : incf [$31],W;
$0104 : goto $0106;
$0105 : decf [$31],W;
$0106 : nop;
if W < konstante 50 then inc else dec
Code:
if W < 50 then
begin
incf [49],W;
end
else
begin
decf [49],W;
end
nop;
$0100 : movwf TEMP;
$0101 : movlw $32;
$0102 : subwf TEMP,W;
$0103 : btfsc STATUS,C;
$0104 : goto $0107;
$0105 : incf [$31],W;
$0106 : goto $0108;
$0107 : decf [$31],W;
$0108 : nop;
if W >= konstante 50 then inc else dec
Code:
if W >= 50 then
begin
incf [49],W;
end
else
begin
decf [49],W;
end
nop;
$0100 : movwf TEMP;
$0101 : movlw $32;
$0102 : subwf TEMP,W;
$0103 : btfss STATUS,C;
$0104 : goto $0107;
$0105 : incf [$31],W;
$0106 : goto $0108;
$0107 : decf [$31],W;
$0108 : nop;
if W <= konstante 50 then inc else dec
Code:
if W <= 50 then
begin
incf [49],W;
end
else
begin
decf [49],W;
end
nop;
$0100 : sublw $32;
$0101 : btfss STATUS,C;
$0102 : goto $0105;
$0103 : incf [$31],0;
$0104 : goto $0106;
$0105 : decf [$31],0;
$0106 : nop;
if W == konstante 50 then inc else dec
Code:
if W == 50 then
begin
incf [49],W;
end
else
begin
decf [49],W;
end
nop;
$0100 : xorlw $32;
$0101 : btfss STATUS,Z;
$0102 : goto $0105;
$0103 : incf [$31],W;
$0104 : goto $0106;
$0105 : decf [$31],W;
$0106 : nop;
if W <> konstante 50 then inc else dec
Code:
if W <> 50 then
begin
incf [49],W;
end
else
begin
decf [49],W;
end
nop;
$0100 : xorlw $32;
$0101 : btfsc STATUS,Z;
$0102 : goto $0105;
$0103 : incf [$31],W;
$0104 : goto $0106;
$0105 : decf [$31],W;
$0106 : nop;
Sada evo primera za testiranje konstante sa W. Naravno, kod koji bi proizvodio kompajler je isti kao i ranije, jedino je znak poredjenja (<, >, <= i >=) promenjen.
Opet je radi lakseg razumevanja uzet prethodni slucaj (inkrementuja, dekrementacija i nop).
if konstanta 50 < W then inc else dec
Code:
if 50 < W then
begin
incf [49],W;
end
else
begin
decf [49],W;
end
nop;
$0100 : sublw $32;
$0101 : btfsc STATUS,C;
$0102 : goto $0105;
$0103 : incf [$31],W;
$0104 : goto $0106;
$0105 : decf [$31],W;
$0106 : nop;
if konstanta 50 > W then inc else dec
Code:
if 50 > W then
begin
incf [49],W;
end
else
begin
decf [49],W;
end
nop;
$0100 : movwf TEMP;
$0101 : movlw $32;
$0102 : subwf TEMP,W;
$0103 : btfsc STATUS,C;
$0104 : goto $0107;
$0105 : incf [$31],W;
$0106 : goto $0108;
$0107 : decf [$31],W;
$0108 : nop;
if konstanta 50 <= W then inc else dec
Code:
if 50 <= W then
begin
incf [49],W;
end
else
begin
decf [49],W;
end
nop;
$0100 : movwf TEMP;
$0101 : movlw $32;
$0102 : subwf TEMP,W;
$0103 : btfss STATUS,C;
$0104 : goto $0107;
$0105 : incf [$31],W;
$0106 : goto $0108;
$0107 : decf [$31],W;
$0108 : nop;
if konstanta 50 >= W then inc else dec
Code:
if 50 >= W then
begin
incf [49],W;
end
else
begin
decf [49],W;
end
nop;
$0100 : sublw $32;
$0101 : btfss STATUS,C;
$0102 : goto $0105;
$0103 : incf [$31],0;
$0104 : goto $0106;
$0105 : decf [$31],0;
$0106 : nop;
if konstanta 50 == W then inc else dec
Code:
if 50 == W then
begin
incf [49],W;
end
else
begin
decf [49],W;
end
nop;
$0100 : xorlw $32;
$0101 : btfss STATUS,Z;
$0102 : goto $0105;
$0103 : incf [$31],W;
$0104 : goto $0106;
$0105 : decf [$31],W;
$0106 : nop;
if konstanta 50 <> W then inc else dec
Code:
if 50 <> W then
begin
incf [49],W;
end
else
begin
decf [49],W;
end
nop;
$0100 : xorlw $32;
$0101 : btfsc STATUS,Z;
$0102 : goto $0105;
$0103 : incf [$31],W;
$0104 : goto $0106;
$0105 : decf [$31],W;
$0106 : nop;
Sve ovo su slucajevi za if...then...else... strukturu. Za obicnu if...then... strukturu izbacio bi se donji deo.
TEMP varijablu je pozeljno staviti u deljene (izmedju svih banki) registre.
Code:
var shared_bank [0x70..0x7E]
<
TEMP : byte
>
Koriscenjem "nestandardnog" W registra kao varijable se malo pobeglo od osnovnih tipova varijabli vaseg MMA, ali smatram da bi ipak pozeljno bilo uvesti i ovaj tip, jer se (relativno) najkrace prevodi, a cesto se srece u asemblerskim programima, bar za PIC.
[Ovu poruku je menjao Stojan Trifunovic dana 08.08.2008. u 08:38 GMT+1]