Modify only the LSB of a memory cell

143 views Asked by At

Is it possible to write a sequence of instructions that will place a 1 in the least significant bit of the memory cell at address B3 without disturbing the other bits in the memory cell?

The machine instructions I am referring to is the STOP, ADD, SWITCH, STOP, LOAD, ROTATE etc.

2

There are 2 answers

1
Tobias On

I think ORing it with 1 will do the job ain't it:
algo:

byte= [data at 0xB3]
byte = byte | 0x01

this works fine with me in developing for 8051 MCUs.

0
Marc Gravell On

Clarification: this question was originally tagged C#; since it wasn't the OP that re-tagged it, I'll leave this here until the OP's intentions are clearer.

C# is a high-level programming language, which compiles down to IL, not machine code. As such: no, there is absolutely no supported mechanism for performing specific machine code operations (and even if there were, it couldn't possibly port between langauges).

You can do high level bit operations, using the operators on the integer-based types; and if you really want you can write IL, either building it manually (ilasm), or at runtime via DynamicMethod / ILGenerator - but these still only deal with CIL opcodes, not machine codes.