-3

I am new to assembly language. Please help me how to find the higher bits after these instruction

MOV AX,08H
MOV BX, 07H
ADD AX,BX

I know a little bit shifting and rotating operation but i am not able to run the whole operation. Any suggestion will help me a lot. Thanks

Peter Cordes
  • 286,368
  • 41
  • 520
  • 731
Sajol
  • 5
  • 2
  • Ok, do you know addition? You can perform the addition in any number base you like, then translate that sum to binary. – Erik Eidt May 12 '22 at 21:50
  • Thanks for your reply. Then how to count all the higher bits? – Sajol May 12 '22 at 21:54
  • 2
    Can you explain what you mean by "counting" and also "higher bits"? Are you trying to write a program that does this? (Since the inputs are constants, you can compute the answer once, manually.) – Erik Eidt May 12 '22 at 22:02
  • `bsr cx, ax` will set CX = the bit-index of the highest `1` bit in AX. (Or leave it unmodified if AX was zero.) Is that your question? (If your code needs to run on a CPU before 386, see https://graphics.stanford.edu/~seander/bithacks.html#IntegerLogObvious for a slow way, and farther down that page for better ways.) – Peter Cordes May 12 '22 at 22:08
  • Thanks everyone. I got a solution. My problem was to count the 1's from a 8-bit binary number. – Sajol May 12 '22 at 22:18
  • 1
    Ok, well I'm glad you found an answer, but that's more or less unrelated to the question you asked, which sounds like you want the carry-out from addition, higher than some bit-position like the top of the register or the top of the low 8 bits. You might want to delete your question since it's not clear and future readers shouldn't spend their time trying to answer it. Or find an existing duplicate like [How to count the number of set bits in a 32-bit integer?](https://stackoverflow.com/q/109023) and close it – Peter Cordes May 12 '22 at 22:22
  • 1
    When you said "find the higher bits", did you mean "find the *set* bits", the `1` bits? That would conventionally be a "high" voltage in a physical circuit? In English we never say "high bit" to mean "set bit", we always use "high" or "higher" to talk about the position of a bit relative to other bits in a register. In electronics you can say that an external signal pulls a pin "high" or "low", but they're we're actually talking about physical voltage, not an abstract logical bit. – Peter Cordes May 12 '22 at 22:23

0 Answers0