论坛里面看到了个函数,拷贝下来编译了下:
原函数:
#define uint8 unsigned char
#define uint unsigned int
void Adjust(uint val)
{
uint8 temp1,temp2,temp3,temp4,temp5;
while(val>=10000)
{
val =val- 10000;
temp1++;
}
while(val>=1000)
{
val =val-1000;
temp2++;
}
while(val>=100)
{
val -= 100;
temp3++;
}
while(val>=10)
{
val =val- 10;
temp4++;
}
temp5 = val;
}
void main()
{
while(1)
{
Adjust(65500);
}
}
编译后发现RAM占了14个字节,寄存器只用了R6,R7,然后5个局部变量用了5个固定地址RAM字节,请教下各位怎么让那些局部变量在寄存器还有的用的情况下分配到寄存器中去呢?
汇编代码如下:
; FUNCTION _Adjust (BEGIN)
; SOURCE LINE # 45
;---- Variable 'val' assigned to Register 'R6/R7' ----
; SOURCE LINE # 46
0000 ?C0001:
; SOURCE LINE # 48
0000 C3 CLR C
0001 EF MOV A,R7
0002 9410 SUBB A,#010H
0004 EE MOV A,R6
0005 9427 SUBB A,#027H
0007 400C JC ?C0003
; SOURCE LINE # 49
; SOURCE LINE # 50
0009 74F0 MOV A,#0F0H
000B 2F ADD A,R7
000C FF MOV R7,A
000D 74D8 MOV A,#0D8H
000F 3E ADDC A,R6
0010 FE MOV R6,A
; SOURCE LINE # 51
0011 0500 R INC temp1
; SOURCE LINE # 52
0013 80EB SJMP ?C0001
0015 ?C0003:
; SOURCE LINE # 54
0015 C3 CLR C
0016 EF MOV A,R7
0017 94E8 SUBB A,#0E8H
0019 EE MOV A,R6
001A 9403 SUBB A,#03H
001C 400C JC ?C0005
; SOURCE LINE # 55
; SOURCE LINE # 56
001E 7418 MOV A,#018H
0020 2F ADD A,R7
0021 FF MOV R7,A
0022 74FC MOV A,#0FCH
0024 3E ADDC A,R6
0025 FE MOV R6,A
; SOURCE LINE # 57
0026 0500 R INC temp2
; SOURCE LINE # 58
0028 80EB SJMP ?C0003
002A ?C0005:
; SOURCE LINE # 60
002A C3 CLR C
002B EF MOV A,R7
002C 9464 SUBB A,#064H
002E EE MOV A,R6
002F 9400 SUBB A,#00H
0031 400C JC ?C0007
; SOURCE LINE # 61
; SOURCE LINE # 62
0033 749C MOV A,#09CH
0035 2F ADD A,R7
0036 FF MOV R7,A
0037 74FF MOV A,#0FFH
0039 3E ADDC A,R6
C51 COMPILER V9.00 GLOB 11/16/2010 13:00:55 PAGE 4
003A FE MOV R6,A
; SOURCE LINE # 63
003B 0500 R INC temp3
; SOURCE LINE # 64
003D 80EB SJMP ?C0005
003F ?C0007:
; SOURCE LINE # 66
003F C3 CLR C
0040 EF MOV A,R7
0041 940A SUBB A,#0AH
0043 EE MOV A,R6
0044 9400 SUBB A,#00H
0046 400C JC ?C0008
; SOURCE LINE # 67
; SOURCE LINE # 68
0048 74F6 MOV A,#0F6H
004A 2F ADD A,R7
004B FF MOV R7,A
004C 74FF MOV A,#0FFH
004E 3E ADDC A,R6
004F FE MOV R6,A
; SOURCE LINE # 69
0050 0500 R INC temp4
; SOURCE LINE # 70
0052 80EB SJMP ?C0007
0054 ?C0008:
; SOURCE LINE # 72
0054 8F00 R MOV temp5,R7
; SOURCE LINE # 73
0056 22 RET
; FUNCTION _Adjust (END)
; FUNCTION main (BEGIN)
; SOURCE LINE # 85
; SOURCE LINE # 86
0000 ?C0010:
; SOURCE LINE # 88
; SOURCE LINE # 89
; SOURCE LINE # 90
0000 7FDC MOV R7,#0DCH
0002 7EFF MOV R6,#0FFH
0004 120000 R LCALL _Adjust
; SOURCE LINE # 92
0007 80F7 SJMP ?C0010
; FUNCTION main (END) |