Question

In: Computer Science

Write a MIPS Assembly Language program which runs interactively to convert between decimal, binary, and hexadecimal....

Write a MIPS Assembly Language program which runs interactively to convert between decimal, binary, and hexadecimal.

1. Request input data type.

2. Request input data.

3. Request output data type.

4. Output the data. Use any algorithm

Solutions

Expert Solution

Here is the solution. Please do upvote thank you.

as per the question requirement it takes input as follows:

First input : The radix base of input data .
Second input : The data (in string format)
Third input : The radix base of output data.
It gives a single output : The desired coverted number.
Generally it is not a human task to code in Assembly Language you can always find a suitable compiler which uses MIPS assembly Language and command it to just create a object file containing the assembly language code.
The compiler used for this code is : MIPS GCC 5.4.
Assembly Language Code :

ConvertTo10(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, int):
addiu $sp,$sp,-56
sw $31,52($sp)
sw $fp,48($sp)
move $fp,$sp
sw $4,56($fp)
sw $5,60($fp)
lw $2,60($fp)
nop
slt $2,$2,2
bne $2,$0,$L2
nop
lw $2,60($fp)
nop
slt $2,$2,37
bne $2,$0,$L3
nop
$L2:
move $2,$0
b $L4
nop
$L3:
move $5,$0
lw $4,56($fp)
jal std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::operator[](unsigned int) const
nop
lb $2,0($2)
nop
xori $2,$2,0x2d
sltu $2,$2,1
sb $2,37($fp)
lw $4,56($fp)
jal std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::length() const
nop
addiu $2,$2,-1
sw $2,40($fp)
lbu $2,37($fp)
nop
beq $2,$0,$L5
nop
li $2,1 # 0x1
b $L6
nop
$L5:
move $2,$0
$L6:
sw $2,44($fp)
sw $0,24($fp)
li $2,1 # 0x1
sw $2,28($fp)
lw $2,40($fp)
nop
sw $2,32($fp)
$L12:
lw $3,32($fp)
lw $2,44($fp)
nop
slt $2,$3,$2
bne $2,$0,$L7
nop
lw $2,32($fp)
nop
move $5,$2
lw $4,56($fp)
jal std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::operator[](unsigned int) const
nop
lbu $2,0($2)
nop
sb $2,36($fp)
lb $2,36($fp)
nop
slt $2,$2,97
bne $2,$0,$L8
nop
lb $2,36($fp)
nop
slt $2,$2,123
beq $2,$0,$L8
nop
lbu $2,36($fp)
nop
addiu $2,$2,-32
andi $2,$2,0x00ff
sb $2,36($fp)
$L8:
lb $2,36($fp)
nop
slt $2,$2,48
bne $2,$0,$L9
nop
lb $2,36($fp)
nop
slt $2,$2,58
beq $2,$0,$L9
nop
lbu $2,36($fp)
nop
addiu $2,$2,-48
andi $2,$2,0x00ff
sb $2,36($fp)
b $L10
nop
$L9:
lbu $2,36($fp)
nop
addiu $2,$2,-55
andi $2,$2,0x00ff
sb $2,36($fp)
$L10:
lb $3,36($fp)
lw $2,60($fp)
nop
slt $2,$3,$2
bne $2,$0,$L11
nop
move $2,$0
b $L4
nop
$L11:
lb $3,36($fp)
lw $2,28($fp)
nop
mult $3,$2
lw $2,24($fp)
mflo $3
addu $2,$2,$3
sw $2,24($fp)
lw $3,28($fp)
lw $2,60($fp)
nop
mult $3,$2
mflo $2
sw $2,28($fp)
lw $2,32($fp)
nop
addiu $2,$2,-1
sw $2,32($fp)
b $L12
nop
$L7:
lbu $2,37($fp)
nop
beq $2,$0,$L13
nop
lw $2,24($fp)
nop
subu $2,$0,$2
sw $2,24($fp)
$L13:
lw $2,24($fp)
$L4:
move $sp,$fp
lw $31,52($sp)
lw $fp,48($sp)
addiu $sp,$sp,56
j $31
nop
$LC0:
.ascii "0\000"
ConvertFrom10[abi:cxx11](long, int):
addiu $sp,$sp,-88
sw $31,84($sp)
sw $fp,80($sp)
sw $16,76($sp)
move $fp,$sp
sw $4,88($fp)
sw $5,92($fp)
sw $6,96($fp)
lw $2,96($fp)
nop
slt $2,$2,2
bne $2,$0,$L15
nop
lw $2,96($fp)
nop
slt $2,$2,37
bne $2,$0,$L16
nop
$L15:
addiu $2,$fp,44
move $4,$2
jal std::allocator<char>::allocator() [complete object constructor]
nop
addiu $2,$fp,44
move $6,$2
lui $2,%hi($LC0)
addiu $5,$2,%lo($LC0)
lw $4,88($fp)
jal std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::basic_string(char const*, std::allocator<char> const&)
nop
addiu $2,$fp,44
move $4,$2
jal std::allocator<char>::~allocator() [complete object destructor]
nop
b $L14
nop
$L16:
lw $2,92($fp)
nop
srl $2,$2,31
sb $2,32($fp)
lbu $2,32($fp)
nop
beq $2,$0,$L18
nop
lw $2,92($fp)
nop
subu $2,$0,$2
sw $2,92($fp)
$L18:
addiu $2,$fp,48
move $4,$2
jal std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::basic_string() [complete object constructor]
nop
$L22:
lw $3,92($fp)
lw $2,96($fp)
nop
bne $2,$0,1f
div $0,$3,$2
break 7
mfhi $2
sb $2,24($fp)
lb $2,24($fp)
nop
slt $2,$2,10
beq $2,$0,$L19
nop
lbu $2,24($fp)
nop
addiu $2,$2,48
andi $2,$2,0x00ff
sb $2,24($fp)
b $L20
nop
$L19:
lbu $2,24($fp)
nop
addiu $2,$2,55
andi $2,$2,0x00ff
sb $2,24($fp)
$L20:
lb $3,24($fp)
addiu $2,$fp,48
move $5,$3
move $4,$2
jal std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::operator+=(char)
nop
lw $3,92($fp)
lw $2,96($fp)
nop
bne $2,$0,1f
div $0,$3,$2
break 7
mfhi $2
mflo $2
sw $2,92($fp)
lw $2,92($fp)
nop
blez $2,$L21
nop
b $L22
nop
$L21:
lbu $2,32($fp)
nop
beq $2,$0,$L23
nop
addiu $2,$fp,48
li $5,45 # 0x2d
move $4,$2
jal std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::operator+=(char)
nop
$L23:
addiu $2,$fp,48
move $4,$2
jal std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::size() const
nop
addiu $2,$2,-1
sw $2,36($fp)
sw $0,28($fp)
$L25:
lw $3,28($fp)
lw $2,36($fp)
nop
slt $2,$3,$2
beq $2,$0,$L24
nop
lw $3,28($fp)
addiu $2,$fp,48
move $5,$3
move $4,$2
jal std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::operator[](unsigned int)
nop
lbu $2,0($2)
nop
sb $2,40($fp)
lw $3,28($fp)
addiu $2,$fp,48
move $5,$3
move $4,$2
jal std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::operator[](unsigned int)
nop
move $16,$2
lw $3,36($fp)
lw $2,28($fp)
nop
subu $2,$3,$2
move $3,$2
addiu $2,$fp,48
move $5,$3
move $4,$2
jal std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::operator[](unsigned int)
nop
lb $2,0($2)
nop
sb $2,0($16)
lw $3,36($fp)
lw $2,28($fp)
nop
subu $2,$3,$2
move $3,$2
addiu $2,$fp,48
move $5,$3
move $4,$2
jal std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::operator[](unsigned int)
nop
move $3,$2
lbu $2,40($fp)
nop
sb $2,0($3)
lw $2,28($fp)
nop
addiu $2,$2,1
sw $2,28($fp)
b $L25
nop
$L24:
addiu $2,$fp,48
move $5,$2
lw $4,88($fp)
jal std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::basic_string(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)
nop
addiu $2,$fp,48
move $4,$2
jal std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::~basic_string() [complete object destructor]
nop
b $L14
nop
move $16,$4
addiu $2,$fp,44
move $4,$2
jal std::allocator<char>::~allocator() [complete object destructor]
nop
move $2,$16
move $4,$2
jal _Unwind_Resume
nop
move $16,$4
addiu $2,$fp,48
move $4,$2
jal std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::~basic_string() [complete object destructor]
nop
move $2,$16
move $4,$2
jal _Unwind_Resume
nop
$L14:
lw $2,88($fp)
move $sp,$fp
lw $31,84($sp)
lw $fp,80($sp)
lw $16,76($sp)
addiu $sp,$sp,88
j $31
nop
ConvertBase(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, int, int):
addiu $sp,$sp,-32
sw $31,28($sp)
sw $fp,24($sp)
move $fp,$sp
sw $4,32($fp)
sw $5,36($fp)
sw $6,40($fp)
sw $7,44($fp)
lw $5,40($fp)
lw $4,36($fp)
jal ConvertTo10(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, int)
nop
move $3,$2
lw $2,32($fp)
lw $6,44($fp)
move $5,$3
move $4,$2
jal ConvertFrom10[abi:cxx11](long, int)
nop
lw $2,32($fp)
move $sp,$fp
lw $31,28($sp)
lw $fp,24($sp)
addiu $sp,$sp,32
j $31
nop
main:
addiu $sp,$sp,-96
sw $31,92($sp)
sw $fp,88($sp)
sw $16,84($sp)
move $fp,$sp
addiu $2,$fp,56
move $4,$2
jal std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::basic_string() [complete object constructor]
nop
addiu $2,$fp,48
move $5,$2
lui $2,%hi(_ZSt3cin)
addiu $4,$2,%lo(_ZSt3cin)
jal std::basic_istream<char, std::char_traits<char> >::operator>>(int&)
nop
addiu $2,$fp,56
move $5,$2
lui $2,%hi(_ZSt3cin)
addiu $4,$2,%lo(_ZSt3cin)
jal std::basic_istream<char, std::char_traits<char> >& std::operator>><char, std::char_traits<char>, std::allocator<char> >(std::basic_istream<char, std::char_traits<char> >&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >&)
nop
addiu $2,$fp,52
move $5,$2
lui $2,%hi(_ZSt3cin)
addiu $4,$2,%lo(_ZSt3cin)
jal std::basic_istream<char, std::char_traits<char> >::operator>>(int&)
nop
lw $3,48($fp)
lw $4,52($fp)
addiu $2,$fp,56
move $7,$4
move $6,$3
move $5,$2
addiu $2,$fp,24
move $4,$2
jal ConvertBase(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, int, int)
nop
addiu $2,$fp,24
move $5,$2
lui $2,%hi(_ZSt4cout)
addiu $4,$2,%lo(_ZSt4cout)
jal std::basic_ostream<char, std::char_traits<char> >& std::operator<< <char, std::char_traits<char>, std::allocator<char> >(std::basic_ostream<char, std::char_traits<char> >&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)
nop
move $3,$2
lui $2,%hi(_ZSt4endlIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_)
addiu $5,$2,%lo(_ZSt4endlIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_)
move $4,$3
jal std::basic_ostream<char, std::char_traits<char> >::operator<<(std::basic_ostream<char, std::char_traits<char> >& (*)(std::basic_ostream<char, std::char_traits<char> >&))
nop
addiu $2,$fp,24
move $4,$2
jal std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::~basic_string() [complete object destructor]
nop
move $16,$0
addiu $2,$fp,56
move $4,$2
jal std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::~basic_string() [complete object destructor]
nop
move $2,$16
b $L39
nop
move $16,$4
addiu $2,$fp,24
move $4,$2
jal std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::~basic_string() [complete object destructor]
nop
b $L36
nop
move $16,$4
$L36:
addiu $2,$fp,56
move $4,$2
jal std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::~basic_string() [complete object destructor]
nop
move $2,$16
move $4,$2
jal _Unwind_Resume
nop
$L39:
move $sp,$fp
lw $31,92($sp)
lw $fp,88($sp)
lw $16,84($sp)
addiu $sp,$sp,96
j $31
nop
__static_initialization_and_destruction_0(int, int):
addiu $sp,$sp,-32
sw $31,28($sp)
sw $fp,24($sp)
move $fp,$sp
sw $4,32($fp)
sw $5,36($fp)
lw $3,32($fp)
li $2,1 # 0x1
bne $3,$2,$L42
nop
lw $3,36($fp)
li $2,65535 # 0xffff
bne $3,$2,$L42
nop
lui $2,%hi(_ZStL8__ioinit)
addiu $4,$2,%lo(_ZStL8__ioinit)
jal std::ios_base::Init::Init() [complete object constructor]
nop
lui $2,%hi(__dso_handle)
addiu $6,$2,%lo(__dso_handle)
lui $2,%hi(_ZStL8__ioinit)
addiu $5,$2,%lo(_ZStL8__ioinit)
lui $2,%hi(_ZNSt8ios_base4InitD1Ev)
addiu $4,$2,%lo(_ZNSt8ios_base4InitD1Ev)
jal __cxa_atexit
nop
$L42:
nop
move $sp,$fp
lw $31,28($sp)
lw $fp,24($sp)
addiu $sp,$sp,32
j $31
nop
_GLOBAL__sub_I_ConvertTo10(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, int):
addiu $sp,$sp,-32
sw $31,28($sp)
sw $fp,24($sp)
move $fp,$sp
li $5,65535 # 0xffff
li $4,1 # 0x1
jal __static_initialization_and_destruction_0(int, int)
nop
move $sp,$fp
lw $31,28($sp)
lw $fp,24($sp)
addiu $sp,$sp,32
j $31
nop
DW.ref.__gxx_personality_v0:
.word __gxx_personality_v0


