You are on page 1of 3

Experiment No.

(B)

Dividing a 16 bit number by 4 in PIC18 F

EXPERIMENT NO. (B) Dividing a 16 bit number by 4 in PIC18 F

Program Objective:

Write a program to divide a 16 bit number by 4.The value of the number is 0181H. Number is available in REG1 (01H) and REG2 (81H)

Software Requirement:

Algorithm:

Division 1. Initialize the Register1 to 01H and Register2 to 81H. 2. Move the upper 8 bits of the number i.e. 01H into address location pointed by register1 and lower 8 bits i.e. 81H into the address pointed by register2. 3. Initialize the counter to 2 as the contents are to be rotated twice. 4. Clear the carry flag. 5. Rotate the contents of register1 right through carry first and store the rotated contents in register1 itself. 6. Rotate the contents of register2 right through carry and store the rotated contents in register2 itself. 7. Decrement counter. Now the number is divided by 2. 8. Start the next loop for the number to be rotated right again so that we get the number divided by 4.

PROGRAM: REG1 EQU 0x01 REG2 EQU 0x81 MOVLW 0x01 MOVWF REG1,0 MOVLW 0x81 MOVLW 0x02 NEXT: BCF STATUS,0,0 RLCF REG1,1,0 RLCF REG2,1,0 DECF WREG,0,0 BNZ NEXT //Decrement counter and store back in WREG //initialising the 16 bit number //initialising counter //Carry flag is cleared //left rotation of REG2

You might also like