Home      Projects     Experiments     Circuits     Theory     BLOG     PIC Tutorials     Time for Science

Byte Orientated Instructions

The byte orientated instructions are instructions to alter a complete byte of a resister:

 Instruction Description RLF f , d Rotate Left through carry. The bits are rotated one position left through the Carry. If d is 0 the result is stored in the W register, if d is 1 the result is stored back to the file register 'f'. RRF f , d Rotate Right through carry. The bits are rotated one position right through the Carry. If d is 0 the result is stored in the W register, if d is 1 the result is stored back to the file register 'f'. INCF f , d The contents of register 'f' are increased by 1. If d is 0 the result is stored in the W register, if d is 1 the result is stored back to the file register 'f'. DECF f , d The contents of register 'f' are decreased by 1. If d is 0 the result is stored in the W register, if d is 1 the result is stored back to the file register 'f'. INCFSZ f , d The contents of register 'f' are increased by 1. If d is 0 the result is stored in the W register, if d is 1 the result is stored back to the file register 'f'. If the result is '0', the very next instruction is read as 'NOP' and is not executed. DECFSZ f , d The contents of register 'f' are decreased by 1. If d is 0 the result is stored in the W register, if d is 1 the result is stored back to the file register 'f'. If the result is '0', the very next instruction is read as 'NOP' and is not executed. CLRF f The register 'f' is cleared. CLRW The working register W is cleared.

Now, let's see the instructions one by one:

RLF f , d

This instruction will shift all bits of register 'f' one position left. The MSB bit will be sent to the Carry, and the Carry bit will be sent back to the register's LSB. If d is 0 the result is stored in the W register, if d is 1 the result is stored back to the file register 'f'. The status that may be affected from this instruction are:

• C - Carry

Example
```;This example requires that you have declare a file register for example
;TempRegister          equ 0x20
bcf Carry             ;Clear the Carry bit
movlw b'10101111'     ;the W register has the byte '10101111' loaded
movwf TempRegister    ;The TempRegister has now the value '10101111'
rlf TempRegister,f      ;Now, the Tempregister has the value '01011110'
;and the Carry is SET
```

RRF f , d

This instruction will shift all bits of register 'f' one position right. The LSB bit will be sent to the Carry, and the Carry bit will be sent back to the register's MSB. If d is 0 the result is stored in the W register, if d is 1 the result is stored back to the file register 'f'. The status that may be affected from this instruction are:

• C - Carry

Example
```;This example requires that you have declare a file register for example
;TempRegister          equ 0x20
bcf Carry             ;Clear the Carry bit
movlw b'10101111'     ;the W register has the byte '10101111' loaded
movwf TempRegister    ;The TempRegister has now the value '10101111'
rrf TempRegister,f      ;Now, the Tempregister has the value '01010111'
;and the Carry is SET
```

INCF f , d

The contents of register 'f' are increased by 1. If d is 0 the result is stored in the W register, if d is 1 the result is stored back to the file register 'f'. The status that may be affected from this instruction are:

• Z - Zero

Example
```;This example requires that you have declare a file register for example
;TempRegister          equ 0x20
movlw d'80'           ;the W register has the decimal value '80'
movwf TempRegister    ;The TempRegister has now the decimal value '80'
incf TempRegister,f   ;Now, the Tempregister has the decimal value '81'
```

DECF f , d

The contents of register 'f' are decreased by 1. If d is 0 the result is stored in the W register, if d is 1 the result is stored back to the file register 'f'. The status that may be affected from this instruction are:

• Z - Zero

Example
```;This example requires that you have declare a file register for example
;TempRegister          equ 0x20
movlw d'80'           ;the W register has the decimal value '80'
movwf TempRegister    ;The TempRegister has now the decimal value '80'
decf TempRegister,f   ;Now, the Tempregister has the decimal value '79'
```

INCFSZ f , d

The contents of register 'f' are increased by 1. If d is 0 the result is stored in the W register, if d is 1 the result is stored back to the file register 'f'. If the result is '0', then the very next instruction is NOT executed. instead, a 'NOP' instructions is executed. No status is affected from this instruction.

