本帖最后由 laoxu 于 2016-6-12 14:36 编辑
随便写了一个 long 的加法程序,是否比原编译程序短小许多?
1. 用ChipON---IDE编译的汇编代码:
; .line 20; "../main.c" Lc = La + Lb;
000f30 6d03 SET 0x3, 5 BANKSEL r0x1000
000f31 508d MOV R0, 0x8d MOV R0, r0x1000
000f32 6d03 SET 0x3, 5 BANKSEL r0x1001
000f33 208e ADD R0, 0x8e ADD R0, r0x1001
000f34 6d03 SET 0x3, 5 BANKSEL r0x1006
000f35 5193 MOV 0x93, R0 MOV r0x1006, R0
000f36 6d03 SET 0x3, 5 BANKSEL r0x1003
000f37 5090 MOV R0, 0x90 MOV R0, r0x1003
000f38 6d03 SET 0x3, 5 BANKSEL r0x1007
000f39 5194 MOV 0x94, R0 MOV r0x1007, R0
000f3a 6d03 SET 0x3, 5 BANKSEL r0x1002
000f3b 0e8f MOVZ R0, 0x8f MOVZ R0, r0x1002
000f3c 7003 JNB 0x3, 0 JNB PSW, 0
000f3d ff10 INC R0 INC R0
000f3e 7203 JNB 0x3, 2 JNB PSW, 2
000f3f cf42 JMP #0xf42 JMP _00006_DS_
000f40 6d03 SET 0x3, 5 BANKSEL r0x1007
000f41 2194 ADD 0x94, R0 ADD r0x1007, R0
_00006_DS_
000f42 6d03 SET 0x3, 5 BANKSEL r0x1005
000f43 5091 MOV R0, 0x91 MOV R0, r0x1005
000f44 6d03 SET 0x3, 5 BANKSEL r0x1009
000f45 5195 MOV 0x95, R0 MOV r0x1009, R0
000f46 6d03 SET 0x3, 5 BANKSEL r0x100A
000f47 0e97 MOVZ R0, 0x97 MOVZ R0, r0x100A
000f48 7003 JNB 0x3, 0 JNB PSW, 0
000f49 ff10 INC R0 INC R0
000f4a 7203 JNB 0x3, 2 JNB PSW, 2
000f4b cf4e JMP #0xf4e JMP _00007_DS_
000f4c 6d03 SET 0x3, 5 BANKSEL r0x1009
000f4d 2195 ADD 0x95, R0 ADD r0x1009, R0
_00007_DS_
000f4e 6d03 SET 0x3, 5 BANKSEL r0x1004
000f4f 5092 MOV R0, 0x92 MOV R0, r0x1004
000f50 6d03 SET 0x3, 5 BANKSEL r0x1008
000f51 5196 MOV 0x96, R0 MOV r0x1008, R0
000f52 6d03 SET 0x3, 5 BANKSEL r0x100B
000f53 0e98 MOVZ R0, 0x98 MOVZ R0, r0x100B
000f54 7003 JNB 0x3, 0 JNB PSW, 0
000f55 ff10 INC R0 INC R0
000f56 7203 JNB 0x3, 2 JNB PSW, 2
000f57 cf5a JMP #0xf5a JMP _00008_DS_
000f58 6d03 SET 0x3, 5 BANKSEL r0x1008
000f59 2196 ADD 0x96, R0 ADD r0x1008, R0
; op : SEND
2. 通过R0~R7传送变量,写的汇编代码:
; Lc = La + Lb;
BANKSEL 切换页面La
MOV R4, La[0] ; [0]表示La最低位,[3]表示La最高位
MOV R5, La[1]
MOV R6, La[2]
MOV R7, La[3]
BANKSEL 切换页面Lb
MOV R0, Lb[0] ; [0]表示Lb最低位,[3]表示Lb最高位
MOV R1, Lb[1]
MOV R2, Lb[2]
MOV R3, Lb[3]
BANKSEL 切换页面PSW
ADD R4, R0 ; 个位数相加
MOV R0, PSW
AND R0, #1
ADD R5, R1 ; 十位数相加
MOV R1, PSW
ADD R5, R0 ; 加个位数进位
ORL R1, PSW
AND R1, #1
ADD R6, R2 ; 百位数相加
MOV R2, PSW
ADD R6, R1 ; 加十位数进位
ORL R2, PSW
AND R2, #1
ADD R7, R3 ; 千位数相加
ADD R7, R2 ; 加百位数进位
BANKSEL 切换页面Lc
MOV Lc[0], R4 ; [0]表示Lc最低位,[3]表示Lc最高位
MOV Lc[1], R5
MOV Lc[2], R6
MOV Lc[3], R7
|