avr单片机用C语言仿真软件编译之后生成hex文件,我们可以通过单片机反汇编软件来还原汇编代码,
产生的.hex文件通过反汇编,之后得到的代码,其此函数的功能也就是获得每一个自定义的函数在flash里的地址,通过反汇编更能了解其数值返回过程,解读。
通过此的反汇编之后的代码,可以用来做基于avr的多任务机制点击衔接。
如下
; reassembly of "实验.hex"
; created by ReAVR V3.2.0
; at 2010/01/31 - 19:38:25
; for ICCAVR assembler
;---------------------------------------
; AVR_TYPE=
; FLASH_SIZE=8KB
; SRAM_START=0x60
;---------------------------------------
.area text
;; older iccavr need different setup:
;; .area text (abs,ovr)
;; .org 0x0000
;---------------------------------------
; byte constants:
;
k00 = 0x00 ;
k01 = 0x01 ;
k02 = 0x02 ;
k03 = 0x03 ;
k04 = 0x04 ;
k05 = 0x05 ;
k08 = 0x08 ;
k10 = 0x10 ;
k40 = 0x40 ;@
k5F = 0x5F ; _
k60 = 0x60 ; `
k69 = 0x69 ; i
kAA = 0xAA ; ?
kFF = 0xFF ;
;
; io register addresses://Data Address Space
;
p11 = 0x11
p12 = 0x12
p14 = 0x14
p15 = 0x15
p17 = 0x17
p18 = 0x18
p1A = 0x1A
p1B = 0x1B
p34 = 0x34
p35 = 0x35
p3B = 0x3B
p3D = 0x3D
p3E = 0x3E
p3F = 0x3F
;
; bit numbers:
;
b0 = 0x00
b1 = 0x01
b2 = 0x02
b3 = 0x03
b4 = 0x04
b5 = 0x05
b6 = 0x06
b7 = 0x07
;---------------------------------------
;
L0000:
jmp __start ; L0030
; ----------- jump on last line
jmp L006E
; ----------- jump on last line
.word 0xFFFF ; pc=0x0004(0x0008)
.word 0xFFFF ; pc=0x0005(0x000A)
.word 0xFFFF ; pc=0x0006(0x000C)
.word 0xFFFF ; pc=0x0007(0x000E)
.word 0xFFFF ; pc=0x0008(0x0010)
.word 0xFFFF ; pc=0x0009(0x0012)
.word 0xFFFF ; pc=0x000A(0x0014)
.word 0xFFFF ; pc=0x000B(0x0016)
.word 0xFFFF ; pc=0x000C(0x0018)
.word 0xFFFF ; pc=0x000D(0x001A)
.word 0xFFFF ; pc=0x000E(0x001C)
.word 0xFFFF ; pc=0x000F(0x001E)
.word 0xFFFF ; pc=0x0010(0x0020)
.word 0xFFFF ; pc=0x0011(0x0022)
.word 0xFFFF ; pc=0x0012(0x0024)
.word 0xFFFF ; pc=0x0013(0x0026)
.word 0xFFFF ; pc=0x0014(0x0028)
.word 0xFFFF ; pc=0x0015(0x002A)
.word 0xFFFF ; pc=0x0016(0x002C)
.word 0xFFFF ; pc=0x0017(0x002E)
.word 0xFFFF ; pc=0x0018(0x0030)
.word 0xFFFF ; pc=0x0019(0x0032)
.word 0xFFFF ; pc=0x001A(0x0034)
.word 0xFFFF ; pc=0x001B(0x0036)
.word 0xFFFF ; pc=0x001C(0x0038)
.word 0xFFFF ; pc=0x001D(0x003A)
.word 0xFFFF ; pc=0x001E(0x003C)
.word 0xFFFF ; pc=0x001F(0x003E)
.word 0xFFFF ; pc=0x0020(0x0040)
.word 0xFFFF ; pc=0x0021(0x0042)
.word 0xFFFF ; pc=0x0022(0x0044)
.word 0xFFFF ; pc=0x0023(0x0046)
.word 0xFFFF ; pc=0x0024(0x0048)
.word 0xFFFF ; pc=0x0025(0x004A)
.word 0xFFFF ; pc=0x0026(0x004C)
.word 0xFFFF ; pc=0x0027(0x004E)
.word 0xFFFF ; pc=0x0028(0x0050)
.word 0xFFFF ; pc=0x0029(0x0052)
.word 0xFFFF ; pc=0x002A(0x0054)
.word 0xFFFF ; pc=0x002B(0x0056)
.word 0xFFFF ; pc=0x002C(0x0058)
.word 0xFFFF ; pc=0x002D(0x005A)
.word 0xFFFF ; pc=0x002E(0x005C)
.word 0xFFFF ; pc=0x002F(0x005E)
;
__start:://*头文件加载 I/O Registers 0020-005f*/
; L0030:
ldi r28,k5F; LDI Rd, K 加载立即数
ldi r29,k04
out p3D,r28; OUT P, Rr 将数据输出到端口
out p3E,r29
subi r28,k10;SUBI Rd, K 立即数与寄存器相减
sbci r29,k00;SBCI Rd, K 寄存器与常数及进位位相减
ldi r16,kAA
std Y+o00,r16;STD Z+q,Rr 带偏移量的间接存储
clr r0
ldi r30,k60
ldi r31,k00
ldi r17,k00
L003C:
cpi r30,k69;CPI Rd,K 比较寄存器与立即数
cpc r31,r17;CPC Rd,Rr 带进位位比较
breq L0041;BREQ k 相等即跳转
; ----- branch on last line
st Z+,r0;ST Z+, Rr 间接存储并执行后加操作
rjmp L003C
; ----------- jump on last line
L0041:
st Z,r16;ST Z, Rr 间接存储
ldi r30,k60
ldi r31,k00
ldi r26,k60
ldi r27,k00
ldi r17,k00
L0047:
cpi r30,k60
cpc r31,r17
breq L004E
; ----- branch on last line
lpm
adiw r30,k01
st X+,r0
rjmp L0047
; ----------- jump on last line
L004E:
call L00C2
L0050:
rjmp L0050
; ----------- jump on last line
; pc=0x51(0xA2) yanshi_0(void)
;
L0051:
rjmp L0054
; ----------- jump on last line
L0052:
ldi r24,k01
out p18,r24
L0054:
rjmp L0052
; ----------- jump on last line
ret
;----------------------*
; pc=0x56(0xAC) yanshi_1(void)
;
L0056:
rjmp L0059
; ----------- jump on last line
L0057:
ldi r24,k02
out p18,r24
L0059:
rjmp L0057
; ----------- jump on last line
ret
;----------------------*
; pc=0x5B(0xB6) yanshi_2(void)
;
L005B:
rjmp L005E
; ----------- jump on last line
L005C:
ldi r24,k04
out p18,r24
L005E:
rjmp L005C
; ----------- jump on last line
ret
;----------------------*
; pc=0x60(0xC0) void yanshi_3(void)
;
L0060:;第一个函数
rjmp L0063
; ----------- jump on last line
L0061:
ldi r24,k08
out p18,r24
L0063:
rjmp L0061
; ----------- jump on last line
ret
;----------------------*
; pc=0x65(0xCA) void int_init(void)
;
L0065:
in r24,p35
ori r24,k02
out p35,r24
in r2,p34
out p34,r2
in r24,p3B
ori r24,k40
out p3B,r24
ret
;----------------------*
; pc=0x6E(0xDC)
/*************************** 中断函数**************************/
;
L006E:
st -Y,r2;ST - Y, Rr 间接存储并执行预减操作
st -Y,r3
st -Y,r24
st -Y,r25
in r2,p3F;IN Rd, P 读入端口数据
st -Y,r2
/* if(k==0)
{SP=sp_1-2;}
*/
lds r2,D0060;LDS Rd, k 从 SRAM 中直接加载
tst r2; TST Rd 测试为 0 或负
brne L0081;BRNE k 不相等即跳转
; ----- branch on last line
lds r2,D0067
lds r3,D0068
sts (p3E+0x20),r3 ; io register
sts (p3D+0x20),r2 ; io register
rjmp L00A7
; ----------- jump on last line
L0081:/*
if(k==1)
{SP=sp_2-2;}*/
lds r24,D0060
cpi r24,k01
brne L008E
; ----- branch on last line
lds r2,D0065
lds r3,D0066
sts (p3E+0x20),r3 ; io register
sts (p3D+0x20),r2 ; io register
rjmp L00A7
; ----------- jump on last line
L008E:/*
if(k==2)
{SP=sp_3-2;}*/
lds r24,D0060
cpi r24,k02
brne L009B
; ----- branch on last line
lds r2,D0063
lds r3,D0064
sts (p3E+0x20),r3 ; io register
sts (p3D+0x20),r2 ; io register
rjmp L00A7
; ----------- jump on last line
L009B:
/*
if(k==3)
{SP=sp_4-2;}
*/
lds r24,D0060
cpi r24,k03
brne L00A7
; ----- branch on last line
lds r2,D0061
lds r3,D0062
sts (p3E+0x20),r3 ; io register
sts (p3D+0x20),r2 ; io register
L00A7:
/*k++;
if(k==4)
k=0;
*/
lds r24,D0060
subi r24,kFF
sts D0060,r24
cpi r24,k04
brne L00B1
; ----- branch on last line
clr r2
sts D0060,r2
L00B1:
ld r2,Y+
out p3F,r2
ld r25,Y+
ld r24,Y+
ld r3,Y+
ld r2,Y+
reti
/*******中断结束************************/
;----------------------*
; pc=0xB8(0x170)
;延时函数
ldi r16,k05
ldi r17,k00
L00BA:
movw r2,r16
subi r16,k01
sbci r17,k00
tst r2
brne L00BA
; ----- branch on last line
tst r3
brne L00BA
; ----- branch on last line
ret
;----------------------*
; pc=0xC2(0x184)
;;主函数部分
/**io端口初始化*/
L00C2:
ldi r24,kFF
out p1B,r24
out p1A,r24
out p18,r24
out p17,r24
out p15,r24
clr r2
out p14,r2
out p12,r24
out p11,r2
rcall L0065
rjmp L00EA
; ----------- jump on last line
L00CE:;while循环部分
in r2,p3D
in r3,p3E
sts D0068,r3; STS k, Rr 直接存储到 SRAM
sts D0067,r2
rcall L0051
in r2,p3D
in r3,p3E
sts D0066,r3
sts D0065,r2
rcall L0056
in r2,p3D
in r3,p3E
sts D0064,r3
sts D0063,r2
rcall L005B
in r2,p3D
in r3,p3E
sts D0062,r3
sts D0061,r2
rcall L0060
L00EA:
rjmp L00CE
; ----------- jump on last line
ret
;----------------------*
; pc=0xEC(0x1D8)
;
__text_end::
;
; last flash byte address = 0x01D7
; last flash word address = 0x00EB
;---------------------------------------
.area bss (abs)
.org 0x0060
;;Internal SRAM 内置的静态随机存储器D0060-D045F
__first_bss::
;
D0060:
.blkb 1
D0061:
.blkb 1
D0062:
.blkb 1
D0063:
.blkb 1
D0064:
.blkb 1
D0065:
.blkb 1
D0066:
.blkb 1
D0067:
.blkb 1
D0068:
;
__last_bss::
;
; last lds/sts data byte at 0x0068
;---------------------------------------
;
单片机疑难问题咨询:方先生 手机:15328075932 QQ:67828115
本文部分文字和图片来源于互联网,如有侵犯您的权利请发送内容至:173323810@qq.com,我们将立即删除!