Bài giảng Vi xử lý - Chương 3: Vi điều khiển. Họ vi điều khiển 8051 (Phần 6)

Assembly Language Programming

Assembler Operation

Assembly Language Program Format

Assemble-Time Expression Evaluation

Assembler Directives

Assembler Controls

Linker Operation

Linking Relocatable Segments and Modules

Macros

 

ppt49 trang | Chuyên mục: Vi Xử Lý – Vi Điều Khiển | Chia sẻ: tuando | Lượt xem: 369 | Lượt tải: 0download
Tóm tắt nội dung Bài giảng Vi xử lý - Chương 3: Vi điều khiển. Họ vi điều khiển 8051 (Phần 6), để xem tài liệu hoàn chỉnh bạn click vào nút "TẢI VỀ" ở trên
data space)EPROM	SEGMENT	CODE (declares that EPROM is a code segment. To actually begin using this segment, the RSEG directive is used)2021/10/2416T. L. Jong, Dept. of E.E., NTHUSymbol Definition EQU and SET -- numberssymbol	EQU	expression (assigns a numeric	value to a specific symbol name)	N27	EQU	27	HERE	EQU	$	MESSAGE:	DB	‘This is a message’	LENGTH	EQU	$-MESSAGEsymbol	SET	expression (similar to EQU except 	that symbol can be redefined 	later using another SET directive)2021/10/2417T. L. Jong, Dept. of E.E., NTHUSymbol Definition DATA, IDATA, XDATA, BIT, & CODE: assign addresses of the corresponding segment type to a symbol.e.g., 	 FLAG1	EQU	05H	FLAG2	BIT	05H 	SETB	FLAG1	SETB	FLAG2	MOV	FLAG1,#0	MOV	FLAG2,#0(error message: data segment address expected)2021/10/2418T. L. Jong, Dept. of E.E., NTHUStorage Initialization/Reservation DS (define storage)[label:]	DS	expression (reserves spaces in byte units, 	can be used in any segment type 	except BIT)	DSEG	AT 30H	;put in data segment 	;(absolute , internal)LENGTH	EQU	40BUFFER:	DS	LENGTH	;reserve 40 bytes	MOV	R7,#LENGTH	MOV	R0,#BUFFER	;R0=30HLOOP:	MOV	@R0,#0	INC 	R0	DJNZ	R7,LOOP2021/10/2419T. L. Jong, Dept. of E.E., NTHUStorage Initialization/Reservation Create 1000 bytes in external RAM at 4000HXSTART	EQU	4000HXLENGTH	EQU	1000 	XSEG	AT XSTART	;put I data segment 	;(absolute , internal)XBUFFER:	DS	XLENGTH	;reserve 40 bytes	MOV	DPTR,#XBUFFERLOOP:	CLR	A	MOV	@DPTR,A	INC	DPTR	MOV	A,DPL	CJNE	A,#LOW(XBUFFER + XLENGTH + 1),LOOP	MOV	A,DPH	CJNE	A,#HIGH(XBUFFER + XLENGTH + 1),LOOP	(continue)2021/10/2420T. L. Jong, Dept. of E.E., NTHUStorage Initialization/Reservation DBIT: reserve space in bit units[label:]	DBIT	expression	BSEG	;bit segment, absolute (00H-7FH)KBFLAG:	DBIT	1	;keyboard statusPRFLAG:	DBIT	1	;printer statusDKFLAG:	DBIT	1	;disk statusDB (define byte): initialize code memory w bye values[label:]	DB	expression [,expression] []	CSEG	AT	0100HSQUARES:	DB	0,1,4,9,16,25	;squares of number 0-5MESSAGE:	DB	‘Login:’,0	;null-terminated char stringDW (define word)[label:]	DW	expression [,expression] []	CSEG	AT	0200H 	DW	$,’A’,1234H,2,’BC’	;02 00 00 41 12 34 00 	;02 42 432021/10/2421T. L. Jong, Dept. of E.E., NTHUProgram Linkage Allows separately assembled modules (files) to communicate by permitting intermodule referencing and naming of the modulesPUBLIC (declare public for other modules to reference) 	PUBLIC	symbol [,symbol] []allows the list of specified symbols to be known and used outside the currently assembled module.EXTRN (declare symbols defined outside current module)	EXTRN	symbol [,symbol] []EXTRN	CODE(HELLO,GOOD_BYE)CALL	HELLOCALL	GOOD_BYEEND	PUBLIC HELLO,GOOD_BYE	HELLO: (begin sub)	...	RETGOOD_BYE: (begin sub)		RETMAIN.SRCMESSAGE.SRC2021/10/2422T. L. Jong, Dept. of E.E., NTHUSegment Selection RSEG (selecting relocatable segment) 	RSEG	segment_namesegment_name is previously defined by SEGMENT directive.Selecting Absolute Segments	CSEG	[AT address]	DSEG	[AT address]	ISEG	[AT address]	BSEG	[AT address]	XSEG	[AT address]Each segment has its own location counter which is set to 0 initially2021/10/2423T. L. Jong, Dept. of E.E., NTHUSegment Selection LOC	OBJ	 LINE	SOURCE	 1	ONCHIP	SEGMENT	DATA	 2	EPROM	SEGMENT	CODE	 3----	 4	BSEG	AT 70H	;begin abs bit seg0070	 5	FLAG1:	DBIT	10071	 6	FLAG2	DBIT	1	 7----	 8	RSEG	ONCHIP	;begin relocatable data seg0000	 9	TOTAL:	DS	10001	 10	COUNT:	DS	10002	 11	SUM16:	DS	2	 12----	 13	RSEG	EPROM	;begin relocatable code seg0000 750000 F 	 14	BEGIN:	MOV	TOTAL,#0	 15	(continue program)	 16	END2021/10/2424T. L. Jong, Dept. of E.E., NTHUAssembler ControlsEstablish the format of the listing and object files. Controls the look of listing file, without having any effect on the program.Can be entered on the invocation line or placed in the source program (preceded with $)Primary controls and general controlse.g., DATE, INCLUDE, LIST, MACRO(50), XREF2021/10/2425T. L. Jong, Dept. of E.E., NTHUAssembler ControlsNAMEPrimary/GeneralDEFAULT Abbrev.MeaningDATE(date)PDATA()DAPlaces string in header (9 Char. max.) DEBUGPNODEBUGDBOutputs debug symbol information to object file NODEBUGPNODEBUGNODBSymbol information not placed in object file EJECTGNot applicableEJContinue listing on next page ERRORPRINTPNOERRORPRINTEPDesignates a file to receive error Messages in addition to the listing file (defaults to console) NOERRORPRINTPNOERRORPRINTNOEPDesignates that error messages will be printed in listing file onlyGENPGENONLYGOList only the fully expanded source as if all lines generated by a macro call were already in the source file2021/10/2426T. L. Jong, Dept. of E.E., NTHUAssembler ControlsGENONLYGGENONLYNOGEList only the original source text in the listing file INCLUDE(file)GNot applicableICDesignates a file to be included as part of the programLISTGNOLISTLIPrint subsequent lines of source code in listing fileNOLISTGNOLISTNOLIDo not print subsequent lines of source code in listing fileMACRO(mem_percent)PMACRO(50)MREvaluate and expand all macro calls. Allocate percentage of free memory for macro processingNOMACROPMACRO(50)NOMRDo not evaluate macro callsMOD51PMOD51MORecognize the 8051-specific predefined special function registersNOMOD51PMOD51NOMODo not recognize 8051-specific predefined special function registers 2021/10/2427T. L. Jong, Dept. of E.E., NTHUAssembler ControlsOBJECT(file)POBJECT(source.OBJ)OJDesignates file to receive object codeNOOBJECTPOBJECT(source.OBJ)NOOJDesignates that no object file will be createdPAGINGPPAGINGPIDesignates that listing file be broken into pages and each will have a headerNOPAGINGPPAGINGNOPIDesignates that listing file will contain no page breaksPAGELENGTHPPAGELENGTH(60)PLSets maximum number of lines in each page of listing file (range = 10 to 65,536)PAGEWIDTHPPAGEWIDTH(120)PWSets maximum number of characters in each line of listing file (range = 72 to 132)PRINT(file)PPRINT(source.LST)PRDesignates file to receive source listingNOPRINTPPRINT(source.LST)NOPRDesignates that no listing file will be created2021/10/2428T. L. Jong, Dept. of E.E., NTHUAssembler ControlsSAVEGNot applicableSAStores current control settings from SAVE stackRESTOREGNot applicableRSRestores control settings from SAVE stackREGISTERBANK(rb,..)PREGISTERBANK(0)RBIndicates one or more banks used in program moduleNOREGISTERBANKPREGISTERBANK(0)NORBIndicates that no register banks are usedSYMBOLSPSYMBOLSSBCreates a formatted table of all symbols used in programNOSYMBOLSPSYMBOLSNOSBDesignates that no symbol table is createdTITLE(string)GTITLE()TTPlaces a string in all subsequent page headers (max. 60 characters)WORKFILES(path)PSame as sourceWFDesignates alternate path for temporary workfiles2021/10/2429T. L. Jong, Dept. of E.E., NTHUAssembler ControlsXREFPNOXREFXRCreates a cross reference listing of all symbols used in programNOXREFPNOXREFNOXRDesignates that no cross reference list is created2021/10/2430T. L. Jong, Dept. of E.E., NTHULinker OperationsIntel RL51: links modules into an output file: RL51 input_list [TO output_file] [location_controls]	input_list: a list of relocatable object modules (files) separated by commas.	Output_file: the name of the output absolute object module (executable program).	Location controls: set start addresses for the named segments.e.g., RL51 MAIN.OBJ,MESSAGE.OBJ, SUBROUTINE.OBJ TO EXAMPLE & CODE (EPROM(4000H)) DATA(ONCHIP(30H))2021/10/2431T. L. Jong, Dept. of E.E., NTHULinker Operations2021/10/2432T. L. Jong, Dept. of E.E., NTHUAnnotated Example: ECHO.LST2021/10/2433T. L. Jong, Dept. of E.E., NTHUAnnotated Example: ECHO.LST2021/10/2434T. L. Jong, Dept. of E.E., NTHUAnnotated Example: IO.LST2021/10/2435T. L. Jong, Dept. of E.E., NTHUAnnotated Example2021/10/2436T. L. Jong, Dept. of E.E., NTHUAnnotated Example2021/10/2437T. L. Jong, Dept. of E.E., NTHUAnnotated Example2021/10/2438T. L. Jong, Dept. of E.E., NTHUAnnotated Example: ECHO+IO2021/10/2439T. L. Jong, Dept. of E.E., NTHU2021/10/2440T. L. Jong, Dept. of E.E., NTHUMACROSMacro allows frequently used sections of code to be defined once using a simple mnemonic and used anywhere in the program by inserting the mnemonic.ASM51’s MPL: string replacement.%DEFINE (call_pattern) (macro_body)%DEFINE (PUSH_DPTR)	(PUSH DPH	 PUSH DPL)%PUSH_DPTR will be replaced by PUSH DPH and PUSH DPL two instructions in the .LST file2021/10/2441T. L. Jong, Dept. of E.E., NTHUAdvantages of Using MacrosMore readableThe source program is shorter and requires less typingUsing macros reduces bugsUsing macros frees the programmer from dealing with low-level details2021/10/2442T. L. Jong, Dept. of E.E., NTHUParameter Passing%DEFINE (macro_name(parameter_list)) 	(macro_body)%DEFINE (CMPA# (VALUE)) 	(CJNE A,#%VALUE, $ + 3	)%CMPA# (20H) = CJNE A,#20H,$+32021/10/2443T. L. Jong, Dept. of E.E., NTHUParameter PassingJUMP if A is greater than X:%DEFINE (macro_name(parameter_list)) 	(macro_body)%DEFINE (JGT(VALUE,LABEL)) 	(CJNE 	A,#%VALUE+1, $ + 3 ;	 JNC	%LABEL 	 ;JGT	)%JGT(‘Z’,GREATER_THAN)2021/10/2444T. L. Jong, Dept. of E.E., NTHULocal Labels%DEFINE (macro_name [(parameter_list)]) 	[LOCAL list_of_local_labels] 	(macro_body)%DEFINE (DEC_DPTR) LOCAL SKIP 	(DEC DPL 	 MOV A,DPL	 CJNE A,#0FFH,%SKIP	 DEC DPH %SKIP: )2021/10/2445T. L. Jong, Dept. of E.E., NTHULocal Labels%DEC_DPTR = 	 DEC DPL 	 MOV A,DPL	 CJNE A,#0FFH, SKIP00	 DEC DPH SKIP00:Side effect: A is used and changed2021/10/2446T. L. Jong, Dept. of E.E., NTHUPreserve A by Push-Pop%DEFINE (DEC_DPTR) LOCAL SKIP 	(PUSH A	 DEC DPL 	 MOV A,DPL	 CJNE A,#0FFH,%SKIP	 DEC DPH %SKIP: POP A	 )2021/10/2447T. L. Jong, Dept. of E.E., NTHURepeat Operations-- Built-in Macros%REPEAT (expression) (text)%REPEAT (100)	(NOP	)2021/10/2448T. L. Jong, Dept. of E.E., NTHUControl Flow OperationsConditional Assembly in ASM51: %IF (expression) THEN (balanced_text)	[ELSE (balanced_text)]INTERNAL	EQU	1	;1=8051 serial I/O drivers	.	;0=8251 serial I/O drivers	%IF (INTERNAL) THEN(INCHAR:	.	;8051 driver	.OUTCHR:	.	.	) ELSE(INCHAR:	.	;8251 driver	.OUTCHR:	.	.	)2021/10/2449T. L. Jong, Dept. of E.E., NTHU

File đính kèm:

  • pptbai_giang_vi_xu_ly_chuong_3_vi_dieu_khien_ho_vi_dieu_khien_8.ppt
Tài liệu liên quan