Section 1: Using the MARS or SPIM simulator develop a program that will evaluate
ID: 3793049 • Letter: S
Question
Section 1: 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. Section 2: Using the MARS or SPIM simulator develop a program that will implement the following conditional statement. If n is even) 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 Hint: There is a remainder pseudoinstruction for the MIPS architecture that you can use to determine if the value is even or odd or you can look at bit o to determine if the value is even or odd.Explanation / Answer
Answer
section .text
global _start
_start:
mov bx, data
mov ds, bx
lea si, msg
call print
mov ah, 01h
int 21h
WHILE:
sar al, 01
jc ODD
lea si, msgE
call print
mov bl, 2
div al, bl
jump loop
ODD:
lea si, msgO
call print
mov bl, 3
mul al, bl
mov bl, 1
add al, bl
loop:
cmp al, 00
jg WHILE
terminate:
mov ah, 4ch
int 21h
print proc
mov dx, si
mov ah, 09h
int 21h
ret
print endp
section .data
msg db 10, 13, 'Enter a number = $'
msgE db 10, 13, 'Number is even $'
msgO db 10, 13, 'Number is odd $'
Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.