Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write an assembly program to count the number of bits that are set to 1 in a DWO

ID: 3772768 • Letter: W

Question

Write an assembly program to count the number of bits that are set to 1 in a DWORD initialized as follows:
countBits PROTO, param1:DWORD, param2:DWORD

.data X DWORD 17089 count DWORD 0
countBits procedure should be invoked from main procedure, should print the count to the console and the parity of X Write an assembly program to count the number of bits that are set to 1 in a DWORD initialized as follows:
countBits PROTO, param1:DWORD, param2:DWORD

.data X DWORD 17089 count DWORD 0
countBits procedure should be invoked from main procedure, should print the count to the console and the parity of X
countBits PROTO, param1:DWORD, param2:DWORD

.data X DWORD 17089 count DWORD 0
countBits procedure should be invoked from main procedure, should print the count to the console and the parity of X

Explanation / Answer

ANSWER:

countBits PROTO, param1:DWORD,

param2:DWORD

.data

          X DWORD 17089

          count DWORD 0

.code

main PROC

          invoke countBits,x,count         

          invoke ExitProcess,0

main endp

;PROCEDURE TO CALCULATE NUBER OF 1 IN BINARY

countBits PROC    

          mov ebx,2

;convert UMBER TO BINARY AND COUNT 1 IN BINARY

PROCESS:

          cmp param1,0              

          je DisplayValue                        

          mov ax, WORD PTR param1

          mov dx, WORD PTR param1 + 2

          div bx

          movzx edx, dx

          cmp edx,0

          je incrementCount

          movzx eax, ax

          mov param1, eax

          jmp PROCEss

incrementCount:    inc param2

          jmp PROCEss

;DISPLAY THE COUNT AND PARITY OF X

displayValue: mov eax,param2

          call WriteDec

          mov eax,param2

          div bx

          cmp edx,0

          je true

          mov eax,1

          call WriteDec

true :        mov eax,0

          call WriteDec

          ret

countBits endp

END main

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote