VXL-Ch03-8051-3.8 Lap trinh hop ngu_50 slides.PPT

50 9 0
VXL-Ch03-8051-3.8 Lap trinh hop ngu_50 slides.PPT

Đang tải... (xem toàn văn)

Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống

Thông tin tài liệu

Hardware Summary of 8051 1 CHƯƠNG 3 HỌ VI ĐiỀU KHIỂN 8051 ĐHBK Tp HCM Khoa Đ ĐT BMĐT GVPT Hồ Trung Mỹ Môn học Vi Xử Lý 2 3 8 Lập trình hợp ngữ Lập trình hợp ngữ – Hoạt động của trình biên dịch hợp ngữ[.]

ĐHBK Tp HCM-Khoa Đ-ĐT BMĐT GVPT: Hồ Trung Mỹ Môn học: Vi Xử Lý CHƯƠNG HỌ VI ĐiỀU KHIỂN 8051 3.8 Lập trình hợp ngữ Lập trình hợp ngữ – – – – – – – – Hoạt động trình biên dịch hợp ngữ Dạng chương trình hợp ngữ Định trị biểu thức lúc biên dịch hợp ngữ Các thị trình biên dịch hợp ngữ Các điều khiển trình biên dịch hợp ngữ Hoạt động trình liên kết Liên kết đoạn tái định vị module Các macro Giới thiệu • Cấu trúc thiết kế chương trình – – – – – Giới thiệu Các thuận lợi bất lợi lập trình [có] cấu trúc Ba cấu trúc: phát biểu, vòng lặp lựa chọn Cú pháp mã giả (pseudo code) Lập trình hợp ngữ • Các cơng cụ kỹ thuật để phát triển chương trình – Chu kỳ phát triển – Tích hợp kiểm chứng – Lệnh mơi trường Lập trình hợp ngữ PROGRAM.OBJ PROGRAM.SRC ASM51 PROGRAM.LST LIBRARY PROGRAM.ABS FILE1.OBJ FILE2.OBJ RL51 • Tập tin chương trình nguồn có asm/a51/src • Tập tin sau ghi ROM có abs/hex PROGRAM.MAP ASM(input_file) /*assemble source program in Minh họa hoạt động trình biên dịch hợp ngữ (1/3) input_file)*/ BEGIN /*pass 1: build the symbol table */ lc = 0; /*lc=location counter; default to 0*/ mnemonic = null; open input_file; WHILE (mnemonic != end) DO BEGIN get_line(); /*get line from input_file */ scan_line(); /*scan line & get label/symbol & mnemonic */ IF (label) THEN enter_into_symbol_table(label, lc); CASE mnemonic OF BEGIN null, comment, END: ; /*do nothing */ ORG: lc = operand_value; EQU: enter_in_symbol_table( symbol, operand_value); DB: WHILE (got_operand) DO increment_lc; /* increment number of bytes defined */ DS: lc = lc + operand_value; 1_byte_instruction: lc = lc + 1; 2_byte_instruction: lc = lc + 2; 3_byte_instruction: lc = lc + 3; END Minh họa hoạt động trình biên dịch hợp ngữ (2/3) /*pass 2: create the object program*/ rewind_input_file_pointer; lc = 0; mnemonic = null; open_output_file; WHILE (mnemonic != end) DO BEGIN get_line(); scan_line(); /* determine mnemonic op code and value(s) of operand(s)*/ /*Note: if symbols are used in operand field, their values are looked-up*/ /* in the symbol table created during pass */ CASE mnemonic OF BEGIN null, comment, EQU, END: ; /*do nothing */ ORG: lc = operand_value; DB: WHILE (operand) DO BEGIN put_in_objectfile(operand); lc = lc + 1; END /* increment number of bytes defined */ Minh họa hoạt động trình biên dịch hợp ngữ (3/3) DS: lc = lc + operand; 1_byte_instruction: put_in_objectfile(inst_code); 2_byte_instruction: put_in_objectfile(inst_code); put_in_objectfile(operand); 3_byte_instruction: put_in_objectfile(inst_code); put_in_objectfile(operand high-byte); put_in_objectfile(operand low-byte); lc = lc + size_of_instruction; END END close_input_file; close_output_file; END Dạng chương trình hợp ngữ • Chương trình hợp ngữ chứa: – – – – Các lệnh máy (ANL, MOV) Các thị trình biên dịch hợp ngữ (ORG, ) Các điều khiển trình biên dịch hợp ngữ ($TITLE) Các thích • Các dịng lệnh máy thị trình biên dịch hợp ngữ có dạng: [label:] Mnemonic [operand] [,operand] […] [;comment] ( [nhãn:] Từ gợi nhớ [tốn hạng] [, tốn hạng] […] [;chú thích]) Dạng chương trình hợp ngữ(2/7) Vùng nhãn (label) • Nhãn biểu diễn địa lệnh (hoặc liệu) theo sau • Thuật ngữ “nhãn" ln ln biểu diễn địa • Thuật ngữ “ký hiệu” (symbol) tổng qt • Nhãn kiểu ký hiệu nhận dạng cách để dấu hai chấm (:) cuối tên nhãn • Các ký hiệu giá trị hay thuộc tính gán thị EQU, SEGMENT, BIT, DATA, etc • Ký hiệu địa chỉ, số liệu, tên đoạn, cấu trúc khác tạo lập trình viên 10/81 Điều khiển trình biên dịch hợp ngữ (2/6) NAME Primary/ General DEFAULT Abbrev Meaning DATE(date) P DATA() DA Places string in header (9 Char max.) DEBUG P NODEBUG DB Outputs debug symbol information to object file NODEBUG P NODEBUG NODB Symbol information not placed in object file EJECT G Not applicable EJ Continue listing on next page ERRORPRINT P NOERRORPRINT EP Designates a file to receive error Messages in addition to the listing file (defaults to console) NOERRORPRINT P NOERRORPRINT NOEP Designates that error messages will be printed in listing file only GEN P GENONLY GO List only the fully expanded source as if all lines generated by a macro call were already in the source file 36 Điều khiển trình biên dịch hợp ngữ (3/6) GENONLY G GENONLY NOGE List only the original source text in the listing file INCLUDE(file) G Not applicable IC Designates a file to be included as part of the program LIST G NOLIST LI Print subsequent lines of source code in listing file NOLIST G NOLIST NOLI Do not print subsequent lines of source code in listing file MACRO(mem_percent ) P MACRO(50) MR Evaluate and expand all macro calls Allocate percentage of free memory for macro processing NOMACRO P MACRO(50) NOMR Do not evaluate macro calls MOD51 P MOD51 MO Recognize the 8051-specific predefined special function registers NOMOD51 P MOD51 NOMO Do not recognize 8051specific predefined special function registers 37 Điều khiển trình biên dịch hợp ngữ (4/6) OBJECT(file) P OBJECT(source.O BJ) OJ Designates file to receive object code NOOBJECT P OBJECT(source.O BJ) NOOJ Designates that no object file will be created PAGING P PAGING PI Designates that listing file be broken into pages and each will have a header NOPAGING P PAGING NOPI Designates that listing file will contain no page breaks PAGELENGTH P PAGELENGTH(60) PL Sets maximum number of lines in each page of listing file (range = 10 to 65,536) PAGEWIDTH P PAGEWIDTH(120) PW Sets maximum number of characters in each line of listing file (range = 72 to 132) PRINT(file) P PRINT(source.LST) PR Designates file to receive source listing NOPRINT P PRINT(source.LST) NOPR Designates that no listing file will be created 38 Điều khiển trình biên dịch hợp ngữ (5/6) SAVE G Not applicable SA Stores current control settings from SAVE stack RESTORE G Not applicable RS Restores control settings from SAVE stack REGISTERBANK(rb, ) P REGISTERBANK(0) RB Indicates one or more banks used in program module NOREGISTERBANK P REGISTERBANK(0) NORB Indicates that no register banks are used SYMBOLS P SYMBOLS SB Creates a formatted table of all symbols used in program NOSYMBOLS P SYMBOLS NOSB Designates that no symbol table is created TITLE(string) G TITLE() TT Places a string in all subsequent page headers (max 60 characters) WORKFILES(path) P Same as source WF Designates alternate path for temporary workfiles 39 Điều khiển trình biên dịch hợp ngữ (6/6) XREF P NOXREF XR Creates a cross reference listing of all symbols used in program NOXREF P NOXREF NOXR Designates that no cross reference list is created 40 Hoạt động trình liên kết (Linker ) • Intel RL51: liên kết module thành tập tin xuất: RL51 input_list [TO output_file] [location_controls] input_list: danh sách module (tập tin) đối tượng tái định vị cách dấu phẩy Output_file: tên module đối tượng xuất (chương trình thực thi được) Location controls: đặt địa bắt đầu cho đoạn có tên • TD: RL51 MAIN.OBJ,MESSAGE.OBJ, SUBROUTINE.OBJ TO EXAMPLE & CODE (EPROM(4000H)) DATA(ONCHIP(30H)) 41 Hoạt động trình liên kết (Linker ) (2/2) 42 MACRO • Macro cho phép đoạn mã thường dùng định nghĩa lần dùng từ gợi nhớ đơn giản dùng chỗ chương trình cách chèn từ gợi nhớ vào • ASM51’s MPL: thay chuỗi • %DEFINE (call_pattern) (macro_body) • %DEFINE (PUSH_DPTR) (PUSH DPH PUSH DPL) • %PUSH_DPTR thay lệnh PUSH DPH PUSH DPL tập tin.LST 43 Các thuận lợi việc dùng macro • • • • Dễ đọc Chương trình nguồn viết ngắn Dùng macro làm giảm lỗi Dùng macro làm cho người lập trình khơng cần biết chi tiết cấp thấp 44 Truyền tham số • %DEFINE (macro_name(parameter_list)) (macro_body) • %DEFINE (CMPA# (VALUE)) (CJNE A,#%VALUE, $ + ) • %CMPA# (20H) = CJNE A,#20H,$+3 45 Truyền tham số (2/2) • Nhảy A ≥ X: • %DEFINE (macro_name(parameter_list)) (macro_body) • %DEFINE (JGE(VALUE,LABEL)) (CJNE A,#%VALUE+1, $ + ; JNC %LABEL ;JGE ) • %JGE(‘Z’,GREATER_THAN) 46 Các nhãn cục • %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: ) • %DEC_DPTR = DEC DPL MOV A,DPL CJNE A,#0FFH, SKIP00 DEC DPH SKIP00: • Hiệu ứng lề: A bị sử dụng bị thay đổi 47 Bảo tồn A Push-Pop • %DEFINE (DEC_DPTR) LOCAL SKIP ( PUSH A DEC DPL MOV A,DPL CJNE A,#0FFH,%SKIP DEC DPH %SKIP: POP A ) 48 Lặp lại tác vụ– Macro có sẵn • %REPEAT (expression) (text) • TD: %REPEAT (100) (NOP) 49 Các tác vụ luồng điều khiển • Biên dịch theo điều kiện ASM51: • %IF (expression) THEN (balanced_text) [ELSE (balanced_text)] INTERNAL EQU ; = 8051 serial I/O drivers ; = 8251 serial I/O drivers %IF (INTERNAL) THEN ( INCHAR: ; 8051 driver OUTCHR: ) ELSE ( INCHAR: ; 8251 driver OUTCHR: ) 50

Ngày đăng: 20/04/2022, 11:19

Từ khóa liên quan

Mục lục

  • CHƯƠNG 3

  • Slide 2

  • Lập trình hợp ngữ

  • Giới thiệu

  • Slide 5

  • Slide 6

  • Slide 7

  • Slide 8

  • Dạng chương trình hợp ngữ

  • Dạng chương trình hợp ngữ(2/7)

  • Dạng chương trình hợp ngữ(3/7)

  • Dạng chương trình hợp ngữ(4/7)

  • Dạng chương trình hợp ngữ(5/7)

  • Dạng chương trình hợp ngữ(6/7)

  • Dạng chương trình hợp ngữ(7/7)

  • Định trị biểu thức lúc biên dịch hợp ngữ

  • Định trị biểu thức lúc biên dịch hợp ngữ (2/7)

  • Định trị biểu thức lúc biên dịch hợp ngữ (3/7)

  • Định trị biểu thức lúc biên dịch hợp ngữ (4/7)

  • Định trị biểu thức lúc biên dịch hợp ngữ (5/7)

Tài liệu cùng người dùng

Tài liệu liên quan