Question: LINUX The following code can be imported intothe ebe assembler IDE. Whileit's mostly correct, it's missing something. You'llneed to fix it up and then make

LINUX

The following code can be imported intothe ebe assembler IDE. Whileit's mostly correct, it's missing something. You'llneed to fix it up and then make sure it assembles correctly

segment .text

global main

main: mov rax, [data] ; rax holds the data

xor ebx, ebx ; clear since setc will fill in bl

xor ecx, ecx ; i = 0;

xor edx, edx ; sum = 0;

while: cmp rcx, 64 ; while ( i < 64 ) {

jnl end_while ; requires testing on opposite

bt rax, 0 ; data & 1

setc bl ; move result of test to bl

add edx, ebx ; sum += data & 1;

shr rax, 1 ; data = data >> 1;

inc rcx ; i++;

jmp while ; end of the while loop

end_while:

mov [sum], rdx ; save result in memory

xor eax, eax ; return 0 from main

ret

Step by Step Solution

3.46 Rating (156 Votes )

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock

The given code appears to be a 64bit assembly code snippet There are a few issues that need to be fi... View full answer

blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!