Computers and Technology

Hello,

i have to build a program using assembly with mars system.

the program is supposed to return a hailstone sequence

a)- get user input (integer) - n

b) check if even or odd

- if the input is even, the next number should n/2

- if the user's input (n*3)+1

c) reproduce the operation on the next number until the number is equal to 1

d) display the sequence

e) count and display the number of iterartion

i have the user input done, and then, i tried to do a bitwise operation using and to see if the number is even or not but the program doesn't work after the user's input, as i have an output equal to zero

can you me ?

here is my code so far

.data

prompt: .asciiz "enter an integer: "
message1: .asciiz "you entered an even number"
message2: .asciiz "you entered an odd number"
message3: .asciiz "and the next numbers should be: "
gototheline: .asciiz "\n"
message4: .asciiz "you just entered the number: "

.text
main:

#print the prompt
li $v0,4
la $a0,prompt
syscall

#get the user's input
li $v0,5
syscall

#store the input'svalue
move $t3, $v0

#display the user's input message
li $v0,4
la $a0,message4
syscall

#go to the line
li $v0,4
la $a0,gototheline
syscall

#print value entered by user
li $v0,1
move $a0, $t3
syscall

#go to the line
li $v0,4
la $a0,gototheline
syscall

#bitwise operation on the input
and $a0,$0,1

#call odd function if number is odd
beq $a0,1,ifodd

#print next number message
li $v0, 4
la,$a0,message3
syscall

#go to the line
li $v0,4
la $a0,gototheline
syscall

#print result
li $v0,1
addi $a0,$v1,0
syscall

li $v0,10
syscall

ifeven:
#print message if even
la $a1,message1
syscall

#call the function operation even to do math on the number entered by user
jal operationeven

ifodd:
#print message if odd
la $a2,message2
syscall

#call method to do math on the number entered by user
jal operationodd

operationeven:
#if even n/2
div $v1,$t3,2 # return value on $v1

jr $ra #go back to the main

operationodd:

#multiply by 3
mul $t1,$t3,3

#add 1 to the result of the multiplication
add $v1, $t1,1 #return value on $v1

jr $ra #go back to the main

answer
Answers: 1

Other questions on the subject: Computers and Technology

image
Computers and Technology, 22.06.2019 16:30, sayedaly2096
What type of file does a cookie place on web site visitors' computers so that web site managers can customize their sites to their visitors' preferences?
Answers: 1
image
Computers and Technology, 22.06.2019 17:00, shimmerandshine1
Aisha has finished working on a word processing document that contains 15 pages. she has added some special elements in the first three pages, page 9 and 10, and page 15 from the document. she wants to print only these pages to see how they look. which option is the correct way to represent (in the print dialog box) the pages that aisha wants to print
Answers: 3
image
Computers and Technology, 22.06.2019 19:30, ibrahimuskalel
Avariable definition defines the name of a variable that will be used in a program, as well as
Answers: 3
image
Computers and Technology, 22.06.2019 23:50, Emptypockets451
You need to design a circuit that implements the functions in the following table: s0 s1 function0 0 a + 10 1 a – b1 0 a + b1 1 a – 1s0 and s1 are 1-bit control inputs to select the function of the circuit. inputs a and b are 4-bitnumbers in 2s complement form. the output is also a 4-bit number in 2s complement form. you are allowed to use only one ttl 7483 4-bit adder to implement all the functions. but anynumber of other components (except the adder) can be used. hint: design a combinational logic circuit to modify the input b and the β€œcarry input” of theadder depending on the control inputs s0 and s1.important: lab grade will depend on the working of the circuit & will be checked of by your labinstructor.1. is the output valid for the following input combinations: a. s0 = 0, s1 = 0, a = 7, b = 3? b. s0 = 0, s1 = 1, a = 7, b = 3? c. s0 = 1, s1 = 0, a = -4, b = -5? d. s0 = 1, s1 = 1, a = -8, b = 6? 2. what is the range of inputs (for both a and b) that will produce the valid output for all the functions?
Answers: 3
Do you know the correct answer?
Hello,

i have to build a program using assembly with mars system.

the progra...

Questions in other subjects:

Konu
Mathematics, 01.02.2021 06:30