# Determining if set bits in the first letter of name is odd or even

I'm a beginner in assembly language. My question is, how do I determine whether the number of set bits in the first letter of my first name is odd or even? I'm only using the 16-bit registers for my code. Thanks for your help.

## Comments

• : I'm a beginner in assembly language. My question is, how do I determine whether the number of set bits in the first letter of my first name is odd or even? I'm only using the 16-bit registers for my code. Thanks for your help.
:
:

I just do Pascal Inline assembly so you may need to modify it a bit, but this should give you the idea. CX will contain a 1 if there is an odd number of bits and a 0 if there is an even number.

[code]
Mov Ax, Word Ptr Letter
Mov Bx, 1
Mov Cx, 0
@Loop:
Test Ax, Bx
Jz @Next
Xor Cx, 1
@Next:
Shl Bx, 1
Cmp Bx, \$80
Jle @Loop
[/code]

Phat Nat
• Thanks for your help Nat!

: : I'm a beginner in assembly language. My question is, how do I determine whether the number of set bits in the first letter of my first name is odd or even? I'm only using the 16-bit registers for my code. Thanks for your help.
: :
: :
:
: I just do Pascal Inline assembly so you may need to modify it a bit, but this should give you the idea. CX will contain a 1 if there is an odd number of bits and a 0 if there is an even number.
:
: [code]
: Mov Ax, Word Ptr Letter
: Mov Bx, 1
: Mov Cx, 0
: @Loop:
: Test Ax, Bx
: Jz @Next
: Xor Cx, 1
: @Next:
: Shl Bx, 1
: Cmp Bx, \$80
: Jle @Loop
: [/code]
:
: Phat Nat
:

Sign In or Register to comment.

#### Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!