I am having trouble understanding the concept of how to address individual bits in a register.  For instance, if I want to look at the last bit of a Register AX and see if it is a 1 or 0.

I've looked online and in books but to no avail.  In c++ I would copy the string into an array, assign to a temp variable and test for 1 or 0.  Can anyone give me an idea how to do this in 8086 Assembly language?
Posted on 2010-02-14 15:15:45 by tejaso

Posted on 2010-02-14 15:38:31 by JimmyClif


I would just go with the trusty AND and TEST instructions (which would also be the best way to test a bit in C++: the & operator).
Basically: if (x & (1 << n)) { // Bit n is set }
Posted on 2010-02-15 02:19:17 by Scali
how about setting just one bit and popping it onto the stack so I could have a 9-bit signed int (int8 but from -255 - 255) or a bool stored as a lone bit (also I realise this may be a bad idea but not why? please explain this to me)
Posted on 2010-08-10 14:56:19 by danielrhodea
Acquaint yourself with the x86 architecture and how the stack works, and you'll end up answering your own question.

Read The Stack @ ASM Book & Stack @ OSDev.org.
Posted on 2010-08-10 16:01:15 by SpooK
  you could also Rotate or shift but it seems TEST is the most appropriate.

  test ax,1000000000000000b
  jz its_zero
  do stuff for one
  jmp somwhere
  do stuff for one


  shl/rcl ax,1
  jnz/jnc it_zero
  do stuff for one
  jmp somwhere
  do stuff for zero
Posted on 2010-09-15 17:38:00 by xandaz