Forum: Mikrocontroller und Digitale Elektronik SBIC skipped, obwohl Bit gesetzt!?


von Malte von dem Hagen (Gast)


Lesenswert?

Moin,

Dies betrifft den ATmega163 und das AVR Studio 4, der reale Chip steht 
derzeit leider nicht zum testen zur Verfügung.

Das am Ende dieses Beitrages gepostete kleine Programm soll ein 
einfaches Linear Feedback Shift register realisieren, dabei tritt 
folgendes Problem auf:

Laut Instruction Set wirkt die Anweisung SBIC wie folgt:
"SBIC – Skip if Bit in I/O Register is Cleared

Description:
This instruction tests a single bit in an I/O Register and skips the 
next instruction if the bit is cleared. This instruction operates on the 
lower 32 I/O Registers – addresses 0-31.

Syntax:   Operands:
SBIC A,b  0 ≤ A ≤ 31, 0 ≤ b ≤7"

Daraus lese ich, daß die Instruction testet, ob ein Bit gesetzt ist, 
falls dem nicht so ist ("Bit is cleared" heisst doch quasi "Bit ist 
gleich 0", oder?), überspringt sie die nächste Anweisung.

Warum haben dann folgende Zeilen ein Überspringen der SBI Anweisung zur 
Folge?
Gewollt ist es, das Bit 0 in R2 in das Bit 0 in R17 zu kopieren.

LDI R18, $ff
MOV R2, R18
SBIC $02, 0
SBI $11, 0

Im Simulator des AVR Studio wird SBI wie gesagt übersprungen, was 
eigentlich nicht der Fall sein sollte. Warum?

Dank && Gruß,

Malte

<----following the complete code---->
; linear feedback shift register
; Malte von dem Hagen 2003
; m@bsdhackers.org

.INCLUDE "m163def.inc"

;init example values to 00000111_00000000_11111111
;result should be R2:R0=00000111_10000000_01111111 C=1
LDI R18, $ff
LDI R17, $00
LDI R16, $07
MOV R2, R18
MOV R1, R17
MOV R0, R16

;clock_lfsr:
CLC      ;clear carry

;prepare the first xor
CLR R17      ;clear buffer
SBIC $02, 0    ;move bit 0 from R2 to buffer
SBI $11, 0

;perform the first xor
CLR R16      ;clear work
SBIC $02, 1    ;move bit 1 from R2 to work
SBI $10, 0
EOR R17, R16          ;xor buffer with work, store result in buffer

;perform the second xor
CLR R16      ;clear work
SBIC $02, 2    ;move bit 2 from R2 to work
SBI $10, 0
EOR R17, R16          ;xor buffer with work, store result in buffer

;perform the third xor
CLR R16      ;clear work
SBIC $02, 5    ;move bit 5 from R2 to work
SBI $10, 0
EOR R17, R16          ;xor buffer with work, store result in buffer

;take care of the result of xoring
SBIC $11, 0    ;if result of xor-ing is 1...
SBI $00, 3    ;...inject it to R0

;kick that stuff one step right
LSR R0      ;rightshift R0 because we need leading zeros
ROR R1      ;rightrotate R1 - carry from R0 is considered
ROR R2      ;rightrotate R2 - carry from R1 is considered
      ;carry from R2 is now in carry as desired

.exit
<----end of complete code---->

von crazy horse (Gast)


Lesenswert?

Falscher Befehl.
Willst du Register-Bits testen, mußt du sbrc bzw. sbrc benutzen. Der 
sbic/sbis bezieht sich auf die I/O-Ports
Skip
Bit
Register bzw Io
Set bzw Clear

Bitte melde dich an um einen Beitrag zu schreiben. Anmeldung ist kostenlos und dauert nur eine Minute.
Bestehender Account
Schon ein Account bei Google/GoogleMail? Keine Anmeldung erforderlich!
Mit Google-Account einloggen
Noch kein Account? Hier anmelden.