; ; Just check out MPLAB .include "p24Hxxxx.inc" .global __reset ;The label for the first line of code. .bss ;unitialized data section ;;These start at location 0x0800 because 0-0x07FF reserved for SFRs count: .space 2 ;Allocating space (in bytes) to variable. x: .space 2 ;Allocating space (in bytes) to variable. ;.............................................................................. ;Code Section in Program Memory ;.............................................................................. .text ;Start of Code section __reset: ; first instruction located at __reset label mov #__SP_init, w15 ;Initalize the Stack Pointer mov #__SPLIM_init,W0 mov W0, SPLIM ;Initialize the stack limit register ;__SP_init set by linker to be after allocated data ;User Code starts here. .equ xvalue, 23 ;; Store x in W4 ; x = xvalue mov #xvalue, W0 mov WREG,x ; count = 0 clr count bra tstloop xodd: ;; X is odd, WREG is X/2, C is 1 addc x ;; X = X + X/2 + 1 = (3*X+1)/2 when X is odd inc2 count bra tstloop xeven: ;; X is even, WREG is X/2, C is 0 mov WREG,x ;; X = X/2 inc count tstloop: lsr x,WREG ;; WREG = x/2, C = x%2 bra NC,xeven bra NZ,xodd done: goto done ;Place holder for last line of executed code .end ;End of program code in this file