Even parity is where there is an even number of 1s in a string of data bits. Wri
ID: 662942 • Letter: E
Question
Even parity is where there is an even number of 1s in a string of data bits. Write a program to check the value loaded into Accumulator B and determine the state of the extra bit that would need to be added to the string in B in order to make all nine-bits have EVEN parity. Store that ninth (parity) bit as the MSB of Accumulator A and exit.
Example: If the value of B is 00111010, the number of ones in this pattern is four. This number is already even. Therefore, the extra bit is zero.
Example: If the value of B is 00101100, the number of ones in this pattern is three. This number is odd. Therefore, the extra bit is 1. The total number of ones, including the extra bit, becomes even.
Write the Assembly Language code to test the code with the two values, 00111010 and 00101100.
Explanation / Answer
pushq %rbp .cfi_def_cfa_offset 16 .cfi_offset 6, -16 movq %rsp, %rbp .cfi_def_cfa_register 6 subq $32, %rsp movq %fs:40, %rax movq %rax, -8(%rbp) xorl %eax, %eax movb $48, -16(%rbp) movb $48, -15(%rbp) movb $49, -14(%rbp) movb $49, -13(%rbp) movb $49, -12(%rbp) movb $48, -11(%rbp) movb $49, -10(%rbp) movb $48, -9(%rbp) movl $0, -24(%rbp) .LBB2: movl $0, -20(%rbp) jmp .L2 .L4: movl -20(%rbp), %eax cltq movzbl -16(%rbp,%rax), %eax F0 cmpb $49, %al jne .L3 addl $1, -24(%rbp) .L3: addl $1, -20(%rbp) .L2: cmpl $7, -20(%rbp) jle .L4 .LBE2: movl -24(%rbp), %eax andl $1, %eax testl %eax, %eax jne .L5 movb $48, -25(%rbp) jmp .L6 .L5: movb $49, -25(%rbp) .L6: movl $0, %eax movq -8(%rbp), %rdx xorq %fs:40, %rdx je .L8 call __stack_chk_fail .L8: leave .cfi_def_cfa 7, 8 ret .cfi_endproc
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.