1. Write a PIC18FXX2 assembly program that takes the variable A and save into B
ID: 3775774 • Letter: 1
Question
1. Write a PIC18FXX2 assembly program that takes the variable A and save into B in inverted the bit order. For example, if A = 110010102, then the program finishes with B = 010100112. The variable A shall preserve the original value at the end of the program execution. The program shall be implemented using any of the loop and shift techniques discussed in class.
2. Write a PIC18FXX2 assembly program that makes the calculus of the first ten (10) terms of the Fibonacci series. This is define by Fn = Fn-1 + Fn-2, with initial values F0 = 0 and F1 = 1. If the following code implements the series in C language.
Explanation / Answer
Answer:
Assembly Language Code:
2)
.zero 1
.LC0:
.string "Enter the number of terms: "
.LC1:
.string "Fibonacci Series: "
.LC2:
.string " "
main:
push rbp
mov rbp, rsp
sub rsp, 32
mov DWORD PTR [rbp-4], 0
mov DWORD PTR [rbp-8], 1
mov DWORD PTR [rbp-16], 0
mov esi, OFFSET FLAT:.LC0
mov edi, OFFSET FLAT:std::cout
call std::basic_ostream<char, std::char_traits<char> >& std::operator<< <std::char_traits<char> >(std::basic_ostream<char, std::char_traits<char> >&, char const*)
lea rax, [rbp-20]
mov rsi, rax
mov edi, OFFSET FLAT:std::cin
call std::basic_istream<char, std::char_traits<char> >::operator>>(int&)
mov esi, OFFSET FLAT:.LC1
mov edi, OFFSET FLAT:std::cout
call std::basic_ostream<char, std::char_traits<char> >& std::operator<< <std::char_traits<char> >(std::basic_ostream<char, std::char_traits<char> >&, char const*)
mov DWORD PTR [rbp-12], 1
.L6:
mov eax, DWORD PTR [rbp-20]
cmp DWORD PTR [rbp-12], eax
jg .L2
cmp DWORD PTR [rbp-12], 1
jne .L3
mov esi, OFFSET FLAT:.LC2
mov edi, OFFSET FLAT:std::cout
call std::basic_ostream<char, std::char_traits<char> >& std::operator<< <std::char_traits<char> >(std::basic_ostream<char, std::char_traits<char> >&, char const*)
mov rdx, rax
mov eax, DWORD PTR [rbp-4]
mov esi, eax
mov rdi, rdx
call std::basic_ostream<char, std::char_traits<char> >::operator<<(int)
jmp .L4
.L3:
cmp DWORD PTR [rbp-12], 2
jne .L5
mov eax, DWORD PTR [rbp-8]
mov esi, eax
mov edi, OFFSET FLAT:std::cout
call std::basic_ostream<char, std::char_traits<char> >::operator<<(int)
mov esi, OFFSET FLAT:.LC2
mov rdi, rax
call std::basic_ostream<char, std::char_traits<char> >& std::operator<< <std::char_traits<char> >(std::basic_ostream<char, std::char_traits<char> >&, char const*)
jmp .L4
.L5:
mov edx, DWORD PTR [rbp-4]
mov eax, DWORD PTR [rbp-8]
add eax, edx
mov DWORD PTR [rbp-16], eax
mov eax, DWORD PTR [rbp-8]
mov DWORD PTR [rbp-4], eax
mov eax, DWORD PTR [rbp-16]
mov DWORD PTR [rbp-8], eax
mov eax, DWORD PTR [rbp-16]
mov esi, eax
mov edi, OFFSET FLAT:std::cout
call std::basic_ostream<char, std::char_traits<char> >::operator<<(int)
mov esi, OFFSET FLAT:.LC2
mov rdi, rax
call std::basic_ostream<char, std::char_traits<char> >& std::operator<< <std::char_traits<char> >(std::basic_ostream<char, std::char_traits<char> >&, char const*)
.L4:
add DWORD PTR [rbp-12], 1
jmp .L6
.L2:
mov eax, 0
leave
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 .L10
cmp DWORD PTR [rbp-8], 65535
jne .L10
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()
call __cxa_atexit
.L10:
nop
leave
ret
push rbp
mov rbp, rsp
mov esi, 65535
mov edi, 1
call __static_initialization_and_destruction_0(int, int)
pop rbp
ret
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.