Chaning bits individually? or merging registers x86

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
computertrick
Member
Member
Posts: 71
Joined: Wed May 29, 2013 1:07 pm

Chaning bits individually? or merging registers x86

Post by computertrick »

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 :)
1100110100010011
Casm
Member
Member
Posts: 221
Joined: Sun Oct 17, 2010 2:21 pm
Location: United Kingdom

Re: Chaning bits individually? or merging registers x86

Post by Casm »

You convert an ascii encoded digit into its corresponding integer by the simple means of subtracting 48 from it (and vice versa).
computertrick
Member
Member
Posts: 71
Joined: Wed May 29, 2013 1:07 pm

Re: Chaning bits individually? or merging registers x86

Post by computertrick »

Ok thanks, Do you know how I would change individual bits just for future reference?
1100110100010011
User avatar
bluemoon
Member
Member
Posts: 1761
Joined: Wed Dec 01, 2010 3:41 am
Location: Hong Kong

Re: Chaning bits individually? or merging registers x86

Post by bluemoon »

Do this has anything to do with OS development?
computertrick
Member
Member
Posts: 71
Joined: Wed May 29, 2013 1:07 pm

Re: Chaning bits individually? or merging registers x86

Post by computertrick »

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
Casm
Member
Member
Posts: 221
Joined: Sun Oct 17, 2010 2:21 pm
Location: United Kingdom

Re: Chaning bits individually? or merging registers x86

Post by Casm »

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
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.

Look up the assembly language OR, AND, XOR and NOT instructions, or the C ~, |, &, ^ operators.
computertrick
Member
Member
Posts: 71
Joined: Wed May 29, 2013 1:07 pm

Re: Chaning bits individually? or merging registers x86

Post by computertrick »

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
User avatar
dozniak
Member
Member
Posts: 723
Joined: Thu Jul 12, 2012 7:29 am
Location: Tallinn, Estonia

Re: Chaning bits individually? or merging registers x86

Post by dozniak »

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
No, that is absolutely not possible.
Learn to read.
Casm
Member
Member
Posts: 221
Joined: Sun Oct 17, 2010 2:21 pm
Location: United Kingdom

Re: Chaning bits individually? or merging registers x86

Post by Casm »

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
Those instructions do precisely that, and more besides. For example, xor ax, 4 would flip bit 2 of the ax register.

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.
User avatar
bluemoon
Member
Member
Posts: 1761
Joined: Wed Dec 01, 2010 3:41 am
Location: Hong Kong

Re: Chaning bits individually? or merging registers x86

Post by bluemoon »

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
Summon the triple /faceplam...

While OS development require excellent skills of all aspect, including flipping a bit, I suggest you read the Required_Knowledge.
User avatar
iansjack
Member
Member
Posts: 4711
Joined: Sat Mar 31, 2012 3:07 am
Location: Chichester, UK

Re: Chaning bits individually? or merging registers x86

Post by iansjack »

BTS, BTR (80386 and later).
User avatar
iansjack
Member
Member
Posts: 4711
Joined: Sat Mar 31, 2012 3:07 am
Location: Chichester, UK

Re: Chaning bits individually? or merging registers x86

Post by iansjack »

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.
That is incorrect. What if the bit is already set (or clear)? Adding (or subtracting) would not have the desired result.
Casm
Member
Member
Posts: 221
Joined: Sun Oct 17, 2010 2:21 pm
Location: United Kingdom

Re: Chaning bits individually? or merging registers x86

Post by Casm »

iansjack wrote:
That is incorrect. What if the bit is already set (or clear)? Adding (or subtracting) would not have the desired result.
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.
User avatar
iansjack
Member
Member
Posts: 4711
Joined: Sat Mar 31, 2012 3:07 am
Location: Chichester, UK

Re: Chaning bits individually? or merging registers x86

Post by iansjack »

Casm wrote:
iansjack wrote:
That is incorrect. What if the bit is already set (or clear)? Adding (or subtracting) would not have the desired result.
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.
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
Member
Member
Posts: 221
Joined: Sun Oct 17, 2010 2:21 pm
Location: United Kingdom

Re: Chaning bits individually? or merging registers x86

Post by Casm »

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.
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).

I don't remember saying that sub was the same as or (or and).
Locked