Consider the following assembly code: .LC0: .string \"ans %d\ \" main: .LFB0: pu
ID: 3748676 • Letter: C
Question
Consider the following assembly code:
.LC0:
.string "ans %d "
main:
.LFB0:
pushq %rbp
movq %rsp, %rbp
subq $16, %rsp
movl $0, -4(%rbp)
movabsq $58217882423726, %rax
movq %rax, -16(%rbp)
.L2:
movq -16(%rbp), %rax
andl $1, %eax
movl %eax, %edx
movl -4(%rbp), %eax
xorl %edx, %eax
movl %eax, -4(%rbp)
shrq -16(%rbp)
cmpq $0, -16(%rbp)
jne .L2
movl -4(%rbp), %eax
movl %eax, %esi
movl $.LC0, %edi
movl $0, %eax
call printf
movl $0, %eax
leave
ret
This code came from skeleton C file below after optimizing with O0. This means gcc -O0 -S command was used to convert C File into assembly file. Complete the C code given below using the provided assembly code. Step 1 might be to ignore the skeleton file and create a equivalent C code from the assembly code, and then rewrite the code to fit the skeleton file.
int main() {
int output = ________________;
unsigned long value = ________________;
do {
output = ________________;
value = ________________; }
while (value ________________ 0x________________);
printf("ans %d ", output);
return 0;
}
Explanation / Answer
int main(){
int output = 0;
unsigned long value = 58217882423726;
do{
output = value & 1;
value = value >> output;
}while(value!=0x0);
printf("ans %d ",output);
return 0;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.