| | |
counting digits
![]() |
create a loop that repeatedly divides the value by 10 until its value becomes 0. increment a counter on each loop iteration. see the description for the idiv instruction if you do not know what it does.
Don't PM me with questions -- you might get a nasty PM in response. If you have a question then post it in one of the forums.
Don't PM me with questions -- you might get a nasty PM in response. If you have a question then post it in one of the forums.
•
•
Join Date: Jul 2006
Posts: 24
Reputation:
Solved Threads: 0
From what I understand, you want to count the number of digits in binary form, ex. 10001 (decimal 17) has 5 digits. You simply test the most significant towards least significant bits untill you reach a bit that is set on or 1. Total bits minus that count is the number of digits, example would be a 16bit register and a 0000000000010001 binary will give you 11 as your count (as theres 11 zeros). So 16-11 = 5. If you want the number of digits in base 10 then refer to the previous posts.
•
•
Join Date: Jul 2006
Posts: 16
Reputation:
Solved Threads: 0
•
•
•
•
From what I understand, you want to count the number of digits in binary form, ex. 10001 (decimal 17) has 5 digits. You simply test the most significant towards least significant bits untill you reach a bit that is set on or 1. Total bits minus that count is the number of digits, example would be a 16bit register and a 0000000000010001 binary will give you 11 as your count (as theres 11 zeros). So 16-11 = 5. If you want the number of digits in base 10 then refer to the previous posts.
In a general, is there list of all assembly functions available somewhere on web, i haven't found one ?
•
•
Join Date: Jul 2006
Posts: 24
Reputation:
Solved Threads: 0
•
•
•
•
How do i test the most/last significant bits of register?
In a general, is there list of all assembly functions available somewhere on web, i haven't found one ?
Example:
Assembly Syntax (Toggle Plain Text)
mov ax, myBinaryValue mov dx, 0000000000000001b ; first ROR will make this most significant bit mov cx, 16 ; 16 bits LOOP: ror dx, 1 ; rotate bits to the right by 1 test dx, ax ; this test will set ZF=0 (not zero) when the a bit is found on jnz BITFOUND dec cx ; decrease bit count jnz LOOP ; test again ;;;; if program enters here myBinaryValue is zero ;;;; BITFOUND: ;;;; if program enters here a bit set on was found ;;;; ;;;; number of digits should be in CX register ;;;
Note: this program was never tested.
Last edited by Ryu; Jan 7th, 2007 at 12:49 pm.
•
•
Join Date: Jan 2007
Posts: 49
Reputation:
Solved Threads: 0
Assembly Syntax (Toggle Plain Text)
; ; Assuming 386 32 bit assembler code ; mov ecx,val xor eax,eax ; Counts the number of '1' bits again: shl ecx,1 adc eax,0 or ecx,ecx jnz again done: ; ; EAX has the count of bits in "val" ;
![]() |
Similar Threads
Other Threads in the Assembly Forum
- Previous Thread: Re: Word Association Game
- Next Thread: how to show PC clock in the screen using TASM
| Thread Tools | Search this Thread |







