For your first project, you will design a simple 8051 program using Keil (no phy
ID: 673348 • Letter: F
Question
For your first project, you will design a simple 8051 program using Keil (no physical implementation). Your task is to design a 4-bit Fibonacci sequence, available on-demand to the user. The Fibonacci sequence is a widely-used sequence in scientific applications. Its first two numbers are 0 and 1, and any other number in the sequence can be calculated as a sum of two previous numbers. The sequence for the first five (5) numbers is as follows: 0, 1, 1, 2, 3. Your task is to write an ASM program to generate a Fibonacci sequence by dividing it into the separate modules listed below:
a) Assume there are 4 switches connected to the lower 4 bits of P1 for a user to be able to enter any combination desired up to 1510 (15 possibilities). Assume that if the user enters 0x00, then the program does nothing and waits for a proper input. Write code to take the value input by the user and store it in R5. Make sure that the upper 4 bits of P1 are cleared before storing the input value in R5.
b) Pin P2.1 will act as a control input, determining the source of the Fibonacci sequence output to the user. If P2.1 is set to '1', then the Fibonacci sequence will be read from the ROM. You will need to calculate the values of the first 15 Fibonacci numbers and write code to store them in a look-up table in the ROM starting at address 200H, reading them one by one and outputting them to the user, as described in the next section. If P2.1 is set to '0', the Fibonacci sequence will be calculated on-the-fly. You can use any registers you want (except the ones already in use) to accomplish this. It may be the case that for some numbers in the sequence, the value will be larger than the memory/registers can accommodate. For that/those case(s), you will need to set the Carry (CY) bit to indicate that the number is larger than we can display with 8 bits. The remaining lower 8 bits of the number will be displayed to the user.
c) Write code that reads the input value stored in R5 and outputs the list of Fibonacci numbers based on the input value (e.g. If R5 = 5, the first five (5) Fibonacci numbers will be displayed.) Once a value is available, it needs to be displayed on P3. Insert a delay of 27,250 µs after displaying each number and show the full delay subroutine in your code. Assume a standard 8051 microcontroller is used with a frequency of 11.0592 MHz.
I am just stumped on how to begin this project. Could anyone lead me in the right direction?
Explanation / Answer
.Ltext0:
.section .rodata
.align 8
.LC0:
0000 0A20456E .string " Enter the number of items in the sequence: "
74657220
74686520
6E756D62
6572206F
.LC1:
002e 256400 .string "%d"
.LC2:
0031 0A202564 .string " %d %d"
20256400
.LC3:
0039 20256420 .string " %d "
00
.text
.globl main
main:
.LFB0:
.cfi_startproc
0000 55 pushq %rbp
.cfi_def_cfa_offset 16
.cfi_offset 6, -16
0001 4889E5 movq %rsp, %rbp
.cfi_def_cfa_register 6
0004 4883EC20 subq $32, %rsp
0008 C745F800 movl $0, -8(%rbp)
000000
000f C745E800 movl $0, -24(%rbp)
000000
0016 C745EC01 movl $1, -20(%rbp)
000000
001d C745F001 movl $1, -16(%rbp)
000000
0024 C745F401 movl $1, -12(%rbp)
000000
002b BF000000 movl $.LC0, %edi
00
0030 B8000000 movl $0, %eax
00
0035 E8000000 call printf
00
003a 488D45E0 leaq -32(%rbp), %rax
003e 4889C6 movq %rax, %rsi
0041 BF000000 movl $.LC1, %edi
00
0046 B8000000 movl $0, %eax
00
004b E8000000 call __isoc99_scanf
00
0050 8B55EC movl -20(%rbp), %edx
0053 8B45E8 movl -24(%rbp), %eax
0056 89C6 movl %eax, %esi
0058 BF000000 movl $.LC2, %edi
00
005d B8000000 movl $0, %eax
00
0062 E8000000 call printf
00
0067 C745E401 movl $1, -28(%rbp)
000000
006e EB5B jmp .L2
.L7:
0070 8B45EC movl -20(%rbp), %eax
0073 8B55E8 movl -24(%rbp), %edx
0076 01D0 addl %edx, %eax
0078 8945FC movl %eax, -4(%rbp)
007b 8B45FC movl -4(%rbp), %eax
007e 89C6 movl %eax, %esi
0080 BF000000 movl $.LC3, %edi
00
0085 B8000000 movl $0, %eax
00
008a E8000000 call printf
00
008f 8B45EC movl -20(%rbp), %eax
0092 8945E8 movl %eax, -24(%rbp)
0095 8B45FC movl -4(%rbp), %eax
0098 8945EC movl %eax, -20(%rbp)
009b C745F001 movl $1, -16(%rbp)
000000
00a2 EB1A jmp .L3
.L6:
00a4 C745F401 movl $1, -12(%rbp)
000000
00ab EB04 jmp .L4
.L5:
00ad 8345F401 addl $1, -12(%rbp)
.L4:
00ba 8345F001 addl $1, -16(%rbp)
00b1 817DF472 cmpl $27250, -12(%rbp)
6A0000
00b8 7EF3 jle .L5
.L3:
00c7 8345E401 addl $1, -28(%rbp)
00be 817DF072 cmpl $27250, -16(%rbp)
6A0000
00c5 7EDD jle .L6
.L2:
00cb 8B45E0 movl -32(%rbp), %eax
00ce 3945E4 cmpl %eax, -28(%rbp)
00d1 7E9D jle .L7
00d3 B8000000 movl $0, %eax
00
00d8 C9 leave
.cfi_def_cfa 7, 8
00d9 C3 ret
.cfi_endproc
.LFE0:
.Letext0:
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.