Related Solutions

Write a program in MIPS assembly language to convert an ASCII number string containing positive and...
Write a program in MIPS assembly language to convert an ASCII number string containing positive and negative integer decimal strings, to an integer. Your program should expect register $a0 to hold the address of a nullterminated string containing some combination of the digits 0 through 9. Your program should compute the integer value equivalent to this string of digits, then place the number in register $v0. If a non-digit character appears anywhere in the string, your program should stop with...
Can someone write a method in MIPS assembly language that asks the user for a hexadecimal...
Can someone write a method in MIPS assembly language that asks the user for a hexadecimal value and converts it into a decimal? I will thumbsup if its right
Convert from hexadecimal to binary to decimal (PLEASE SHOW WORK) 1. B2 - binary: - decimal:...
Convert from hexadecimal to binary to decimal (PLEASE SHOW WORK) 1. B2 - binary: - decimal: 2. 37 - binary: - decimal: 3. 0A -binary: - decimal: 4. 11 - binary: - decimal:
HCS12 Assembly Language: 1. Write a program to convert a decimal number stored at memory location...
HCS12 Assembly Language: 1. Write a program to convert a decimal number stored at memory location $1010 into a binary number. Store the result in memory location $2000
This is to be done with MIPS assembly language. Write MIPS code which is equivalent to...
This is to be done with MIPS assembly language. Write MIPS code which is equivalent to the follow java program: int day = (int)(Math.random() * 7); switch (day) { case 1: System.out.println(“Monday”); break case 2: System.out.println(“Tuesday”); break case 3: System.out.println(“Wednesday”); break case 4: System.out.println(“Thursday”); break case 5: System.out.println(“Friday”); break case 6: System.out.println(“Saturday”); break case 0: System.out.println(“Sunday”); break }
Convert the following binary values to hexadecimal and decimal (1 pt each) Write Hex Numbers as...
Convert the following binary values to hexadecimal and decimal (1 pt each) Write Hex Numbers as 0x##(ex 0x0A, 0xFF) Binary Hexadecimal Decimal 0001-1011 0x 0000-1000 0000-0100 0000-1001 0001-1111 1001-1001 0111-1010 1100-0010 1110-0101 1000-1010 0011-0100 0001-1001 0100-0011 1111-1111 1110-0111 0001-0010 0100-1000 0100-1110 1001-0001 0110-1100 Name: Convert the following hexadecimal values to binary and decimal Write binary numbers as 0000-0000 Hexadecimal Binary Decimal 0xf1 0xac 0x56 0x6c 0x32 0x30 0x05 0x28 0xf0 0x07 0x42 0xb9 0x6d 0x2f 0x71 0x0e 0x2d 0xfb 0xba...
Write a program in C++ that converts decimal numbers to binary, hexadecimal, and BCD. You are...
Write a program in C++ that converts decimal numbers to binary, hexadecimal, and BCD. You are not allowed to use library functions for conversion. The output should look exactly as follows: DECIMAL      BINARY                     HEXDECIMAL                      BCD 0                      0000 0000                   00                                            0000 0000 0000 1                      0000 0001                   01                                            0000 0000 0001 2                      0000 0010                   02                                            0000 0000 0010 .                       .                                   .                                               . .                       .                                   .                                               . 255                  1111 1111                   FF                                            0010 0101 0101
Convert a list of decimal numbers into their binary and hexadecimal equivalents Add the elements of...
Convert a list of decimal numbers into their binary and hexadecimal equivalents Add the elements of each of these lists to generate a total sum Print the lists, and the total sum of each value C++ contains some built-in functions (such as itoa and std::hex) which make this assignment trivial. You may NOT use these in your programs. You code must perform the conversion through your own algorithm. The input values are: 5 9 24 2 39 83 60 8...
MIPS Assembly LanguageWrite a MIPS assembly language program that asks the user toinput an...
MIPS Assembly LanguageWrite a MIPS assembly language program that asks the user to input an integer and then prints out a string that shows how that integer should be encoded using 16 bits. Your program should handle both positive and negative valued inputs. Your program should also print out an error message if the given input cannot be expressed as a 16 bit signed integer.As an example, if the input is 12, your program should output “0000000000001100”. If the input...
Write a program in MIPS assembly language to perform the calculation of the following equation and...
Write a program in MIPS assembly language to perform the calculation of the following equation and save the result accordingly:    f = 5x + 3y + z Assumptions: - Registers can be used to represent variables x, y, z, and f - Initialize x, y, and z to values of your choice. f can be initialized to zero. - Use comments to specify your register usage and explain your logic
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT