XA User Guide 9-6 3/24/97
Since the XA optimizes the timing of each instruction, there will be very little correspondence to
the original 80C51 timing for the same code prior to translation to the XA. If the exact timing of
a sequence of instructions is important to the application, the translated code must be altered,
perhaps by adding NOPs or delay loops, to provide the necessary timing.
To show how a simple 80C51 to XA source code translator might work, a subroutine was
extracted from a working 80C51 program and translated using the table at the end of this
document and the other rules presented here. The original 80C51 source code was:
;StepCal - Calculates a trip point value for motor movement based on
; a percent of pointer full scale (0 - 100%).
; Call with target value in A. Returns result in A and "StepResult".
StepCal: MOV Temp2,A ; Save step target for later use.
MOV B,#Steplow ; Get low byte of step increment.
MUL AB ; Multiply this by the step target.
MOV StepResult,B ; Save high byte as partial result.
MOV Temp1,A ; Save low byte to use for rounding.
MOV A,Temp2 ; Get back the step target.
MOV B,#StepHigh ; Get high byte of step increment,
MUL AB ; and multiply the two.
ADD A,StepResult ; Add the two partial results.
JNB Temp1.7,Exit ; Least significant byte > 80h?
INC A ; If so, round up the final result.
Exit: ADD A,#MotorBot ; Add in the 0 step displacement.
MOV StepResult,A ; Save final step target.
RET
The same code as translated for the XA is as follows:
;StepCal - Calculates a trip point value for motor movement based on
; a percent of pointer full scale (0 - 100%).
; Call with target value in A. Returns result in A and "StepResult".
StepCal: MOV Temp2,R4L ; Save step target for later use.
MOV R4H,#Steplow ; Get low byte of step increment.
MULU.b R4,R4H ; Multiply this by the step target.
MOV StepResult,R4H ; Save high byte as partial result.
MOV Temp1,R4L ; Save low byte to use for rounding.
MOV R4L,Temp2 ; Get back the step target.
MOV R4H,#StepHigh ; Get high byte of step increment,
MULU.b R4,R4H ; and multiply the two.
ADD R4L,StepResult ; Add the two partial results.
JNB Temp1.7,Exit ; Least significant byte > 80h?
ADDS R4L,#1 ; If so, round up the final result.
Exit: ADD R4L,#MotorBot ; Add in the 0 step displacement.
MOV StepResult,R4 ; Save final step target.
RET