;=============================================================================== ; Macro to rotate a register a variable number of positions to the right. ; The number of positions to rotate must be in another register. ; ; Input: ; value: Register with the value to be rotated. ; vacc: Access method (ACCESS or BANKED) for the value. ; positions: Register with the number of positions to rotate. ; pacc: Access method (ACCESS or BANKED) for the positions. ; ; Output: ; "value" register with the result. ; ; Changes: ; "value" register. ; ; Side effects: ; Flags Z and N may be affected. ; ; Notes: ; - If both registers use access method BANKED, both must reside in the ; same bank. ; - The code is isochronous (runs always in the same number of cycles). rrvar macro value,vacc,positions,pacc btfsc positions, 2, pacc swapf value, F, vacc btfsc positions, 1, pacc rrncf value, F, vacc btfsc positions, 1, pacc rrncf value, F, vacc btfsc positions, 0, pacc rrncf value, F, vacc endm ;=============================================================================== ; Macro to rotate a register a variable number of positions to the left. ; The number of positions to rotate must be in another register. ; ; Input: ; value: Register with the value to be rotated. ; vacc: Access method (ACCESS or BANKED) for the value. ; positions: Register with the number of positions to rotate. ; pacc: Access method (ACCESS or BANKED) for the positions. ; ; Output: ; "value" register with the result. ; ; Changes: ; "value" register. ; ; Side effects: ; Flags Z and N may be affected. ; ; Notes: ; - If both registers use access method BANKED, both must reside in the ; same bank. ; - The code is isochronous (runs always in the same number of cycles). rlvar macro value,vacc,positions,pacc btfsc positions, 2, pacc swapf value, F, vacc btfsc positions, 1, pacc rlncf value, F, vacc btfsc positions, 1, pacc rlncf value, F, vacc btfsc positions, 0, pacc rlncf value, F, vacc endm ;=============================================================================== ; Macro to rotate a register a fixed number of positions to the right. ; The number of positions to rotate must be a numeric constant. ; ; Input: ; value: Register with the value to be rotated. ; vacc: Access method (ACCESS or BANKED) for the value. ; positions: Constant with the number of positions to rotate. ; ; Output: ; "value" register with the result. ; ; Changes: ; "value" register. ; ; Side effects: ; Flags Z and N may be affected. ; ; Notes: ; - The code generated may range from one to four instructions. rrcon macro value,vacc,positions if positions & b'00000100' swapf value, F, vacc endif if positions & b'00000010' rrncf value, F, vacc rrncf value, F, vacc endif if positions & b'00000001' rrncf value, F, vacc endif endm ;=============================================================================== ; Macro to rotate a register a fixed number of positions to the left. ; The number of positions to rotate must be a numeric constant. ; ; Input: ; value: Register with the value to be rotated. ; vacc: Access method (ACCESS or BANKED) for the value. ; positions: Constant with the number of positions to rotate. ; ; Output: ; "value" register with the result. ; ; Changes: ; "value" register. ; ; Side effects: ; Flags Z and N may be affected. ; ; Notes: ; - The code generated may range from one to four instructions. rlcon macro value,vacc,positions if positions & b'00000100' swapf value, F, vacc endif if positions & b'00000010' rlncf value, F, vacc rlncf value, F, vacc endif if positions & b'00000001' rlncf value, F, vacc endif endm ;===============================================================================
;=============================================================================== ; Macro to rotate a register a variable number of positions to the right. ; The number of positions to rotate must be in another register. ; ; Input: ; value: Register with the value to be rotated. ; positions: Register with the number of positions to rotate. ; ; Output: ; "value" register with the result. ; ; Changes: ; "value" register, WREG. ; ; Side effects: ; Flag C is affected. ; ; Notes: ; - Both registers must reside in the same bank. ; - The code is isochronous (runs always in the same number of cycles). rrvar macro value,positions btfsc positions, 2 swapf value, F rrf value, W btfsc positions, 1 rrf value, F btfsc positions, 1 rrf value, F btfsc positions, 0 rrf value, F endm ;=============================================================================== ; Macro to rotate a register a variable number of positions to the left. ; The number of positions to rotate must be in another register. ; ; Input: ; value: Register with the value to be rotated. ; positions: Register with the number of positions to rotate. ; ; Output: ; "value" register with the result. ; ; Changes: ; "value" register, WREG. ; ; Side effects: ; Flag C is affected. ; ; Notes: ; - Both registers must reside in the same bank. ; - The code is isochronous (runs always in the same number of cycles). rlvar macro value,positions btfsc positions, 2 swapf value, F rlf value, W btfsc positions, 1 rlf value, F btfsc positions, 1 rlf value, F btfsc positions, 0 rlf value, F endm ;=============================================================================== ; Macro to rotate a register a fixed number of positions to the right. ; The number of positions to rotate must be a numeric constant. ; ; Input: ; value: Register with the value to be rotated. ; positions: Constant with the number of positions to rotate. ; ; Output: ; "value" register with the result. ; ; Changes: ; "value" register, "WREG". ; ; Side effects: ; Flag C is affected. ; ; Notes: ; - The code generated may range from one to five instructions. rrcon macro value,positions if positions & b'00000100' swapf value, F endif if positions & b'00000011' != 0 rrf value, W endif if positions & b'00000010' rrf value, F rrf value, F endif if positions & b'00000001' rrf value, F endif endm ;=============================================================================== ; Macro to rotate a register a fixed number of positions to the left. ; The number of positions to rotate must be a numeric constant. ; ; Input: ; value: Register with the value to be rotated. ; positions: Constant with the number of positions to rotate. ; ; Output: ; "value" register with the result. ; ; Changes: ; "value" register, WREG. ; ; Side effects: ; Flag C is affected. ; ; Notes: ; - The code generated may range from one to five instructions. rlcon macro value,positions if positions & b'00000100' swapf value, F endif if positions & b'00000011' != 0 rlf value, W endif if positions & b'00000010' rlf value, F rlf value, F endif if positions & b'00000001' rlf value, F endif endm ;===============================================================================
file: /Techref/microchip/math/bit/variablerotate.htm, 8KB, , updated: 2012/1/24 12:36, local time: 2024/12/22 16:47,
owner: IMB-yahoo-J86,
3.133.133.251:LOG IN
|
©2024 These pages are served without commercial sponsorship. (No popup ads, etc...).Bandwidth abuse increases hosting cost forcing sponsorship or shutdown. This server aggressively defends against automated copying for any reason including offline viewing, duplication, etc... Please respect this requirement and DO NOT RIP THIS SITE. Questions? <A HREF="http://massmind.ecomorder.com/Techref/microchip/math/bit/variablerotate.htm"> Rotate a byte a variable number of positions</A> |
Did you find what you needed? |
Welcome to ecomorder.com! |
Welcome to massmind.ecomorder.com! |
.