WinAsm Studio, The Assembly IDE - Free Downloads, Source Code
Sponsors
Articles
Programming Quick Start
32-bit Assembler is Easy
Porting Iczelion tutorials
What is FASM
What is FASM G
Hard Drive Recovery
Wiring your own LAN
Personal menu
Welcome Guest
User:
Pass:
Register!
Resend Validation Email
 
Forum
Pages (2) [1] 2   ( Go to first unread post )

How to count the number of set bits in a 32-bit...

rosikolo
Quote Post


New Member
*

Group: Members
Posts: 3
Member No.: 69769
Joined: 20-September 16


Sponsored Links
Hello,

I'm a total newbie and I'm triyng to write the code to How to count the number of set bits in a 32-bit integer.

I Wrote this but I have a lot of error:

.586
.model flat,stdcall
.stack 4096
; Windows libraries
includelib \masm32\lib\kernel32.lib
includelib \masm32\lib\user32.lib


.DATA
data: .LONG 0x0F0F0101
count: .BYTE 0x00

.TEXT
_main: NOP
MOVB $0x00, %CL
MOVL data, %EAX
comp: CMPL $0x00, %EAX
JE end
SHRL %EAX
ADCB $0x0, %CL
JMP comp
end: MOVB %CL, count
RET


How can I solve this?

Thank you very much!!!
PMEmail Poster
Top
shoorick
Quote Post


Extremely Active Member
******

Group: Admins
Posts: 2332
Member No.: 160
Joined: 22-June 04


roll any 32-bit register 32 times and count each time you get carry flag set.

also, you have inserted code in at&t syntax format: masm will not able to assemble it. look at masm examples how must it look
PMEmail PosterUsers Website
Top
rosikolo
Quote Post


New Member
*

Group: Members
Posts: 3
Member No.: 69769
Joined: 20-September 16


Thank you for your answer!

I have found an editor for at6T syntax form but now I have the problem with the "system pause" command or an equivalent for Assembly.

PMEmail Poster
Top
shoorick
Quote Post


Extremely Active Member
******

Group: Admins
Posts: 2332
Member No.: 160
Joined: 22-June 04


the reason is not in editor, the reason is in assembler (tool) which will use to assemble your source. at&t is quiet specific, i can not help you with it. in regular (intel) syntax it should look like this:

CODE
   mov eax,your_constant
   mov cl,32
   mov ch,0
m1:
   rcl eax,1
   adc ch,0
   dec cl
   jnz m1
   ...  ; now ch has count of ones in eax


PMEmail PosterUsers Website
Top
rosikolo
Quote Post


New Member
*

Group: Members
Posts: 3
Member No.: 69769
Joined: 20-September 16


Ok.
Anyway my problem now is different.
I have started the build and it was built successfully. When I will create the .exe file and I will launch if from DOS, nothing happens.

So for this reasons I would like to know if there is a code to stop the istruction and to insert an INPUT from Keyboard.

Thank You!
PMEmail Poster
Top
1 User(s) are reading this topic (1 Guests and 0 Anonymous Users)
0 Members:

Topic Options Pages (2) [1] 2  Reply to this topicStart new topicStart Poll

 

Sponsors
Computer Science

Internet
C/C++
Hardware & PC maintenance

HiEditor

General Discussions
Suggestions/Bug Reports
WinAsm Studio

General Discussions
Suggestions/Bug Reports
WinAsm Studio FAQ
Multilingual User Interface
Add-Ins
Assembly Programming

Main
Newbies
Projects
Custom Controls
Snippets
Announcements & Rules

Announcements

General

Online Degrees - Distance Learning
The Heap
Russian
Google