Answer to Question #303994 in Assembler for Jack

Question #303994

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
Expert's answer
2022-02-28T16:15:41-0500
; 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

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS