Double word and program issue

  Kiến thức lập trình

Write a program to calculate the parity of a 32-bit memory operand. The formula for calculating the parity of a binary number is to XOR all the bits together. Refer to section 6.1.5

Test with two double words and display on the screen if odd or even parity. Take a screenshot of the output.

.386
.model flat, stdcall
.stack 4096

ExitProcess PROTO :DWORD

.data
memory_operand DD 0xDEADBEEF ; Example 32-bit memory operand

.code
main PROC
; Load the memory operand into ESI register
mov esi, OFFSET memory_operand
; Initialize ebx register for parity calculation
mov ebx, 0
; Initialize ecx register to count the number of bits to check
mov ecx, 32
; Load the memory operand into eax register
mov eax, DWORD PTR [esi]

calculate_parity_loop:
xor ebx, eax ; XOR the least significant bit with the parity result
shr eax, 1 ; Shift the eax register to the right by 1 bit
loop calculate_parity_loop ; Decrement ecx and loop if not zero

test ebx, 1                ; Test the least significant bit of the result
jnz odd_parity             ; If it's 1, jump to odd_parity
; If it's 0, even parity
mov eax, 0
jmp end_program

odd_parity:
mov eax, 1 ; Set EAX register to 1 for odd parity

end_program:
; Exit the program
INVOKE ExitProcess, 0 ; Exit the program

main ENDP

END main

I tried everything bruh! nothing works! Its due by 11:59 pm today and Idk what to fix! I keep getting missing operator in expression on line 8

New contributor

Ethan Russell is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.

LEAVE A COMMENT