斐波那契程序
Problem statement:
问题陈述:
Write an assembly language program in 8085 microprocessor to generate Fibonacci series.
在8085微处理器中编写汇编语言程序以生成Fibonacci系列。
Example: Assume Fibonacci series is stored at starting memory location 3050.
示例:假设斐波那契数列存储在起始存储位置3050中。
3050 = 00, 3051 = 01, 3052 = 02, 3053 = 03 and so on.
Note: This program generates Fibonacci series in hexadecimal numbers.
注意:此程序以十六进制数生成斐波那契数列。
Algorithm:
算法:
Initialize register H with 30 and register L with 50, so that indirect memory M points to memory location 3050.
用30初始化寄存器H并用50初始化寄存器L,以便间接存储器M指向存储器位置3050。
Initialize register B with 00, register C with 08 and register D with 01.
用00初始化寄存器B,用08初始化寄存器C,用01初始化寄存器D.
Move the content of B in M.
将B的内容移至M。
Increment M by 1 so that M points to next memory location.
将M递增1,以使M指向下一个存储位置。
Move the content of D in M.
在M中移动D的内容。
Move the content of B in accumulator A.
将B的内容移动到累加器A中。
Add the content of D in A.
在A中添加D的内容。
Move the content of D in B.
在B中移动D的内容。
Move the content of A in D.
在D中移动A的内容。
Increment M by 1 so that M points to next memory location.
将M递增1,以使M指向下一个存储位置。
Move the content of A in M.
将A的内容移到M中。
Decrements C by 1.
将C减1。
Jump to memory location 200D if ZF = 0 otherwise Halt the program.
如果ZF = 0,则跳转到内存位置200D,否则暂停程序。
Program:
程序:
ADDRESS | MNEMONICS | COMMENTS |
---|---|---|
2000 | LXI H, 3050 | H ← 30, L ← 50 |
2003 | MVI C, 08 | C ← 08 |
2005 | MVI B, 00 | B ← 00 |
2007 | MVI D, 01 | D ← 01 |
2009 | MOV M, B | M ← B |
200A | INX H | M ← M + 01 |
200B | MOV M, D | M ← D |
200C | MOV A, B | A ← B |
200D | ADD D | A ← A + D |
200E | MOV B, D | B ← D |
200F | MOV D, A | D ← A |
2010 | INX H | M ← M + 01 |
2011 | MOV M, A | M ← A |
2012 | DCR C | C ← C – 01 |
2013 | JNZ 200D | Jump if ZF = 0 |
2016 | HLT | END |
地址 | 记忆 | 注释 |
---|---|---|
2000 | LXI H,3050 | 高←30,长←50 |
2003年 | MVI C,08 | C←08 |
2005年 | MVI B,00 | B←00 |
2007年 | MVI D,01 | D←01 |
2009年 | MOV M,B | M←B |
200A | INX H | M←M + 01 |
200B | MOV M,D | M←D |
200度 | MOV A,B | A←B |
200D | 添加D | A←A + D |
200E | MOV B,D | B←D |
200楼 | MOV D,A | D←A |
2010 | INX H | M←M + 01 |
2011年 | MOV M,A | M←A |
2012年 | DCR C | C←C – 01 |
2013年 | JNZ 200D | 如果ZF = 0则跳转 |
2016年 | HLT | 结束 |
Explanation: Registers A, B, C, D, H, L are used for general purpose.
说明:寄存器A,B,C,D,H,L用于通用。
LXI H 3050: assigns 30 to H and 50 to L.
LXI H 3050:将30分配给H,将50分配给L。
MVI B, 00: assigns 00 to B.
MVI B,00:将00分配给B。
MVI C, 08: assigns 08 to C.
MVI C,08:将08分配给C。
MVI D, 01: assigns 01 to D.
MVI D,01:将01分配给D。
MOV M, B: moves the content of B in M.
MOV M,B:移动M中B的内容。
INX H: increment M by 1.
INX H:将 M递增1。
MOV M, D: moves the content of D in M.
MOV M,D:在M中移动D的内容。
MOV A, B: moves the content of B in A.
MOV A,B:移动B在A中的内容。
ADD D: add the content of D and A. Store the result in A.
添加D:添加D和A的内容。将结果存储在A中。
MOV B, D: moves the content of D in B.
MOV B,D:移动B中D的内容。
MOV D, A: moves the content of A in D.
MOV D,A:在D中移动A的内容。
INX H: increment M by 1.
INX H:将 M递增1。
MOV M, A: moves the content of A in M.
MOV M,A:在M中移动A的内容。
DCR C: decrements C by 1.
DCR C:将C减1。
JNZ 200C: jump to memory location 200D if ZF = 0.
JNZ 200C:如果ZF = 0则跳转到存储位置200D。
HLT: stops executing the program and halts any further execution.
HLT:停止执行程序,并停止任何进一步的执行。
翻译自: https://www.includehelp.com/embedded-system/fibonacci-series-program-using-8085-microprocessor.aspx
斐波那契程序