Chaning bits individually? or merging registers x86
-
- Member
- Posts: 71
- Joined: Wed May 29, 2013 1:07 pm
Chaning bits individually? or merging registers x86
Hi I am trying to convert decimal into character I have noticed a pattern in the binary
0x01 = 00000001b
1 = 00110001b
My question is how can I change the last four bits of 0x01 into 0011 so it can be seen as a character?
If you could also give some examples that would be great thanks. I have looked into this already and can't find an answer
Many thanks
0x01 = 00000001b
1 = 00110001b
My question is how can I change the last four bits of 0x01 into 0011 so it can be seen as a character?
If you could also give some examples that would be great thanks. I have looked into this already and can't find an answer
Many thanks
1100110100010011
Re: Chaning bits individually? or merging registers x86
You convert an ascii encoded digit into its corresponding integer by the simple means of subtracting 48 from it (and vice versa).
-
- Member
- Posts: 71
- Joined: Wed May 29, 2013 1:07 pm
Re: Chaning bits individually? or merging registers x86
Ok thanks, Do you know how I would change individual bits just for future reference?
1100110100010011
Re: Chaning bits individually? or merging registers x86
Do this has anything to do with OS development?
-
- Member
- Posts: 71
- Joined: Wed May 29, 2013 1:07 pm
Re: Chaning bits individually? or merging registers x86
Of course it does read the title. My question was about changing bits individually or merging registers which is a processor question and it is important for OS development
1100110100010011
Re: Chaning bits individually? or merging registers x86
That is the sort of thing any assembly language or C programmer should know, long before he/she even thinks of embarking upon OS development.computertrick wrote:Of course it does read the title. My question was about changing bits individually or merging registers which is a processor question and it is important for OS development
Look up the assembly language OR, AND, XOR and NOT instructions, or the C ~, |, &, ^ operators.
-
- Member
- Posts: 71
- Joined: Wed May 29, 2013 1:07 pm
Re: Chaning bits individually? or merging registers x86
I am aware of all of those instructions my question was is their an instruction in 8086 to change a single bit that's what I was trying to get across
1100110100010011
Re: Chaning bits individually? or merging registers x86
No, that is absolutely not possible.computertrick wrote:I am aware of all of those instructions my question was is their an instruction in 8086 to change a single bit that's what I was trying to get across
Learn to read.
Re: Chaning bits individually? or merging registers x86
Those instructions do precisely that, and more besides. For example, xor ax, 4 would flip bit 2 of the ax register.computertrick wrote:I am aware of all of those instructions my question was is their an instruction in 8086 to change a single bit that's what I was trying to get across
For that matter, you can do it even without those instructions. add ax, 0x80 would set bit 7, and sub ax, 0x80 would clear it. That is elementary, and, if you haven't got that far, it will be a long time before you are ready for osdev.
Re: Chaning bits individually? or merging registers x86
Summon the triple /faceplam...computertrick wrote:Of course it does read the title. My question was about changing bits individually or merging registers which is a processor question and it is important for OS development
While OS development require excellent skills of all aspect, including flipping a bit, I suggest you read the Required_Knowledge.
Re: Chaning bits individually? or merging registers x86
BTS, BTR (80386 and later).
Re: Chaning bits individually? or merging registers x86
That is incorrect. What if the bit is already set (or clear)? Adding (or subtracting) would not have the desired result.For that matter, you can do it even without those instructions. add ax, 0x80 would set bit 7, and sub ax, 0x80 would clear it. That is elementary, and, if you haven't got that far, it will be a long time before you are ready for osdev.
Re: Chaning bits individually? or merging registers x86
What has that got to do with anything? or ax, 0x80 wouldn't change a bit which was already set, and "and ax, 0xff7f" wouldn't clear a bit which was already clear. That is in the nature of bitwise operations.iansjack wrote:That is incorrect. What if the bit is already set (or clear)? Adding (or subtracting) would not have the desired result.
Re: Chaning bits individually? or merging registers x86
Read the bit of your post that I quoted again. add is not and, sub is not or. add would clear a set bit (and affect other bits), sub would set a clear bit (and affect other bits). That is the nature of arithmetic operations.Casm wrote:What has that got to do with anything? or ax, 0x80 wouldn't change a bit which was already set, and "and ax, 0xff7f" wouldn't clear a bit which was already clear. That is in the nature of bitwise operations.iansjack wrote:That is incorrect. What if the bit is already set (or clear)? Adding (or subtracting) would not have the desired result.
Re: Chaning bits individually? or merging registers x86
If I wanted to convert a digit into its corresponding integer value, I could either do and ax, 0xcf or sub ax, 48, and which I did would depend upon the mood I was in at the time. Similarly, and ax, 0xdf and sub ax, 32 will both convert a lower case letter into an upper case letter (or clear the archive bit in an MS-DOS fille attribute byte).iansjack wrote: Read the bit of your post that I quoted again. add is not and, sub is not or. add would clear a set bit (and affect other bits), sub would set a clear bit (and affect other bits). That is the nature of arithmetic operations.
I don't remember saying that sub was the same as or (or and).