In: Computer Science
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
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