For the below mentioned pseudo code (i) and pseudocode (ii), write the equivalent assembly code (mnemonics) in zero, one , two, three address instruction format for swapping the value of two variables a and b.
// pseudo Code(i)
Void Swap(int a , int b)
{
int temp;
temp=a
a=b;
b= temp;
}
// pseudo Code(ii)
/*Assume the address of variable a and b is stored in the pointer variable *x and *y. */
Void Swap(int *x , int *y)
{
int temp;
temp= *x;
*x=*y;
*y= temp;
}
(i) With taking necessary assumption, find the number of clock cycle that will be required for each case in zero, one, two, three address format for the completion of the program.
(ii) For each case find the number of times refers to memory for the completion of the program.
; 1
swap:
mov rax, rdi
mov rdx, rsi
mov rdi, rdx
mov rsi, rax
ret
; 2
swap:
mov rax, word[rdi]
mov rdx, word[rsi]
mov word[rdi], rdx
mov word[rsi], rax
ret
Comments
Leave a comment