Question

In: Computer Science

analyze the assembly code and explain what each line is doing 000000000000063a <main>: 63a: 55 push...

analyze the assembly code and explain what each line is doing

000000000000063a <main>:
 63a:   55                      push   ebp
 63b:   48 89 e5                mov    ebp,esp
 63e:   48 83 ec 10             sub    esp,0x10
 642:   c7 45 fc 00 00 00 00    mov    DWORD PTR [ebp-0x4],0x0
 649:   eb 16                   jmp    661 <main+0x27>
 64b:   83 7d fc 09             cmp    DWORD PTR [ebp-0x4],0x9
 64f:   75 0c                   jne    65d <main+0x23>
 651:   48 8d 3d 9c 00 00 00    lea    edi,[eip+0x9c]        # 6f4 <_IO_stdin_used+0x4>
 658:   e8 b3 fe ff ff          call   510 <printf@plt>
 65d:   83 45 fc 01             add    DWORD PTR [ebp-0x4],0x1
 661:   83 7d fc 09             cmp    DWORD PTR [ebp-0x4],0x9
 665:   7e e4                   jle    64b <main+0x11>
 667:   b8 00 00 00 00          mov    eax,0x0
 66c:   c9                      leave 
 66d:   c3                      ret    

Solutions

Expert Solution

Assembly language provides two instructions for stack operations: PUSH and POP.

63a:Push the content in the register ebp.EBP stands for extended base pointer,It keeps track of the current stackframe.

63b:Move the content of the register ebp to register esp.

63e:Subtact 10 from the esp and store it in the ebp.The function will take 10 byte.

642:Now assign value 0 to the address pointed by 4 bytes less than ebp.

649:Jmp switches the CPU to execute a different piece of code! Here, it jumps to 661.

64b:Compare the content of the register and test if function return is 0.

64f:jne is a conditional jump that follows a test.It jumps to the specified location if the zero flag is cleared(0).jne is commonly used to explicitly test for something not being equal to zero whereas jne is commonly found after a cmp instruction.Jmp to 65d.

651:The lea is the load effective address instruction which is a way of obtaining the address which arises from any of the Intel processor's memory addressing modes.It is not a specific arithmetic instruction:it is a way of intercepting the effective address arising from any of the processsor's memory addressing modes.

658:print@plt is actually a small stub which eventually calls the real printf function,modifying things on the way to make subsequent calls faster.So the plt is a smaller process-specific area at a reliably -calculated-at-runtime address that is not shared between processes,so any given process is free to change it however it wants to,without adverse effects.Here the call operand transfers the program sequence to the memory address given in the operand(550).

65d:The dword ptr part is called a size directive.Basically,it means " the size of the target operand is 32 bits" so it will ADD the 32-bit value at the address computed by taking the contents of the ebp register and subtracting four with 0.

661:It will compare the 32 bit value at the address computed by taking the contents of the ebp register and subtracting four with 0.It will test that the function return is 0 or not.

665:The jle instruction is a conditional jump that follows a test.It performs a signed comparison jump after a cmp if the destination operand is less than or equal to the source operand.Depends on the statisfaction of the condition here it will jump to 64b.

667:Move the content of the register eax .

66c:The leave instruction reverse the action of an enter instruction.Leave copies the frame pouinter to the stack point and releases the stack space formerly used by a procedure for its local variables.leave pops the old frame pointer into ebp,thus restoring the caller's frame.

66d:The ret instruction transfers control to return address located on the stack.


Related Solutions

