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

Consider the assembly language function below. I have added some comments to hel

ID: 2293574 • Letter: C

Question

Consider the assembly language function below. I have added some comments to help you understand the code.

(gdb) disas p4

Dump of assembler code for function p4:

   0x4005c0 <+0>:     movzbl (%rdi),%edx

   0x4005c3 <+3>:     test   %dl,%dl        # %dl is the least significant bype of %rdx

   0x4005c5 <+5>:     je     0x4005e9 <p4+41>

   0x4005c7 <+7>:     add    $0x1,%rdi

   0x4005cb <+11>:    xor    %eax,%eax

   0x4005cd <+13>:    nopl   (%rax)         # nopl ("no-op") does nothing and is for alignment

   0x4005d0 <+16>:    cmp    %sil,%dl       # %sil is the least significant byte of %rsi

   0x4005d3 <+19>:    sete   %dl           

   0x4005d6 <+22>:    add    $0x1,%rdi

   0x4005da <+26>:    movzbl %dl,%edx

   0x4005dd <+29>:    add    %edx,%eax

   0x4005df <+31>:    movzbl -0x1(%rdi),%edx

   0x4005e3 <+35>:    test   %dl,%dl

   0x4005e5 <+37>:    jne    0x4005d0 <p4+16>

   0x4005e7 <+39>:    retq

   0x4005e9 <+41>:    xor    %eax,%eax

   0x4005eb <+43>:    retq

The first parameter of p4 is an array. What type of data does the array contain? Explain your answer.

Explanation / Answer

0x4005c0 <+0>: movzbl (%rdi),%edx

0x4005c3 <+3>: test %dl,%dl # %dl is the least significant bype of %rdx

0x4005c5 <+5>: je 0x4005e9 <p4+41>

0x4005c7 <+7>: add $0x1,%rdi

0x4005cb <+11>: xor %eax,%eax

0x4005cd <+13>: nopl (%rax) # nopl ("no-op") does nothing and is for alignment

0x4005d0 <+16>: cmp %sil,%dl # %sil is the least significant byte of %rsi

0x4005d3 <+19>: sete %dl

0x4005d6 <+22>: add $0x1,%rdi

0x4005da <+26>: movzbl %dl,%edx

0x4005dd <+29>: add %edx,%eax

0x4005df <+31>: movzbl -0x1(%rdi),%edx

0x4005e3 <+35>: test %dl,%dl

0x4005e5 <+37>: jne 0x4005d0 <p4+16>

0x4005e7 <+39>: retq

0x4005e9 <+41>: xor %eax,%eax

0x4005eb <+43>: retq