I want a MIPS code, which can run on MARS4_5. This program will print \"Enter nu
ID: 3752597 • Letter: I
Question
I want a MIPS code, which can run on MARS4_5.
This program will print "Enter numbers " to ask user to type a decimal number and print its 8-bits binary number, like 15 to 00001111.
Also, the input decimal number should in a range between -128 and 127. If the input is out of range, system should print "out of range"
Here is the output.
Enter Number: -15 Binary Number: 0001 program is finished running (dropped off bottom Enter Number: 12 Binary Number: 0000 1100 program is finished running (dropped off bottom Enter Number: 230 Number out of range! program is finished running (dropped off bottom Enter Number: -150 Number out of range! program is finished running (dropped off bottom Enter Number: 85 Binary Number: 0101 0101 program is finished running (dropped off bottom Enter Number: -85 iary NroD 1010 1011 program is finished running (dropped off bottom)Explanation / Answer
.data
ask_str1: .asciiz "Enter a number between range of -127 to +127: "
binary_str: .asciiz "Binary equivalent :"
out_of_range_str: .asciiz "Out of range :"
.align 2
.text
.globl __main
__main:
# ask and store the first number
li $v0, 4
la $a0, ask_str1
syscall
li $v0, 5
syscall
move $s0, $v0
li $t0,127
bgt $s0,$t0,OUT_OF_RANGE
li $t0,-128
blt $s0,$t0,OUT_OF_RANGE
li $v0, 4
la $a0, binary_str
syscall
li $t2,0x80
LOOP:
beq $t2,$0,EXIT_PROG
li $t1,0
and $t1,$s0,$t2
srl $t2,$t2,1
beq $t1,$0,ZERO_B
ONE_B:
li $v0,1
li $a0,1
syscall
j LOOP
ZERO_B:
li $v0,1
li $a0,0
syscall
j LOOP
EXIT_PROG:
li $v0, 10
syscall
OUT_OF_RANGE:
li $v0, 4
la $a0, out_of_range_str
syscall
li $v0, 10
syscall
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.