4. Explain what is happening on each line of the following AVR assembly code. If you...
4. Explain what is happening on each line of the following AVR assembly code. If you were to execute this code what would be the final decimal values in R20, R21 and SREG registers? BCLR 0 BCLR 1 BCLR 2 BCLR 3 BCLR 4 BCLR 5 BCLR 6 BCLR 7 LDI ​R19, 0x02 LDI​R20, 0x74 LDI​R21, 0x04 LDI​R22, 0x22 ADD​R20, R22 SUB​R22, R21 ADD​R20, R21 MOV​R20, R21 JMP​DONE ADD​R21, R20 SUB​R21, R22 DONE:​SUB​R20, R21 -embedded system-
Can you please explain in detail what each line of code stands for in the Main...
Can you please explain in detail what each line of code stands for in the Main method import java.util.Scanner; public class CashRegister { private static Scanner scanner = new Scanner(System.in); private static int dollarBills[] = {1, 2, 5, 10, 20, 50, 100}; private static int cents[] = {25, 10, 5, 1}; public static void main(String[] args) { double totalAmount = 0; int count = 0; for (int i = 0; i < dollarBills.length; i++) { count = getBillCount("How many $"...
Can someone please write clear and concise comments explaining what each line of code is doing...
Can someone please write clear and concise comments explaining what each line of code is doing for this program in C. I just need help tracing the program and understand what its doing. Thanks #include <stdio.h> #include<stdlib.h> #include<unistd.h> #include<sys/wait.h> int join(char *com1[], char *com2[]) {    int p[2], status;    switch (fork()) {        case -1:            perror("1st fork call in join");            exit(3);        case 0:            break;        default:...
explain the code for a beginner in c what each line do Question 3. In the...
explain the code for a beginner in c what each line do Question 3. In the following code, answer these questions: Analyze the code and how it works? How can we know if this code has been overwritten? Justify how? #include <stdlib.h> #include <unistd.h> #include <stdio.h> int main(int argc, char **argv) { int changed = 0; char buff[8]; while (changed == 0){ gets(buff); if (changed !=0){ break;} else{     printf("Enter again: ");     continue; } }      printf("the 'changed' variable...
convert following C++ code into MIPS assembly: int main() {                                 &
convert following C++ code into MIPS assembly: int main() {                                         int x[10], occur, count = 0;                                                              cout << "Type in array numbers:" << endl; for (int i=0; i<10; i++) // reading in integers                               { cin >> x[i];        } cout << "Type in occurrence value:" << endl;                                 cin >> occur;                                                 // Finding and printing out occurrence indexes in the array                                  cout << "Occurrences indices are:" <<...
HCS12 Assembly code please. Translate the following code into assembly. Allocate each variable on the stack....
HCS12 Assembly code please. Translate the following code into assembly. Allocate each variable on the stack. Simulate your program and screenshot the final value of the variables in memory. { char A,B,C; int F; A = 2; B = 6; C = - 10; F = (A + B)*C; C = F +10 }
3. Translate the following C code to MIPS assembly code (in two separate files). int main()...
3. Translate the following C code to MIPS assembly code (in two separate files). int main() { printf(“before subroutine!\n”); Subfunc(); printf(“after subroutine!\n!”); } void Subfunc() {printf(“I am subroutine!\n”);} Submission file: Lab4_3a.asm for the main routine and Lab4_3b.asm for the sub-routine.
3. Translate the following C code to MIPS assembly code (in two separate files). int main()...
3. Translate the following C code to MIPS assembly code (in two separate files). int main() { printf(“before subroutine!\n”); Subfunc(); printf(“after subroutine!\n!”); } void Subfunc() {printf(“I am subroutine!\n”);} 4. Translate the following C code to MIPS assembly (in two separate files). Run the program step by step and observe the order of instructions being executed and the value of $sp. int main() { int x=2; z=Subfunc(x); printf(“Value of z is: %d”, z); } int Subfunc(int x) { return x+1;}
Translate the following C code to MIPS assembly. The main function and subfunction are translated to...
Translate the following C code to MIPS assembly. The main function and subfunction are translated to two separate .asm files. Finish the assembly code segment for the above requirement. int main() { int x=2; int y=1; int z=0; z=Subfunc(x,y); printf(“Value of z is: %d”, z); } int Subfunc(int x, int y) { int t1=0; t1=x+y+100; return t1;} File 1: .data str: .asciiz "The value of z:" .text #.globl main main: addi $s0, $0,2 #x addi $s1, $0,1 #y addi $s2,...
a. What will be the output of LINE A in code “a” and output of code...
a. What will be the output of LINE A in code “a” and output of code “b”? Also write reasons for the outputs. a. #include <sys/types.h> #include <stdio.h> #include <unistd.h> int value = 3; int main() { pid_t pid; pid = fork(); if (pid = = 0) {/* child process */} value += 233; return 0; } else if (pid > 0) {/* parent process */} wait(NULL); printf(“PARENT: value = %d”, value); /* LINE A */ return 0; } }...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT