CS 410 Assembly to C++ Activity Template

docx

School

Southern New Hampshire University *

*We aren’t endorsed by this school

Course

410

Subject

Computer Science

Date

Feb 20, 2024

Type

docx

Pages

2

Uploaded by colossaltitan

Report
‘’CS 410 Assembly to C++ Activity Template Step 1: Convert the assembly code into C++ code. Step 2: Explain the function of the converted C++ code. Assembly Code C++ Code Explanation of Functionality movl −8(%rbp), %eax sall $3, %eax subl $3, %eax movl %eax, −4(%rbp) int x4 = x8 * 8 – 3; *int is normally 32 bits/4bytes Moves 32 bits from 8 bytes below the base pointer to the eax register. Local variables are located some offset from the base pointer (between the base and stack pointer). The value in the eax register (x8) then has a logical shift (zeroes fill) of 3 to the right. All the bits in the variable are shifted 3 places to the left. Since it is stored in base 2 it means multiplying by 2 3 . 3 is subtracted from the value in the register The value in the register is moved (a 32 bit operation) to 4 bytes below the base pointer where the variable x4 is located movl −8(%rbp), %eax sall $2, %eax subl $1, %eax leal 7(%rax), %edx testl %eax, %eax cmovs %edx, %eax sarl $3, %eax movl %eax, −4(%rbp) x4 = (x8 * 4 – 1) / 8 Moves 32 bits from the location of the x8 variable to the eax register. Logical shift to the left by two effectively multiplies the value in the eax register by 4 Skeleton code for if the math operations result in value in the eax register being zero (assumed non-zero) Logical shift to the right by three. Similar effect to shifting left but divides by 2 3 instead of
Assembly Code C++ Code Explanation of Functionality multiply Moves 32 bit value at the register to the location 4 bytes below the base pointer (x4) movl −8(%rbp), %eax leal 7(%rax), %edx testl %eax, %eax cmovs %edx, %eax sarl $3, %eax movl −8(%rbp), %edx sall $2, %edx addl %edx, %eax movl %eax, −4(%rbp) x4 = (x8 / 8) + (x8 * 4) Moves 32 bits from 8 bytes below the base pointer (x8) to the eax register Skeleton code that moves the address of 7(%rax) to %eax IF %eax is zero (assumed non zero) The value in %eax is shifted right by 3 which divides the value by 8 Moves 32 bits from 8 bytes below the base pointer (x8) to the edx register. The value in %edx is left shifted by 2 which multiplies the value by 8 The value in the edx register is added to the value in the eax register The 32 bits of the value in the eax register is moved 4 bytes below the base pointer (x4)
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
  • Access to all documents
  • Unlimited textbook solutions
  • 24/7 expert homework help