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

Write a MIPS assembly language program that takes a decimal integer from a user

ID: 3742061 • Letter: W

Question

Write a MIPS assembly language program that takes a decimal integer from a user and outputs a 8-bit binary number.

This program requirements:

- Read a decimal integer from a user

- 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.

- Display exactly one byte in binary based on the decimal number input from the user

- Print a space character between each of the four bits

- Display meaningful messages from the user whenever appropriate. For example “Enter Number: ”.

- Do not use syscalls #35 or #36 to complete this code!

Explanation / Answer

As per given data concept is

*read value A from user as input and it stored in register*

*display binary format of register value*

.data

User Input: .asciiz     "Enter an integer value: "

Binary Input:    .asciiz "Output in binary format: "

*for new line*

nl:         .asciiz     " "

main:

*ask Enter an integer value by user*

    li      $v0,4

    la      $a0,userInput

    syscall

    *here read user entered input*

    li      $v0,5

    syscall

    move    $s0,$v0

    *output in binary format*

    la      $a0,binaryInput

    li      $a1,32

    jal     prtbin

*here exit from the program*

    li      $v0,10

    syscall

* prtbin – for print the output in binary format*

*arguments*

*a1 it will tells us how many digits in binary format*

prtbin:

    li      $a2,1                   *bit width of number base digit *

    j       prtany                *arguments:*

*a0 it will tell us output format*

*a1 it tell us number of bits in output format*

*a2   it tell us bit width of number base digit*

*s0    number to print*

*registers:*

*t0   it specify current digit value*

*t5   it specify current remaining number value*

*t6   it specify output pointer*

*t7   mask for digit*

prtany:

    li      $t7,1

    sllv    $t7,$t7,$a2            *get mask+1*

    subu    $t7,$t7,1               *here get mask for digit*

    la      $t6,obufe               *it will point one past point of buffer*

    subu    $t6,$t6,1               *it will point last character of buffer*

    sb      $zero,0($t6)            *store string EOS*

    move    $t5,$s0                 *get number*

*output string*

    li      $v0,4

    syscall

*output the number*

    move    $a0,$t6                 

    syscall

*output in new line*

    la      $a0,nl

    syscall

    jr      $ra               *return value*

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