Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Basically, the only work to do on this code is to : 1 - Print a space character between each of the four (4) bits

Basically, the only work to do on this code is to :

1- Print a space character between each of the four (4) bits

2- Display a meaningful error message and terminate if the number is out of range. Recall that the largest signed one byte number is 0111 11112= 27 - 1 = 127. The smallest possible number is 1000 00002 = -27 = -128.

.data

the_num: .asciiz "Enter a number in decimal: "

result_str: .asciiz ""

space: .asciiz " "

lessThanError: .asciiz "Number should be less than equal to 127!!! Exiting..."

greaterThanError: .asciiz "Number should be greater than equal to -128!!! Exiting..."

.align 2

.text

.globl __start

__start:

# ask and store the first number

li $v0, 4

la $a0, the_num

syscall

li $v0, 5

syscall

move $a0, $v0

jal print_bin

# New Line

li $v0, 11

li $a0, 10

syscall

j __start

print_bin:

add $t0, $zero, $a0 # put our input ($a0) into $t0

add $t1, $zero, $zero # Zero out $t1

addi $t3, $zero, 1 # load 1 as a mask

sll $t3, $t3, 7 # move the mask to appropriate position

addi $t4, $zero, 8 # loop counter

loop:

and $t1, $t0, $t3 # and the input with the mask

beq $t1, $zero, print # Branch to print if its 0

add $t1, $zero, $zero # Zero out $t1

addi $t1, $zero, 1 # Put a 1 in $t1

j print

print: li $v0, 1

move $a0, $t1

syscall

srl $t3, $t3, 1

addi $t4, $t4, -1

bne $t4, $zero, loop

jr $ra

showLessError:

li $v0, 4

la $a0, lessThanError

syscall

j exit

showGreaterError:

li $v0, 4

la $a0, greaterThanError

syscall

j exit

exit:

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Design For Mere Mortals

Authors: Michael J Hernandez

4th Edition

978-0136788041

More Books

Students also viewed these Databases questions

Question

What are the Five Phases of SDLC? Explain each briefly.

Answered: 1 week ago

Question

How can Change Control Procedures manage Project Creep?

Answered: 1 week ago