116
Evaluating and Programming the 29K RISC Family
cpneq gr116,gr117,0
jmpi lr0
constn gr96,65535
;test for s1[] end
;no match
; return –1
;here if s1[cnt]==s2[cnt]
;return if at string end
L5:
jmpfi gr116,lr0
const gr96,0
add lr3,lr3,1
jmp L2
add lr2,lr2,1
;next s2[] character
;for–loop
;next s1[] character
All of the code is contained in the body of the for–loop. A for–loop transition
consists of 10 instructions, a decrease of one compared to the Metaware code. How-
ever, LOAD instructions are now placed back–to–back, and loaded data is used im-
mediately. Additionally, the
normal
path through the for–loop contains an
additional
jump to label L5. This will increase the actual number of cycles required to execute a
single for–loop to more than 10 cycles. It is likely the Metaware produced code will
execute in a shorter time.
No register (previously
gr97
) is used to contain the
cnt
value. The pointers to the
passed strings,
lr2
and
lr3
, are advanced to point to the next character within the for–
loop. Delay slot instructions are productively filled and there are no unnecessary
jump instructions.
Lines 8 through 12 of the source code are only applied if the tested characters are
found not to match. Consequently, it is redundant to test if either string has reached
the termination character –– if one has, they both have. This optimization should
have been reflected in the source code. However, the GNU compiler has identified
that it need only test string
s1[]
for termination. This results in the elimination of 29K
instructions relating to later C code lines. For example, there is no code relating to the
if–statement on line 9. If an attempt is made to place a breakpoint on source line 9
using the GDB source level debugger, then no breakpoint will be installed. Other de-
buggers may give a warning message or place a breakpoint at the first line before or
after the requested source line.
Programmers familiar with
older generation
compilers applied to CISC code
generation will notice the increased complexity in associating 29K instructions to
source C statements –– even for the simple example shown. As procedures become
larger and more complex, code association become increasingly more difficult. The
quality of 29K code produced by the better compilers available, make it very difficult
to consistently (or frequently) produce better code via
hand crafting
29K instruc-
tions. Because of the difficulty of understanding the compiler generated code, it is
best to only incorporate hand–built code as separate procedures which comply with
the C language calling convention.
2.3.6 Linking Compiled Code
After application code modules have been compiled or assembled, they must be
linked together to form an executable file. There are three widely used linker tools: