More Related Content Similar to Write a program in MIPS that reads in a Roman form number from th.pdf (20) More from santanadenisesarin13 (20) Write a program in MIPS that reads in a Roman form number from th.pdf1. Write a program in MIPS that reads in a Roman form number from the user, then output the
number in decimal form.
Write a program in MIPS that reads in a Roman form number from the user, then output the
number in decimal form.
Solution
Answer:
MIPS Assembly Language Program:
.zero 1
RomanNumber::RomanNumber(std::__cxx11::basic_string, std::allocator >):
push rbp
mov rbp, rsp
push rbx
sub rsp, 24
mov QWORD PTR [rbp-24], rdi
mov QWORD PTR [rbp-32], rsi
mov rax, QWORD PTR [rbp-24]
mov rdi, rax
call std::__cxx11::basic_string, std::allocator >::basic_string()
mov rax, QWORD PTR [rbp-24]
mov rdx, QWORD PTR [rbp-32]
mov rsi, rdx
mov rdi, rax
call std::__cxx11::basic_string, std::allocator >::operator=(std::__cxx11::basic_string,
std::allocator > const&)
jmp .L4
mov rbx, rax
mov rax, QWORD PTR [rbp-24]
mov rdi, rax
call std::__cxx11::basic_string, std::allocator >::~basic_string()
mov rax, rbx
mov rdi, rax
call _Unwind_Resume
2. .L4:
add rsp, 24
pop rbx
pop rbp
ret
.LC0:
.string " is not a Roman Numeral!"
RomanNumber::convert():
push rbp
mov rbp, rsp
sub rsp, 32
mov QWORD PTR [rbp-24], rdi
mov rax, QWORD PTR [rbp-24]
mov rdi, rax
call std::__cxx11::basic_string, std::allocator >::length() const
mov DWORD PTR [rbp-16], eax
mov DWORD PTR [rbp-4], 0
mov BYTE PTR [rbp-5], 0
mov DWORD PTR [rbp-12], 0
mov rax, QWORD PTR [rbp-24]
mov DWORD PTR [rax+32], 0
.L24:
cmp BYTE PTR [rbp-5], 0
jne .L6
mov eax, DWORD PTR [rbp-12]
cmp eax, DWORD PTR [rbp-16]
jge .L6
mov eax, DWORD PTR [rbp-12]
movsx rdx, eax
mov rax, QWORD PTR [rbp-24]
mov rsi, rdx
mov rdi, rax
call std::__cxx11::basic_string, std::allocator >::operator[](unsigned long)
movzx eax, BYTE PTR [rax]
movsx eax, al
sub eax, 67
3. cmp eax, 21
ja .L7
mov eax, eax
mov rax, QWORD PTR .L9[0+rax*8]
jmp rax
.L9:
.quad .L8
.quad .L10
.quad .L7
.quad .L7
.quad .L7
.quad .L7
.quad .L11
.quad .L7
.quad .L7
.quad .L12
.quad .L13
.quad .L7
.quad .L7
.quad .L7
.quad .L7
.quad .L7
.quad .L7
.quad .L7
.quad .L7
.quad .L14
.quad .L7
.quad .L15
.L13:
mov rax, QWORD PTR [rbp-24]
mov eax, DWORD PTR [rax+32]
lea edx, [rax+1000]
mov rax, QWORD PTR [rbp-24]
mov DWORD PTR [rax+32], edx
cmp DWORD PTR [rbp-4], 999
jg .L16
4. mov rax, QWORD PTR [rbp-24]
mov eax, DWORD PTR [rax+32]
mov edx, DWORD PTR [rbp-4]
add edx, edx
sub eax, edx
mov edx, eax
mov rax, QWORD PTR [rbp-24]
mov DWORD PTR [rax+32], edx
.L16:
mov DWORD PTR [rbp-4], 1000
jmp .L17
.L10:
mov rax, QWORD PTR [rbp-24]
mov eax, DWORD PTR [rax+32]
lea edx, [rax+500]
mov rax, QWORD PTR [rbp-24]
mov DWORD PTR [rax+32], edx
cmp DWORD PTR [rbp-4], 499
jg .L18
mov rax, QWORD PTR [rbp-24]
mov eax, DWORD PTR [rax+32]
mov edx, DWORD PTR [rbp-4]
add edx, edx
sub eax, edx
mov edx, eax
mov rax, QWORD PTR [rbp-24]
mov DWORD PTR [rax+32], edx
.L18:
mov DWORD PTR [rbp-4], 500
jmp .L17
.L8:
mov rax, QWORD PTR [rbp-24]
mov eax, DWORD PTR [rax+32]
lea edx, [rax+100]
mov rax, QWORD PTR [rbp-24]
mov DWORD PTR [rax+32], edx
5. cmp DWORD PTR [rbp-4], 99
jg .L19
mov rax, QWORD PTR [rbp-24]
mov eax, DWORD PTR [rax+32]
mov edx, DWORD PTR [rbp-4]
add edx, edx
sub eax, edx
mov edx, eax
mov rax, QWORD PTR [rbp-24]
mov DWORD PTR [rax+32], edx
.L19:
mov DWORD PTR [rbp-4], 100
jmp .L17
.L12:
mov rax, QWORD PTR [rbp-24]
mov eax, DWORD PTR [rax+32]
lea edx, [rax+50]
mov rax, QWORD PTR [rbp-24]
mov DWORD PTR [rax+32], edx
cmp DWORD PTR [rbp-4], 49
jg .L20
mov rax, QWORD PTR [rbp-24]
mov eax, DWORD PTR [rax+32]
mov edx, DWORD PTR [rbp-4]
add edx, edx
sub eax, edx
mov edx, eax
mov rax, QWORD PTR [rbp-24]
mov DWORD PTR [rax+32], edx
.L20:
mov DWORD PTR [rbp-4], 50
jmp .L17
.L15:
mov rax, QWORD PTR [rbp-24]
mov eax, DWORD PTR [rax+32]
lea edx, [rax+10]
6. mov rax, QWORD PTR [rbp-24]
mov DWORD PTR [rax+32], edx
cmp DWORD PTR [rbp-4], 9
jg .L21
mov rax, QWORD PTR [rbp-24]
mov eax, DWORD PTR [rax+32]
mov edx, DWORD PTR [rbp-4]
add edx, edx
sub eax, edx
mov edx, eax
mov rax, QWORD PTR [rbp-24]
mov DWORD PTR [rax+32], edx
.L21:
mov DWORD PTR [rbp-4], 10
jmp .L17
.L14:
mov rax, QWORD PTR [rbp-24]
mov eax, DWORD PTR [rax+32]
lea edx, [rax+5]
mov rax, QWORD PTR [rbp-24]
mov DWORD PTR [rax+32], edx
cmp DWORD PTR [rbp-4], 4
jg .L22
mov rax, QWORD PTR [rbp-24]
mov eax, DWORD PTR [rax+32]
mov edx, DWORD PTR [rbp-4]
add edx, edx
sub eax, edx
mov edx, eax
mov rax, QWORD PTR [rbp-24]
mov DWORD PTR [rax+32], edx
.L22:
mov DWORD PTR [rbp-4], 5
jmp .L17
.L11:
mov rax, QWORD PTR [rbp-24]
7. mov eax, DWORD PTR [rax+32]
lea edx, [rax+1]
mov rax, QWORD PTR [rbp-24]
mov DWORD PTR [rax+32], edx
cmp DWORD PTR [rbp-4], 0
jg .L23
mov rax, QWORD PTR [rbp-24]
mov eax, DWORD PTR [rax+32]
mov edx, DWORD PTR [rbp-4]
add edx, edx
sub eax, edx
mov edx, eax
mov rax, QWORD PTR [rbp-24]
mov DWORD PTR [rax+32], edx
.L23:
mov DWORD PTR [rbp-4], 1
jmp .L17
.L7:
mov eax, DWORD PTR [rbp-12]
movsx rdx, eax
mov rax, QWORD PTR [rbp-24]
mov rsi, rdx
mov rdi, rax
call std::__cxx11::basic_string, std::allocator >::operator[](unsigned long)
movzx eax, BYTE PTR [rax]
movsx eax, al
mov esi, eax
mov edi, OFFSET FLAT:std::cout
call std::basic_ostream >& std::operator<< >(std::basic_ostream >&, char)
mov esi, OFFSET FLAT:.LC0
mov rdi, rax
call std::basic_ostream >& std::operator<< >(std::basic_ostream >&, char const*)
mov esi, OFFSET FLAT:std::basic_ostream >& std::endl >(std::basic_ostream >&)
mov rdi, rax
call std::basic_ostream >::operator<<(std::basic_ostream >& (*)(std::basic_ostream >&))
mov BYTE PTR [rbp-5], 1
8. mov rax, QWORD PTR [rbp-24]
mov DWORD PTR [rax+32], 0
.L17:
add DWORD PTR [rbp-12], 1
jmp .L24
.L6:
mov rax, QWORD PTR [rbp-24]
mov eax, DWORD PTR [rax+32]
leave
ret
RomanNumber::~RomanNumber():
push rbp
mov rbp, rsp
sub rsp, 16
mov QWORD PTR [rbp-8], rdi
mov rax, QWORD PTR [rbp-8]
mov rdi, rax
call std::__cxx11::basic_string, std::allocator >::~basic_string()
nop
leave
ret
.LC1:
.string "color 1F"
.LC2:
.string " tt....ROMAN NUMBER TO DECIMAL CONVERTER.... "
.LC3:
.string " tEnter your input in Roman Number(Plz Keep Caps Lock On): "
.LC4:
.string " ttRoman Number "
.LC5:
.string " is equals to Decimal "
.LC6:
.string "pause"
main:
push rbp
mov rbp, rsp
9. push rbx
sub rsp, 136
mov edi, OFFSET FLAT:.LC1
call system
lea rax, [rbp-96]
mov rdi, rax
call std::__cxx11::basic_string, std::allocator >::basic_string()
mov esi, OFFSET FLAT:.LC2
mov edi, OFFSET FLAT:std::cout
call std::basic_ostream >& std::operator<< >(std::basic_ostream >&, char const*)
mov esi, OFFSET FLAT:.LC3
mov edi, OFFSET FLAT:std::cout
call std::basic_ostream >& std::operator<< >(std::basic_ostream >&, char const*)
lea rax, [rbp-96]
mov rsi, rax
mov edi, OFFSET FLAT:std::cin
call std::basic_istream >& std::operator>>, std::allocator >(std::basic_istream >&,
std::__cxx11::basic_string, std::allocator >&)
lea rdx, [rbp-96]
lea rax, [rbp-64]
mov rsi, rdx
mov rdi, rax
call std::__cxx11::basic_string, std::allocator >::basic_string(std::__cxx11::basic_string,
std::allocator > const&)
lea rdx, [rbp-64]
lea rax, [rbp-144]
mov rsi, rdx
mov rdi, rax
call RomanNumber::RomanNumber(std::__cxx11::basic_string, std::allocator >)
lea rax, [rbp-64]
mov rdi, rax
call std::__cxx11::basic_string, std::allocator >::~basic_string()
lea rax, [rbp-144]
mov rdi, rax
call RomanNumber::convert()
mov DWORD PTR [rbp-20], eax
10. mov esi, OFFSET FLAT:.LC4
mov edi, OFFSET FLAT:std::cout
call std::basic_ostream >& std::operator<< >(std::basic_ostream >&, char const*)
mov rdx, rax
lea rax, [rbp-96]
mov rsi, rax
mov rdi, rdx
call std::basic_ostream >& std::operator<< , std::allocator >(std::basic_ostream >&,
std::__cxx11::basic_string, std::allocator > const&)
mov esi, OFFSET FLAT:.LC5
mov rdi, rax
call std::basic_ostream >& std::operator<< >(std::basic_ostream >&, char const*)
mov rdx, rax
mov eax, DWORD PTR [rbp-20]
mov esi, eax
mov rdi, rdx
call std::basic_ostream >::operator<<(int)
mov esi, OFFSET FLAT:std::basic_ostream >& std::endl >(std::basic_ostream >&)
mov rdi, rax
call std::basic_ostream >::operator<<(std::basic_ostream >& (*)(std::basic_ostream >&))
mov esi, OFFSET FLAT:std::basic_ostream >& std::endl >(std::basic_ostream >&)
mov rdi, rax
call std::basic_ostream >::operator<<(std::basic_ostream >& (*)(std::basic_ostream >&))
mov edi, OFFSET FLAT:.LC6
call system
mov ebx, 0
lea rax, [rbp-144]
mov rdi, rax
call RomanNumber::~RomanNumber()
lea rax, [rbp-96]
mov rdi, rax
call std::__cxx11::basic_string, std::allocator >::~basic_string()
mov eax, ebx
jmp .L35
mov rbx, rax
lea rax, [rbp-64]
11. mov rdi, rax
call std::__cxx11::basic_string, std::allocator >::~basic_string()
jmp .L30
mov rbx, rax
lea rax, [rbp-144]
mov rdi, rax
call RomanNumber::~RomanNumber()
jmp .L30
mov rbx, rax
.L30:
lea rax, [rbp-96]
mov rdi, rax
call std::__cxx11::basic_string, std::allocator >::~basic_string()
mov rax, rbx
mov rdi, rax
call _Unwind_Resume
.L35:
add rsp, 136
pop rbx
pop rbp
ret
__static_initialization_and_destruction_0(int, int):
push rbp
mov rbp, rsp
sub rsp, 16
mov DWORD PTR [rbp-4], edi
mov DWORD PTR [rbp-8], esi
cmp DWORD PTR [rbp-4], 1
jne .L38
cmp DWORD PTR [rbp-8], 65535
jne .L38
mov edi, OFFSET FLAT:std::__ioinit
call std::ios_base::Init::Init()
mov edx, OFFSET FLAT:__dso_handle
mov esi, OFFSET FLAT:std::__ioinit
mov edi, OFFSET FLAT:std::ios_base::Init::~Init()