This code will be so huge and slow.
Example 1:
Code: Select all
function calc(a : byte) : byte;
begin
Result := a * 2;
end;
;test.mpas,6 :: begin
;test.mpas,7 :: Result := a * 2;
0x002E 0x7801 MOV R0, #1
0x0030 0xE509 MOV A, FARG_calc_a
0x0032 0x08 INC R0
0x0033 0x8002 SJMP L_test_calc2
L_test_calc3:
0x0035 0xC3 CLR C
0x0036 0x33 RLC A
L_test_calc2:
0x0037 0xD8FC DJNZ R0, L_test_calc3
0x0039 0xF50A MOV calc_local_result, A
;test.mpas,8 :: end;
0x003B 0xA80A MOV R0, calc_local_result
0x003D 0x22 RET
Code: Select all
MOV A, FARG_calc_a
ADD A,ACC
MOV R0,A
RET
Code: Select all
function calc(a : byte) : byte;
begin
Result := a shr 4;
end;
;test.mpas,6 :: begin
;test.mpas,7 :: Result := a shr 4;
0x002E 0x7804 MOV R0, #4
0x0030 0xE509 MOV A, FARG_calc_a
0x0032 0x08 INC R0
0x0033 0x8002 SJMP L_test_calc2
L_test_calc3:
0x0035 0xC3 CLR C
0x0036 0x13 RRC A
L_test_calc2:
0x0037 0xD8FC DJNZ R0, L_test_calc3
0x0039 0xF50A MOV calc_local_result, A
;test.mpas,8 :: end;
0x003B 0xA80A MOV R0, calc_local_result
0x003D 0x22 RET
Code: Select all
MOV A, FARG_calc_a
SWAP A
ANL A,#15
MOV R0,A
RET
Code: Select all
function calc : byte;
begin
Result := 1;
end;
;test.mpas,6 :: begin
;test.mpas,7 :: Result := 1;
0x002E 0x750901 MOV calc_local_result, #1
;test.mpas,8 :: end;
0x0031 0xA809 MOV R0, calc_local_result
0x0033 0x22 RET
The well-optimized code:
Code: Select all
MOV R0,#1
RET