Example
```;This example requires that you have declare a file register for example
;TempRegister          equ 0x20
movlw d'80'             ;the W register has the decimal value '80'
movwf TempRegister      ;The TempRegister has now the decimal value '80'
incfsz TempRegister,f   ;Now, the Tempregister has the decimal value '81'
movlw b'11111111'       ;The W register has the value '11111111'
movwf TempRegister      ;The TempRegister has now the value '11111111'
incfsz TempRegister,f   ;Now, the Tempregister is increased and has the value '0'
movlw 0x30              ;The result was '0'. This instruction is NOT executed
```

DECFSZ f , d

The contents of register 'f' are decreased by 1. If d is 0 the result is stored in the W register, if d is 1 the result is stored back to the file register 'f'. If the result is '0', then the very next instruction is NOT executed. instead, a 'NOP' instructions is executed. No status is affected from this instruction.

Example
```;This example requires that you have declare a file register for example
;TempRegister          equ 0x20
movlw d'80'             ;the W register has the decimal value '80'
movwf TempRegister      ;The TempRegister has now the decimal value '80'
decfsz TempRegister,f   ;Now, the Tempregister has the decimal value '79'
movlw b'00000001'       ;The W register has the value '00000001'
movwf TempRegister      ;The TempRegister has now the value '00000001'
decfsz TempRegister,f   ;Now, the Tempregister is decreased and has the value '0'
movlw 0x30              ;The result was '0'. This instruction is NOT executed
```

CLRF f

The register 'f' is cleared. The Zero Status is always SET:

• Z - Zero

Example
```;This example requires that you have declare a file register for example
;TempRegister          equ 0x20
movlw d'80'             ;the W register has the decimal value '80'
movwf TempRegister      ;The TempRegister has now the decimal value '80'
clrf TempRegister       ;The TempRegister has now the value '0'
```

CLRW

The working register W is cleared. The Zero Status is always SET:

• Z - Zero

Example
```          movlw d'80'             ;the W register has the decimal value '80'
clrw                    ;The W register has now the value '0'
```

There is an online test to check your knowledge on this page. You may reveal the test with the following button:

Previous page ---- Next page

Go back to the book contents

Go to the discussion forum of this book

 At 10 July 2012, 22:02:09 user Chris wrote:   [reply @ Chris]@Giorgos Lazaridis My pleasure! Superb set of tutorials by the way, thank you for creating them and posting them up :-)At 10 July 2012, 20:30:35 user Giorgos Lazaridis wrote:   [reply @ Giorgos Lazaridis]@Chris my bad. thanks!At 10 July 2012, 13:25:28 user Chris wrote:   [reply @ Chris]Hi, RLF and RRF I think movlw b'10101111' movwf TempRegister rlf '10101111',f should be movlw b'10101111' movwf TempRegister rlf Tempregister,f same for RRFAt 14 September 2011, 11:19:35 user Kammenos wrote:   [reply @ Kammenos]@creativefla good point. It seems that the question had false answer :(. It happens unfortunately. Thanks for noticing. Regarding the: BCF Carry RLF tempreg,1 RLF tempreg,1 If the results are stored in W register (it should be tempreg,0), then the tempregister remains as is all the time. In your example (tempreg,1) the end result will be b'11111101' because carry is net cleared between the two RLF instructions.At 3 September 2011, 22:09:07 user creativefla wrote:   [reply @ creativefla]another question is, in question 4, why "D) RLF tempregister,1" doesnt cause the carry to go SET? wouldnt "d" part in "RLF f ,d" only determine which register the result will be saved (ie, either W or file register)? which can be seen from question 2. if that is the case, if i double rotate b'11111111' under; BCF Carry RLF tempreg,1 RLF tempreg,1 will the end result of tempreg become b'11111100' since the carry will only go SET if the result is saved in W register? thank you. =))At 3 September 2011, 21:36:34 user creativefla wrote:   [reply @ creativefla]RLF f,d rlf '10101111',f ;Now, the Tempregister has the value '01011110' ;and the Carry is SET hi, im quite confused with this instruction because i dont see that its in "RLF f, d" format. =S

No part of this publication may be reproduced, stored in a retrieval system or transmitted in any form or by any means, electronic, mechanical, photocopying, recording, scanning or otherwise without the prior written permission of the author.

All trademarks used are properties of their respective owners.

 HOT in heaven!

 Disclaimer Book Contents Discussion forum

 NEW in heaven! New Theory: AC electric motor working principle