------------------------------------------------------ C programming coding prob
ID: 3717650 • Letter: #
Question
------------------------------------------------------
C programming coding problem. Assembly related.
It seems long but NOT LONG. most parts are introductive steps/examples.
Please read carefully and ONLY FULL ANSWERS (YOUR CODE SHOULD ANSWER Q 1, 2, 3, &4) will get positive rate.
Thank you.
This there is a swap function, which swaps the value of two variables (Content of one memory location to others, and vice versa). The swap function is below is based on the basic understanding of the assembly. Let us assume that, void swap(int "xp, int *yp) int t0 xp int t1- *yp yp to; .For this above and show the exchange of the values ., you need to write the main function that would call the swap function 2. Write the equivalent assembly code or generate assembly from your C codee .. (using gcc) 3. Make comment on each statement of your assembly code 4.Give the final memory images after the operation, answer the following questions 1) What's the memory address of your swap function? 2) Which register holds the initial value Xp? Which register holds the initial value *yp? 3) What are the memory addresses of the two locations pointed by xp and yp? ample putput with comments could be //assuming memory as Memoryll movq %rdi,-24(%rbp) //move first parameter %rdi in Memory[%rbp-241 movq %rsi,-32(%rbp) //move second parameter %rsi in Memoryl%rbp-32] movi (%rax), (%eax) // move Memory[%rax) to Memory[%eax) %eax-8(%rbp) // move %eax to Memory[%rbp-8] moviExplanation / Answer
1.
int main()
{
int x, y;
printf("Enter Value : x ");
scanf("%d", &x);
printf(" Enter Value : y ");
scanf("%d", &y);
swap(&x, &y);
printf("After Swapping: x = %d, y = %d", x, y);
return 0;
}
2 & 3 :
DATA SEGMENT //initialize variables
NUM1 DB 9H // Declaring variable
NUM2 DB 7H // Declaring variable
ENDS
CODE SEGMENT //Text segment
ASSUME DS:DATA CS:CODE
START:
MOV AX,DATA // moving data AX to Data
MOV DS,AX // moving data DS to AX
MOV AL,NUM1 // moving data AL to NUM1
MOV BL,NUM2 // moving data BL to NUM2
XCHG AL,NUM2 // Exchanging data AL to NUM2
XCHG BL,NUM1 // Exchanging BL & NUM1
MOV AH,4CH // MOVING data AH to 4CH
INT 21H
ENDS
END START
4.
Memory address :
0x7fff7db17c80
0x7fff7db17c84
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.