Jump to content
ELFORUM - Forumul electronistilor

# Probleme cu programarea in asm-Ajutor

## Recommended Posts

As vrea sa compar starile logice ale registrului ADRESH (conversia A/D)In momentul in care tensiunea pe intrare variaza sa vor modifica si starile logice din ADRESH.Eu am o ideie cum sa selectez si sa compar din cele 255 de stari ale registrului ADRESH dar e prea complicat.Iata un exempluDaca in registrul ADRESH se afla starea: 00001010 eu pot compara si verifica cu:label btfcs ADRESH.0 goto label btfss ADRESH,1 goto label btfcs ADRESH.2 goto label btfss ADRESH,3 goto label btfcs ADRESH,4 goto label btfcs ADRESH,5 goto label btfcs ADRESH,6 goto label btfcs ADRESH,7 goto label call oriceStiti voi ceva mai simplu?

• Replies 2
• Created
• Last Reply

#### Popular Days

Pt. PIC16xxxx poti folosi instructiuni de tip XOR, in caz de egalitate, rezultatul va fi nul si bitul Z din reg. STATUS setat. Eu am scris cateva macro-uri pt. astfel de operatii:

`;=================================================================================; => EqualTo : checks if a reg.(number) is equal to a given value (literal): =; if number==val then goto label_yes; else goto label_no;---------------------------------------------------------------------------------EqualTo macro number, val, label_yes, label_no	movlw	val	xorwf	number, W	btfsc	_Z	goto	label_yes	goto	label_no  endm;=================================================================================;=================================================================================; => EqualToReg : checks if a reg.(number) is equal to a given value (register): =; if number==reg then goto label_yes; else goto label_no;---------------------------------------------------------------------------------EqualToReg macro number, reg, label_yes, label_no	movfw	reg	xorwf	number, W	btfsc	_Z	goto	label_yes	goto	label_no  endm;=================================================================================`

Alte macro-uri utile:

`;=================================================================================; => Between : checks if a reg.(number) is in an interval (given by literals): [ ... ); if min<=number<max then goto label_yes; else goto label_no;---------------------------------------------------------------------------------Between macro number, min, max, label_yes, label_no 	movlw	min 	subwf	number, W 	btfss	_C 	goto	label_no 	movlw	max 	subwf	number, W 	btfsc	_C 	goto	label_no 	goto	label_yes  endm;=================================================================================;=================================================================================; => LessThan : checks if a reg.(number) is less than a given value (literal): <; if number<val then goto label_yes; else goto label_no;---------------------------------------------------------------------------------LessThan macro number, val, label_yes, label_no	movlw	val	subwf	number, W	btfss	_C	goto	label_yes	goto	label_no  endm;=================================================================================;=================================================================================; => LessThanReg : checks if a reg.(number) is less than a given value (register): <; if number<reg then goto label_yes; else goto label_no;---------------------------------------------------------------------------------LessThanReg macro number, reg, label_yes, label_no		movfw	reg	subwf	number, W	btfss	_C	goto	label_yes	goto	label_no  endm;================================================================================;=================================================================================; => LessOrEqualReg : checks if a reg.(number) is less than a given value (register): <=; if number<=reg then goto label_yes; else goto label_no;---------------------------------------------------------------------------------LessOrEqualReg macro number, reg, label_yes, label_no		movfw	number	subwf	reg, W	btfss	_C	goto	label_no	goto	label_yes  endm;================================================================================`

Edit: Exemple de utilizare:

`cblock 0x20    A, B, C, Dendc.......LessOrEqualReg A, B, L_Y1, L_N1  ...........L_Y1:          .......    ;;  Executed if  A<=B.......L_N1:          .......    ;;  Executed if  A>B...........EqualTo A, .56, L_Y2, L_N2...........L_Y2:          .......    ;;  Executed if  A==56.......L_N2:          .......    ;;  Executed if  A!=56`
##### Link to comment

Corect. Xorul iti detecteaza egalitatea intre 2 octeti.Daca vrei sa rafinezi un pic si lucrezi numai pe 8 biti (un registru), poti efectua o scadere intre valoarea variabilei (ADRESH in cazul tau) si valoarea pragului (de ex o constanta). Ai grija sa nu distrugi variabilele in urma operatiei. In fct de relatia dintre cele doua valori, se vor seta/reseta corespunzator Z si C. Experimenteaza un pic cu simulatorul, ca sa vezi ce si cum se intampla.Cirip

## Create an account or sign in to comment

You need to be a member in order to leave a comment

## Create an account

Sign up for a new account in our community. It's easy!

Register a new account

## Sign in

Already have an account? Sign in here.

Sign In Now
• ### Popular Now

×
• #### Activity

×
• Create New...

## Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.Terms of Use si Guidelines