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

Using the MARS or SPIM simulator develop a program that will evaluate the follow

ID: 3793048 • Letter: U

Question

Using the MARS or SPIM simulator develop a program that will evaluate the following expression: 3 * n + n * (n- 1)- 15 where n is stored in a data location and is set to 15. Your program should use the system calls to print the result and to exit the program. Using the MARS or SPIM simulator develop a program that will implement the following conditional statement. If (n is even) {n = n/2;} else {n " 3 * n + 1;} In this case, n is to be input by the user (assume they input a non-negative value), the conditional is performed, and the resulting n is to be output. Again, use the system calls for input, output, and exiting the program.

Explanation / Answer

Answer

1.

SYS_EXIT equ 1
SYS_WRITE equ 4
STDIN equ 0
STDOUT equ 1
section .text
   global _start
_start:
   mov eax, 3
   mul eax, n
   sub eax, 15
   mov x, eax
   mov eax, n
   sub eax, 1
   add eax, x
   mov x, eax
  
   mov eax, SYS_WRTE
   mov ebx, STDOUT
   mov ecx, msg
   mov edx, len
   int 0x80

   mov eax, SYS_WRTE
   mov ebx, STDOUT
   mov ecx, x
   int 0x80

   mov eax, SYS_EXIT
   int 0x80  

section .data
n db 12
msg db 'The result is ::', 0xA, 0xD
len equ $ - msg

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