| ||||||||
Technical Support Support Resources Product Information | A51: CONVERTING LEGACY 8051 ASSEMBLY CODE TO KEIL C51/A51Information in this article applies to:
QUESTIONHow do I convert my legacy code written for another assembler into Keil A51 assembly code ? ANSWERKeil gives a handy template found at C:\Keil\C51\ASM\Template.A51. So open a UV2 project and then choose View> Workbook mode. Then File>open> Browse C:\Keil\C51\asm\Template.a51 Then open your assembly file legacy.a51 Then Windows>title Vertically. template.a51 and the Legacy .a51 side by side . This view enables you to look at the template and change any of legacy .A51 to conform with the Keil A51 assembler. As always use the book feature to open the keil documentation to the Keil A51 Assembler and Utililites to look up specific directives and to see the Template.A51 example in full detail. The example below is just for illustration on differences you may find.
1) Add $NOMOD51 ; disable predefined 8051 registers
#include <reg52.h> // include CPU definition file (for example, 8052)
2) Comment out any TiTle Directive
3) Comment Out any $PAGELENGTH(58)
any $PAGEWIDTH(88)
any $XREF NOGEN
any $SYMBOLS
µVision will set these parameters Project>options "Target 1"> Listings>
4) Make Sure that the Public and External areas are properly sequenced.
5) Add ?STACK SEGMENT IDATA ; ?STACK goes into IDATA RAM.
RSEG ?STACK ; switch to ?STACK segment.
DS 5 ; reserve your stack space
; 5 bytes in this example.
Between new public area and segment declaration areas. This will put the STACK segment in the main module.
6) Then ensure that the main module is correctly vectored for reset
; Provide an LJMP to start at the reset address (address 0) in the main module.
; You may use this style for interrupt service routines.
;------------------------------------------------------------------------------
CSEG AT 0 ; absolute Segment at Address 0
LJMP start ; reset location (jump to start)
7) Then ensure Code Segment reservation
;------------------------------------------------------------------------------
; CODE SEGMENT--Reserves space in CODE ROM for assembler instructions.
;------------------------------------------------------------------------------
code_seg_name SEGMENT CODE
RSEG code_seg_name ; switch to this code segment
USING 0 ; state register_bank used
; for the following program code.
start: MOV SP,#?STACK-1 ; assign stack at beginning
;------------------------------------------------------------------------------
; INSERT YOUR ASSEMBLY PROGRAM HERE
This will be copied from your legacy.a51
8) Then after all the legacy.a51 assembly code routines add any Intterupt service routines.
an example the following ISR's.
;------------------------------------------------------------------------------
; To include an interrupt service routins, provide an LJMP to the ISR at the
; interrupt vector address.
;------------------------------------------------------------------------------
CSEG AT 0BH ; 0BH is address for Timer 0 interrupt
LJMP timer0int
;------------------------------------------------------------------------------
; Give each interrupt function its own code segment.
;------------------------------------------------------------------------------
int0_code_seg SEGMENT CODE ; segment for interrupt function
RSEG int0_code_seg ; switch to this code segment
USING 1 ; register bank for interrupt routine
timer0int: PUSH PSW
MOV PSW,#08H ; register bank 1
PUSH ACC
MOV R1,data_variable
MOV DPTR,#xdata_variable
MOVX A,@DPTR
ADD A,R1
MOV data_variable1,A
CLR A
ADD A,#0
MOV data_variable1+1,A
POP ACC
POP PSW
RETI
9) Then as always ensure that the END directive is used
;------------------------------------------------------------------------------
; The END directive is ALWAYS required.
;------------------------------------------------------------------------------
END ; End Of File
FORUM THREADSThe following Discussion Forum threads may provide information related to this topic. Last Reviewed: Thursday, September 22, 2005 | |||||||
| ||||||||