
Counting the number of zeros in a binary representation using assembly language?
Hi
Could anyone suggest how can I count the number of zeros found in a binary representation using assembly language.
For example if the user inputs
20
The output should be
30
Since 20 – 00..010100 (using 32 bits) and contains a total number of 30 zeros.
Thank you
Shifting a register left with the SHL instruction pushes the most significant bit into the carry flag. Therefore, if a 1 was the most significant bit and its shifted left, the carry flag is set, if the most significant bit was 0 it wont be set.
Write a loop that shifts the register you have your input number in to the left 32 times. In this loop have a JC (jump if carry is set / jump no carry) instruction to jump over an instruction where you increment a register containing the sum of your zeros. Heres an untested code snippet:
xor ebx,ebx
mov ecx,32
shiftl:
shl eax,1
jc $+2
inc ebx
loop shiftl
EBX would now contain the number of zeros in the value contained within EAX. Keep in mind that in order to display the number of zeros you will have to convert the value in EBX to to ascii.
Upfront CFD for the Drilling Industry – tricone bit assembly
| Warhammer 40K Tyranid Bits Hive Tyrant / Swarmlord Torso Assembly $19.99 |
|
| LEMAN RUSS TRACK ASSEMBLY SPRUE Warhammer 40K Imperial Guard Bits $19.99 |
|
| WARHAMMER 40K BIN BITS DARK ELDAR TALOS – TORSO ASSEMBLY $17.99 |
|
| WARHAMMER 40K BIN BITS BLOOD ANGELS FURIOSO – 2x ARM ASSEMBLY $15.79 |
|
| WARHAMMER 40K BIN BITS CHAOS SPACE MARINES LAND RAIDER – HULL ASSEMBLY $14.99 |
|
| WARHAMMER 40K BIN BITS DARK ELDAR VENOM – HULL ASSEMBLY $14.99 |
|
| Warhammer 40K Tyranid Bits Trygon / Mawloc Tail Assembly $14.99 |
|
| Warhammer 40K: Necron Triarch Stalker Cannon Assembly Bits (NE31) $13.99 |
|
| Warhammer 40K Tyranid Bits Tyrannofex / Tervigon Tail Assembly $12.99 |
|
| WAR ALTAR GRIFFON STATUE ASSEMBLY Warhammer Fantasy Empire Bits $11.99 |
|
| TRIARCH STALKER CHASSIS & LEG ASSEMBLY Warhammer 40K Necron Bits $11.09 |
|
| TRIARCH STALKER PILOT & COCKPIT ASSEMBLY Warhammer 40K Necron Bits $11.09 |
|
| Space Marines Drop Pod Central Weapon Engine Assembly plastic bits Warhammer 40k $11.00 |
|
| *WARHAMMER BITS TOMB KINGS KNIGHTS – 3x HOOD ASSEMBLY $10.99 |
|
| Warhammer 40K: Space Marine Land Raider Side Hull Assembly Bits (18K) $10.99 |
|
| WARHAMMER 40K BITS NECRON TRIARCH STALKER – CANNON ASSEMBLY $10.50 |
|
| Warhammer 40K Necron Bits Doomsday / Ghost Ark Chassie Ribs & Rib Assembly $9.99 |
|
| Warhammer 40K Tyranid Bits Tyrannofex / Tervigon Tail Assembly $9.99 |
|
| RAVAGER HULL ASSEMBLY Warhammer 40k Dark Eldar Bits $9.99 |
|
| WARHAMMER 40K BIN BITS SPACE MARINE LAND SPEEDER – TOP ASSEMBLY $9.99 |
|
| WARHAMMER 40K BIN BITS SPACE MARINE LAND SPEEDER – BOTTOM ASSEMBLY $9.99 |
|
| *WARHAMMER BITS SKAVEN SCREAMING BELL- CHASSIE ASSEMBLY $9.99 |
|
| WARHAMMER 40K BIN BITS FORTRESS OF REDEMPTION – WALKWAY ASSEMBLY $9.99 |
|
| *WARHAMMER 40K BITS TYRANID TRYGON – HEAD BASE ASSEMBLY $9.99 |
|
| 40K Imperial Guard Manticore Launcher Assembly Bits S $9.95 |
|
| WAR ALTAR HULL ASSEMBLY Warhammer Fantasy Empire Bits $9.49 |
|
| HURRICANUM / LUMINARK ASSEMBLY & EXTRAS Warhammer Fantasy Empire Bits $9.49 |
|
| Warhammer 40K: Necron Triarch Stalker Cockpit Assembly Bits (NE22) $8.99 |
|
| HURRICANUM HULL ASSEMBLY Warhammer Fantasy Empire Bits $8.99 |
|
| Warhammer 40K: Tau Sky Ray Lower Turret Assembly Bits (BA33) $8.25 |
|
| WARHAMMER BIN BITS EMPIRE CANNON – CANNON ASSEMBLY $7.99 |
|
| *WARHAMMER BITS HIGH ELF BOLT THROWER- THROWER ASSEMBLY $7.99 |
|
| PREDATOR HULL ASSEMBLY Chaos Marine Bits Warhammer 40K $7.49 |
|
| WARHAMMER 40K BIN BITS CHAOS SPACE MARINES RHINO – HULL ASSEMBLY $7.49 |
|
| WARHAMMER 40K BIN BITS CHAOS SPACE MARINES PREDATOR – HULL ASSEMBLY $7.49 |
|
| Necrons Barge Chasis & Thruster Assembly Bits Pack Necron $7.19 |
|
| *WARHAMMER 40K BITS ORK DEFF DREAD – TORSO ASSEMBLY $6.99 |
|
| WARHAMMER 40K BIN BITS GREY KNIGHTS DREADKNIGHT – ARM ASSEMBLY $6.49 |
|
| Necrons Ghost Ark Thruster Engines Assembly Bits Pack Necron $6.39 |
|
| Necrons Command Barge Tail Crescent Assembly Bits Pack $6.39 |
|
| Dremel 220-01 Rotary Tool Work Station $36.72 Turn that Dremel rotary tool into a drill press with this rotary tool workstation from Dremel. The station accepts several Dremel models to drill perpendicular and angled holes in 15-degree increments from 90 degrees vertical to 90 degrees horizontal. Inch and metric markings on the base make for accurate drilling of workpieces. Depth markings with depth stop provide consistent depth adjustment, w… |
|
| General Tools 500 Cordless Ultra Tech Power Precision Screwdriver $16.39 … |
|
| Karcher 2.642-182.0 Pressure Washer Trigger Gun With 25-Foot Hose And Quick Connect $34.00 Includes Replacement Trigger Gun and Hose – 2.642-182.0, Quick Connect Adapter… |
|
| Xerox DocuMate 515 Flatbed Fast Simplex ADF ColorScanner with One Touch PDF and VRS Image Enhancement (XDM5155D-WU) $189.00 The Xerox DocuMate 515 Scanner from Visioneer is a compact and effective hi-speed scanner perfect for workgroups and other decentralized scanning applications. It features 600×1200 dpi optical resolution, 24-bit color, Hi-Speed USB 2.0 interface and scans everything from photos up to legal-sized documents. It also features one of the smallest footprints available of any business-oriented flatbed s… |
|
| Genuine Dell Inspiron 1520, 1521 NVIDIA GeForce UW390 8600M Video Graphics Card, Also For Vostro 1500, 1510, 1520 Laptops Notebooks, Dell Part Numbers: GM716 (heatsink), YY634 (plastic plate) $18.99 Genuine Dell NVIDIA GeForce 8600M GT Video Card for Vostro 1500, 1510, 1520 and Inspiron 1520, 1521 Laptops. Chipset Manufacturer: NVIDIA. Memory: 256MB. Model: NVIDIA GeForce 8600M. Memory Interface: 128-Bit. Chipset Manufacturer: NVIDIA, |
|
| HP OfficeJet 7410 All-in-One $499.99 TX1521 1 RED ON CLEAR FOR PT-8000 PT-PC… |
|
| Skuut Balance Bike $72.39 Built for kids ages 2-5, the Skuut is a pedal-less, chainless push bike that moves by foot power (“Flinstone” style). Its the perfect introduction to cycling because its specifically designed to complement the motor skills of young children, teaching balance and control at a much earlier age than traditional cycles with training wheels. The Skuut is a great confidence booster. From the very beginn… |
|
| Space Marine Whirlwind Tank Warhammer 40k $38.50 You get enough plastic parts to assemble one (1) Whirlwind Tank. Miniatures come unpainted and unassembled in their original packaging. Books are in brand new condition…. |
|
| 185 Piece Laq Puzzle Bits Set Mini Plane -Affordable Gift for your Little One! Item #DLAQ-703606 $13.88 This appealing intellectual toy, ”Mini Plane ” by LAQ, will help you exercise your creativity and spatial perception while offering hours of fun as you build various objects out of 185 pieces included in the kit, either using instructions provided with the kit, or coming up with your own unique LaQ artwork. The skills your child masters now will stay with them for the rest of their life, so make… |
|
| Apple iPhone 3GS LCD Display Screen + Repair Tools $10.99 This part is perfect to fix your broken LCD Screen. Just simply remove the LCD from the frame and replace it with this new one!!… |
|