Actually it did work: I was putting in the binary when I should have been putting in the gray code
Here's the example combined with bin2gry then gry2bin
this is using Microchip's mplab simulator.
==================================
list p=12c509A ; list directive to define processor
#include <p12c509A.inc> ; processor specific variable definitions
__CONFIG _CP_OFF & _WDT_OFF & _MCLRE_OFF & _IntRC_OSC
cblock 0x10
gry_in
bin_out
count
temp
endc
ORG 0x000 ; coding begins here
reset movwf OSCCAL ; update register with factory cal value
goto init
init clrf STATUS ;
clrf GPIO ;
movlw b'00101001' ;
OPTION ;
movlw 0x10 ;
TRIS GPIO ;
clrf GPIO ; initialize the output bits on GPIO
;=====above is just pic setup=====================
; setup for conversion
movlw 0x76 ; 0x76(hex)-->0x4D(gray) expected result
;================================
; Binary to Gray Code routine
; entry: with binary in w
; exit with Grey result: in w
; trashes gry_in contents during conversion
; uses: gry_in,temp
; ie 2 ram locations
;================================
bin2Gry
movwf gry_in ;
movwf temp
bcf STATUS,C
rrf temp
movf temp,w
xorwf gry_in,w
;==end bin2gry===================
;setup for reverse conversion
movwf gry_in
nop ; place to set break point
;================================
; Gray Code to binary routine
; entry: with grey code in: gry_in
; exit with binary result: in bin_out
; trashes gry_in contents during conversion
; uses: gry_in,bin_out,count,temp
; ie 4 ram locations
;================================
gry2bin
movlw 0x08 ;set counter
movwf count
clrf temp
clrf bin_out
g_loop
movf gry_in,w ; get gray code in w
xorwf temp ; xor msb w/ 0
rlf temp,w ; rotate into carry
rlf bin_out ; carry rot's into bin_out
rlf gry_in ; shift gry_in for next bit
decfsz count ; chk if 8 bits done
goto g_loop ; else gloop
;==end gry2bin===================
nop ; place to set break point
;*************************************************************************
end ; directive 'end of program'
;*************************************************************************