Home
JAQForum Ver 24.01
Log In or Join  
Active Topics
Local Time 10:57 01 Aug 2025 Privacy Policy
Jump to

Notice. New forum software under development. It's going to miss a few functions and look a bit ugly for a while, but I'm working on it full time now as the old forum was too unstable. Couple days, all good. If you notice any issues, please contact me.

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 Kingdom
Posts: 10310
Posted: 03:23pm 11 Nov 2022
Copy link to clipboard 
Print this post

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 Kingdom
Posts: 2170
Posted: 03:55pm 11 Nov 2022
Copy link to clipboard 
Print this post

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: Netherlands
Posts: 5089
Posted: 04:00pm 11 Nov 2022
Copy link to clipboard 
Print this post

If (current & new) == new then it can be programmed

Volhout
PicomiteVGA PETSCII ROBOTS
 
matherp
Guru

Joined: 11/12/2012
Location: United Kingdom
Posts: 10310
Posted: 04:04pm 11 Nov 2022
Copy link to clipboard 
Print this post

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 Kingdom
Posts: 2170
Posted: 04:12pm 11 Nov 2022
Copy link to clipboard 
Print this post

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 Kingdom
Posts: 10310
Posted: 04:18pm 11 Nov 2022
Copy link to clipboard 
Print this post

OK - got it - thanks both
 
DaveJacko
Regular Member

Joined: 25/07/2019
Location: United Kingdom
Posts: 83
Posted: 09:40pm 11 Nov 2022
Copy link to clipboard 
Print this post

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: Netherlands
Posts: 5089
Posted: 01:31pm 12 Nov 2022
Copy link to clipboard 
Print this post

In my world NOP was &hEA
PicomiteVGA PETSCII ROBOTS
 
Mixtel90

Guru

Joined: 05/10/2019
Location: United Kingdom
Posts: 7937
Posted: 03:13pm 12 Nov 2022
Copy link to clipboard 
Print this post

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 Kingdom
Posts: 2170
Posted: 03:20pm 12 Nov 2022
Copy link to clipboard 
Print this post

... 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 Kingdom
Posts: 7937
Posted: 05:27pm 12 Nov 2022
Copy link to clipboard 
Print this post

Yes.



;)
Mick

Zilog Inside! nascom.info for Nascom & Gemini
Preliminary MMBasic docs & my PCB designs
 
Print this page


To reply to this topic, you need to log in.

The Back Shed's forum code is written, and hosted, in Australia.
© JAQ Software 2025