![]() |
Forum Index : Microcontroller and PC projects : Brain fade - help wanted for simple algorithm - logic puzzle
Author | Message | ||||
matherp Guru ![]() Joined: 11/12/2012 Location: United KingdomPosts: 10310 |
Flash memory can only be written by converting bits set to 1 to 0. When flash is erased all bits are set to 1 Therefore if a byte is set to &HFF then by definition it can be overwritten but what if the byte in flash is &Bxyxyxyxy where x and y are either 1 or 0 Can it be overwritten by a replacement byte &Babababab ? At a bit level this is easy: OK_to_overwrite=1 For all bits in a byte if bit in flash = 0 and bit in replacement = 1 then OK_to_overwrite=0 exit for endif next But it should be possible to do this at a byte level using a single statement combining XOR/AND/OR/NOT is some way. I can't see it at the moment so ideas appreciated for the most efficient algorithm |
||||
CaptainBoing![]() Guru ![]() Joined: 07/09/2016 Location: United KingdomPosts: 2170 |
from my experimenting a while back, I found the writing of bits to be ANDed between what's already there and what you want to write. You can write to a given cell any number of times, but it is always an aggregation of the zero bits. I do touch on this in my article here (hate to bang the drum but at least it is pertinent this time)... back in the 80s I had use of an EPROM programmer that would read the ROM, AND it with your target code and then decide if you could burn it in without erasing - same process, only zero bits got burned and if you tried to burn a 1 over an existing 0 it would result in a corrupt ROM. Saved time occasionally. It used to take 30mins to erase the darn thing but I don't remember being able that often to burn a new image over an old. Was always a dozen "spare" EPROMS in the eraser. Edited 2022-11-12 02:06 by CaptainBoing |
||||
Volhout Guru ![]() Joined: 05/03/2018 Location: NetherlandsPosts: 5089 |
If (current & new) == new then it can be programmed Volhout PicomiteVGA PETSCII ROBOTS |
||||
matherp Guru ![]() Joined: 11/12/2012 Location: United KingdomPosts: 10310 |
Don't understand. 0 can be written on top of 0 so AND doesn't work unless I am missing something A XOR B gives the bits that are different but 1:0 is OK whereas 0:1 isn't. 1:1 and 0:0 are both OK |
||||
CaptainBoing![]() Guru ![]() Joined: 07/09/2016 Location: United KingdomPosts: 2170 |
Either you are playing some 4D chess or I don't understand what you are trying to do (I favour the latter) this is what I found: OK_to_overwrite=((FlashByte AND ReplacementByte)=ReplacementByte) Edited 2022-11-12 02:13 by CaptainBoing |
||||
matherp Guru ![]() Joined: 11/12/2012 Location: United KingdomPosts: 10310 |
OK - got it - thanks both |
||||
DaveJacko Regular Member ![]() Joined: 25/07/2019 Location: United KingdomPosts: 83 |
in the 80's NOP was often h'00' leading to the common phrase 'can you NOP it out?' (writing video games in assembler in 2716 EEproms ) Try swapping 2 and 3 over |
||||
Volhout Guru ![]() Joined: 05/03/2018 Location: NetherlandsPosts: 5089 |
In my world NOP was &hEA PicomiteVGA PETSCII ROBOTS |
||||
Mixtel90![]() Guru ![]() Joined: 05/10/2019 Location: United KingdomPosts: 7937 |
That's because you were a heathen and didn't worship at the church of the Holy Z80, Volhout. ![]() Weren't the CPU wars fun? ![]() Mick Zilog Inside! nascom.info for Nascom & Gemini Preliminary MMBasic docs & my PCB designs |
||||
CaptainBoing![]() Guru ![]() Joined: 07/09/2016 Location: United KingdomPosts: 2170 |
... and the 8080/85 - of which admittedly the Z80 was a shameless rip should I get me coat as later a NOP for me was 4E71 (ooh! 16 bit snob!)? ![]() Edited 2022-11-13 01:35 by CaptainBoing |
||||
Mixtel90![]() Guru ![]() Joined: 05/10/2019 Location: United KingdomPosts: 7937 |
Yes. ;) Mick Zilog Inside! nascom.info for Nascom & Gemini Preliminary MMBasic docs & my PCB designs |
||||
![]() |
![]() |
The Back Shed's forum code is written, and hosted, in Australia. | © JAQ Software 2025 |