一段算一个数组中最大最小值的子程序
1)
void MaxMin(U32 *max, U32 *min)
{
U8 i;
U32 _max;
U32 _min;
U32 d;
i=Settings[STABLE_TIME]-1;
_max=0;
_min=0xFFFFFFFF;
while(i!=0xFF)
{
d=Lux[i]; // 用一个临时变量代替Lux[i]
if(d>_max)_max=d;
if(d<_min)_min=d;
i--;
}
*max=_max;
*min=_min;
}
2)
void MaxMin(U32 *max, U32 *min)
{
U8 i;
U32 _max;
U32 _min;
i=Settings[STABLE_TIME]-1;
_max=0;
_min=0xFFFFFFFF;
while(i!=0xFF)
{
if(Lux[i]>_max)_max=Lux[i]; // 直接用Lux[i]
if(Lux[i]<_min)_min=Lux[i];
i--;
}
*max=_max;
*min=_min;
}
在XC8 pro V1.32中编译, 1)比2)小59个word
但是同样程序放在AVRstudio里面(GCC),编译出来,1)和2)是一样的。
友情提示: 此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。
对比lst文件,真的不一样
1)程序空间0650-068F,用64 words
- 9592 ;TaskLight.c: 57: d=*lptr++;
- 9593 0650 0820 movf MaxMin@lptr,w
- 9594 0651 0086 movwf 6
- 9595 0652 0821 movf MaxMin@lptr+1,w
- 9596 0653 0087 movwf 7
- 9597 0654 3F40 moviw [0]fsr1
- 9598 0655 00AC movwf MaxMin@d
- 9599 0656 3F41 moviw [1]fsr1
- 9600 0657 00AD movwf MaxMin@d+1
- 9601 0658 3F42 moviw [2]fsr1
- 9602 0659 00AE movwf MaxMin@d+2
- 9603 065A 3F43 moviw [3]fsr1
- 9604 065B 00AF movwf MaxMin@d+3
- 9605 065C 3004 movlw 4
- 9606 065D 07A0 addwf MaxMin@lptr,f
- 9607 065E 1803 skipnc
- 9608 065F 0AA1 incf MaxMin@lptr+1,f
- 9609
- 9610 ;TaskLight.c: 58: if(d>_max)_max=d;
- 9611 0660 082F movf MaxMin@d+3,w
- 9612 0661 0227 subwf MaxMin@_max+3,w
- 9613 0662 1D03 skipz
- 9614 0663 2E6E goto u4255
- 9615 0664 082E movf MaxMin@d+2,w
- 9616 0665 0226 subwf MaxMin@_max+2,w
- 9617 0666 1D03 skipz
- 9618 0667 2E6E goto u4255
- 9619 0668 082D movf MaxMin@d+1,w
- 9620 0669 0225 subwf MaxMin@_max+1,w
- 9621 066A 1D03 skipz
- 9622 066B 2E6E goto u4255
- 9623 066C 082C movf MaxMin@d,w
- 9624 066D 0224 subwf MaxMin@_max,w
- 9625 066E u4255:
- 9626 066E 1803 skipnc
- 9627 066F 2E78 goto l169
- 9628 0670 082F movf MaxMin@d+3,w
- 9629 0671 00A7 movwf MaxMin@_max+3
- 9630 0672 082E movf MaxMin@d+2,w
- 9631 0673 00A6 movwf MaxMin@_max+2
- 9632 0674 082D movf MaxMin@d+1,w
- 9633 0675 00A5 movwf MaxMin@_max+1
- 9634 0676 082C movf MaxMin@d,w
- 9635 0677 00A4 movwf MaxMin@_max
- 9636 0678 l169:
- 9637
- 9638 ;TaskLight.c: 59: if(d<_min)_min=d;
- 9639 0678 082B movf MaxMin@_min+3,w
- 9640 0679 022F subwf MaxMin@d+3,w
- 9641 067A 1D03 skipz
- 9642 067B 2E86 goto u4265
- 9643 067C 082A movf MaxMin@_min+2,w
- 9644 067D 022E subwf MaxMin@d+2,w
- 9645 067E 1D03 skipz
- 9646 067F 2E86 goto u4265
- 9647 0680 0829 movf MaxMin@_min+1,w
- 9648 0681 022D subwf MaxMin@d+1,w
- 9649 0682 1D03 skipz
- 9650 0683 2E86 goto u4265
- 9651 0684 0828 movf MaxMin@_min,w
- 9652 0685 022C subwf MaxMin@d,w
- 9653 0686 u4265:
- 9654 0686 1803 skipnc
- 9655 0687 2E90 goto l4120
- 9656 0688 082F movf MaxMin@d+3,w
- 9657 0689 00AB movwf MaxMin@_min+3
- 9658 068A 082E movf MaxMin@d+2,w
- 9659 068B 00AA movwf MaxMin@_min+2
- 9660 068C 082D movf MaxMin@d+1,w
- 9661 068D 00A9 movwf MaxMin@_min+1
- 9662 068E 082C movf MaxMin@d,w
- 9663 068F 00A8 movwf MaxMin@_min
- 9664 0690 l4120:
复制代码2)程序空间064D-06CB,用127 words
- 9583 ;TaskLight.c: 60: if(Lux[i]>_max)_max=Lux[i];
- 9584 064D 0831 movf MaxMin@i,w
- 9585 064E 00A0 movwf ??_MaxMin
- 9586 064F 3023 movlw 35
- 9587 0650 01A1 clrf ??_MaxMin+1
- 9588 0651 35A0 lslf ??_MaxMin,f
- 9589 0652 0DA1 rlf ??_MaxMin+1,f
- 9590 0653 35A0 lslf ??_MaxMin,f
- 9591 0654 0DA1 rlf ??_MaxMin+1,f
- 9592 0655 01A2 clrf ??_MaxMin+2
- 9593 0656 00A3 movwf ??_MaxMin+3
- 9594 0657 0820 movf ??_MaxMin,w
- 9595 0658 0722 addwf ??_MaxMin+2,w
- 9596 0659 0086 movwf 6
- 9597 065A 0821 movf ??_MaxMin+1,w
- 9598 065B 3D23 addwfc ??_MaxMin+3,w
- 9599 065C 0087 movwf 7
- 9600 065D 3F40 moviw [0]fsr1
- 9601 065E 00A4 movwf ??_MaxMin+4
- 9602 065F 3F41 moviw [1]fsr1
- 9603 0660 00A5 movwf ??_MaxMin+5
- 9604 0661 3F42 moviw [2]fsr1
- 9605 0662 00A6 movwf ??_MaxMin+6
- 9606 0663 3F43 moviw [3]fsr1
- 9607 0664 00A7 movwf ??_MaxMin+7
- 9608 0665 022C subwf MaxMin@_max+3,w
- 9609 0666 1D03 skipz
- 9610 0667 2E72 goto u4255
- 9611 0668 0826 movf ??_MaxMin+6,w
- 9612 0669 022B subwf MaxMin@_max+2,w
- 9613 066A 1D03 skipz
- 9614 066B 2E72 goto u4255
- 9615 066C 0825 movf ??_MaxMin+5,w
- 9616 066D 022A subwf MaxMin@_max+1,w
- 9617 066E 1D03 skipz
- 9618 066F 2E72 goto u4255
- 9619 0670 0824 movf ??_MaxMin+4,w
- 9620 0671 0229 subwf MaxMin@_max,w
- 9621 0672 u4255:
- 9622 0672 0831 movf MaxMin@i,w
- 9623 0673 00A0 movwf ??_MaxMin
- 9624 0674 3023 movlw 35
- 9625 0675 01A1 clrf ??_MaxMin+1
- 9626 0676 1803 skipnc
- 9627 0677 2E90 goto L2
- 9628 0678 35A0 lslf ??_MaxMin,f
- 9629 0679 0DA1 rlf ??_MaxMin+1,f
- 9630 067A 35A0 lslf ??_MaxMin,f
- 9631 067B 0DA1 rlf ??_MaxMin+1,f
- 9632 067C 01A2 clrf ??_MaxMin+2
- 9633 067D 00A3 movwf ??_MaxMin+3
- 9634 067E 0820 movf ??_MaxMin,w
- 9635 067F 0722 addwf ??_MaxMin+2,w
- 9636 0680 0086 movwf 6
- 9637 0681 0821 movf ??_MaxMin+1,w
- 9638 0682 3D23 addwfc ??_MaxMin+3,w
- 9639 0683 0087 movwf 7
- 9640 0684 3F40 moviw [0]fsr1
- 9641 0685 00A9 movwf MaxMin@_max
- 9642 0686 3F41 moviw [1]fsr1
- 9643 0687 00AA movwf MaxMin@_max+1
- 9644 0688 3F42 moviw [2]fsr1
- 9645 0689 00AB movwf MaxMin@_max+2
- 9646 068A 3F43 moviw [3]fsr1
- 9647 068B 00AC movwf MaxMin@_max+3
- 9648
- 9649 ;TaskLight.c: 61: if(Lux[i]<_min)_min=Lux[i];
- 9650 068C 0831 movf MaxMin@i,w
- 9651 068D 00A0 movwf ??_MaxMin
- 9652 068E 3023 movlw 35
- 9653 068F 01A1 clrf ??_MaxMin+1
- 9654 0690 L2:
- 9655 0690 35A0 lslf ??_MaxMin,f
- 9656 0691 0DA1 rlf ??_MaxMin+1,f
- 9657 0692 35A0 lslf ??_MaxMin,f
- 9658 0693 0DA1 rlf ??_MaxMin+1,f
- 9659 0694 01A2 clrf ??_MaxMin+2
- 9660 0695 00A3 movwf ??_MaxMin+3
- 9661 0696 0820 movf ??_MaxMin,w
- 9662 0697 0722 addwf ??_MaxMin+2,w
- 9663 0698 0086 movwf 6
- 9664 0699 0821 movf ??_MaxMin+1,w
- 9665 069A 3D23 addwfc ??_MaxMin+3,w
- 9666 069B 0087 movwf 7
- 9667 069C 3F40 moviw [0]fsr1
- 9668 069D 00A4 movwf ??_MaxMin+4
- 9669 069E 3F41 moviw [1]fsr1
- 9670 069F 00A5 movwf ??_MaxMin+5
- 9671 06A0 3F42 moviw [2]fsr1
- 9672 06A1 00A6 movwf ??_MaxMin+6
- 9673 06A2 3F43 moviw [3]fsr1
- 9674 06A3 00A7 movwf ??_MaxMin+7
- 9675 06A4 0830 movf MaxMin@_min+3,w
- 9676 06A5 0227 subwf ??_MaxMin+7,w
- 9677 06A6 1D03 skipz
- 9678 06A7 2EB2 goto u4265
- 9679 06A8 082F movf MaxMin@_min+2,w
- 9680 06A9 0226 subwf ??_MaxMin+6,w
- 9681 06AA 1D03 skipz
- 9682 06AB 2EB2 goto u4265
- 9683 06AC 082E movf MaxMin@_min+1,w
- 9684 06AD 0225 subwf ??_MaxMin+5,w
- 9685 06AE 1D03 skipz
- 9686 06AF 2EB2 goto u4265
- 9687 06B0 082D movf MaxMin@_min,w
- 9688 06B1 0224 subwf ??_MaxMin+4,w
- 9689 06B2 u4265:
- 9690 06B2 1803 skipnc
- 9691 06B3 2ECC goto l4108
- 9692 06B4 0831 movf MaxMin@i,w
- 9693 06B5 00A0 movwf ??_MaxMin
- 9694 06B6 3023 movlw 35
- 9695 06B7 01A1 clrf ??_MaxMin+1
- 9696 06B8 35A0 lslf ??_MaxMin,f
- 9697 06B9 0DA1 rlf ??_MaxMin+1,f
- 9698 06BA 35A0 lslf ??_MaxMin,f
- 9699 06BB 0DA1 rlf ??_MaxMin+1,f
- 9700 06BC 01A2 clrf ??_MaxMin+2
- 9701 06BD 00A3 movwf ??_MaxMin+3
- 9702 06BE 0820 movf ??_MaxMin,w
- 9703 06BF 0722 addwf ??_MaxMin+2,w
- 9704 06C0 0086 movwf 6
- 9705 06C1 0821 movf ??_MaxMin+1,w
- 9706 06C2 3D23 addwfc ??_MaxMin+3,w
- 9707 06C3 0087 movwf 7
- 9708 06C4 3F40 moviw [0]fsr1
- 9709 06C5 00AD movwf MaxMin@_min
- 9710 06C6 3F41 moviw [1]fsr1
- 9711 06C7 00AE movwf MaxMin@_min+1
- 9712 06C8 3F42 moviw [2]fsr1
- 9713 06C9 00AF movwf MaxMin@_min+2
- 9714 06CA 3F43 moviw [3]fsr1
- 9715 06CB 00B0 movwf MaxMin@_min+3
- 9716 06CC l4108:
复制代码一周热门 更多>