how to shift bits in memory
- Posted by gareth_mcdaid Jan 24, 2011
- 1290 views
Hi everyone
I need to know how to shift bits in memory, I’m using version 3.1 of euphoria.
I’ve look in the manual for a inbuilt function to shift bits around in memory, but not been able to find one.
Do I need to write my own?
include misc.e include machine.e --The pic12f675 puts(1," pic12f675 \n") constant rom_size = 1024 --each opcode is incoded with 14 bits. --wraping is used because the program counter --is able to address upto 8kb constant ram_size = 256 --the ram is 256 bytes it is split into two banks --each bank is 128 bytes. --the general purpose ram is mapped across both banks --and starts at location 20h-5fh or 32-96 --constant eeprom_size = 128 atom rom atom ram sequence stack integer pc -- program counter integer regw -- working registery integer bank -- selected bank procedure init() pc = 0 regw = 0 bank = 0 stack={} rom = allocate(rom_size*2) ram = allocate(ram_size) end procedure procedure deinit() free(rom) free(ram) end procedure procedure reset() free(rom) free(ram) rom = allocate(rom_size*2) ram = allocate(ram_size) pc = 0 regw = 0 bank = 0 stack= {} end procedure procedure loadcart() integer fn,char,pos fn = open("data.bin","rb") for i=0 to 63 do char=getc(fn) poke(ram+32+i , char) end for pos=0 for i=0 to (rom_size/2)-1 do char=getc(fn) poke(rom+pos,char) char=getc(fn) poke(rom+pos+1,char) pos+=2 end for close(fn) end procedure function peek2(atom address) return peek(address)*256 + peek(address+1) end function integer instr integer optype integer opcode procedure execute_op() --?peek(rom) --?peek(rom+1) instr = peek2(rom+pc) instr = and_bits(instr,#3FFF) -- trim of the 2 msbits optype = and_bits(instr,#3000) ?instr ?optype if optype=0 then -- BYTE-ORIENTED FILE REGISTER OPERATIONS opcode = and_bits(instr,#F00) if opcode=8 then puts(1,"movf\n") end if ?opcode elsif optype=1 then -- BIT-ORIENTED FILE REGISTER OPERATIONS else -- LITERAL AND CONTROL OPERATIONS end if pc+=2 end procedure init() loadcart() execute_op() sleep(1)