| ||
Byte Orientated Instructions The byte orientated instructions are instructions to alter a complete byte of a resister:
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:
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:
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:
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:
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:
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:
Example movlw d'80' ;the W register has the decimal value '80' clrw ;The W register has now the value '0' Confirm your knowledge There is an online test to check your knowledge on this page. You may reveal the test with the following button: Comments
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. Read the Disclaimer
All trademarks used are properties of their respective owners.
Copyright © 2007-2009 Lazaridis Giorgos. All rights reserved. |
|
Contact
Forum
Projects
Experiments
Circuits
Theory
BLOG
PIC Tutorials
Time for Science
RSS
Site design: Giorgos Lazaridis © Copyright 2008 Please read the Terms of services and the Privacy policy |