Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write an assembly language program that, when given an integer n, will calculate

ID: 3629241 • Letter: W

Question

Write an assembly language program that, when given an integer n, will calculate the value of the expression (n^2 + 1)^3 -3n^4. Your program is to get the value for n from ECX and is to leave the value of the expression in EAX.(note: The name of the integer multiplication instruction is imul)

 

Wrte an assembly language program that, when given a positive integer n, will calculate the value 2^n - n. For example, when given the value 5, your program should calculate the value 27( the difference of 32 and 5). Your program is to get the value for n from ECX and is to leave the value of 2^n - n in EAX.

Explanation / Answer

Register usage:
   EAX Sum
   ECX Original value of n

      [SECTION .text]

      global main
      
main:
      push EBP
      mov EBP, ESP

      push EBX
      push edi
      mov eax, ecx    #eax := n
      imul eax    #eax := n ^ 2
      mov ebx, 2   #eax := (n ^ 2) * 2
      imul ebx
      dec eax   #eax := ((n ^ 2) * 2) - 1
      imul ebx    #eax := (((n ^2 ) * 2) - 1) * 2
      mov edi, eax #edi := (((n ^2 ) * 2) - 1) * 2
      mov eax, ecx #eax := n
      mov ebx, ecx #ebx := n
      imul ebx # eax := n ^ 2
      imul ebx #eax := n ^ 3
      #eax := (n ^ 3) + ((((n ^ 2) * 2) - 1) * 2)

      add eax, edi
      pop edi
      pop EBX
      mov ESP, EBP
     pop EBP
    ret

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote