Compilation language writing method and program analysis

xiaoxiao2021-03-06  95

Compilation language writing method and program analysis

1. Compilation language program writing method

(1) The assembly language source program is. SASM to extension.

(2) Each line of the assembly language source program can be composed of 4 parts, the syntax is as follows:

[Number] [:] Help Number [Operation] [; Note]

Among them, spaces or TABS keys can be separated

Number - Other parts or other programs for this program. The label is optional, and it can be added after the label can be added ":": " The label must be written from the first column, the label can reach up to 32 characters (A ~ Z, A ~ Z, 0 ~ 9, _, and $), but the first letter cannot begin with a number. When the reference mark, the number of labels must be consistent. The value of the label is the value of the SPC (Segment Program Counter). If not used, the first letter must be space, a semicolon or signal (*).

Help Missing - Help Requirements, Assembles, Macro, Macro. As a museum instruction, general writing; assembly command and macro, start with the end of the number "." And lowercase. The assembly command can form constants and variables, and when using it to control assembly and connection procedures, the storage space can be not occupied. The instructions and assembly commands cannot be written in column 1.

Operations - Operations in the command or content defined in the assembly command. A comma must be separated between operands. Some instructions operate without operation, such as NOP, RESET.

Note - Note From the semicolon ";", it can be placed behind the instruction or assembly command, or it can be placed separately or a row. Comments are optional. (If the comment starts from the first column, you can use "*".)

(3) The common assembly command is shown in Table.

The assembly command function example .TITLE follows the assembly language program body .title "eXample.asm" .End end assembly commands in the finals of the assembly language program. TEXT follows the assembly language program body after compilation , Followed by .Text is the executable program code. Data followed the initialized data has two data forms: .int and .word .int .int used to set one or more 16-bit unsigned whole Type constant table: .word 1, 2, 3, 4 .word 6, 8, 4, 2 .word. Word is used to set one or more 16-bit symbol integers, indicating that the program memory label begins The initialization data 1, 2, 3, 4, 6, 8, 4, and 2. BSS .BSS is stored in the uninitialized variable to retain storage space. BSS X, 4 indicates that the variable is empty in the data store. X1, X2, X3 and X4 .sect build a custom segment containing code and data. Sect "vectors" definition vector table, followed by the reset vector and interrupt vector, named vectors .usect is the uninitialized variable reserved storage Space Custom Section Stack .usect "stack", 10h left 16 units in the data store as a stack area, named Stack

(4) The data form in the assembly language program is shown in the table

Example of a binary 1110001B or 1111001B Octa 226Q or 572Q decimal 1234 or 1234 or -1234 (default) hexadecimal

0A

40h or

0A

40h or 0xA40 floating point 1.654E-23 (only in the C language program can be used in the assembler) characters 'D' string "this is a string" 2. Program

2.1 Program

Programmation Purpose: This program is the first program of the test, its main purpose is to understand the input and output methods of the DSP.

Program function: Search for the sum y = a1 * x1 a2 * x2 a3 * x3 a4 * x4

.title "Sample.asm"

.mmmregs; import mapping mapping register

Stack .usect "stack", 10h; assign space to the stack segment

.bss a, 4; assign 9 words to each variable

.bss x, 4

.bss y, 1

PA0 .SET 0

.def start

.data; The following is allocated data

Table: .word 4, 4, 4, 4

.word 4, 4, 4, 4

.Text; The following is data

START: STM # 0, SWWSR; will be waiting to be set to 0

STM # stack 10h, sp; set stack pointer

STM # a, AR1; point AR1 points to variables a

RPT # 7; Transfer 8 values ​​from program storage space to data storage space

MVPD TABLE, * AR1

Call Sum; call SUM subroutine

End: b end

SUM: STM # a, AR3; subroutine

STM # x, AR4

RPTZ A, # 3;

Mac * Ar3 , * AR4 , A

STL A, @ Y; deposit 16 bits in register A in Y address space

Portw @ Y, PA0; output the value in the Y address to the output port

Ret; subroutine return

.end;

Waiting for the setting:

One part of the 'C54X tablet-software programmable waiting state generator, controls the work of the external bus. Software programmable Waiting Status generator can extend the external bus cycle up to 7 cycles, so that 'C54x can easily connect with external slow device. If the external device requires more than 7 wait cycles, you can use the hardware Ready to first interface. When all external addressing are configured in the 0 waiting state, the clock applied to the waiting state generator is turned off; these channels from the internal clock are cut, and the power consumption of the processor can be reduced.

Software programmable Waiting Status generator work is controlled by a 16-bit Software Wait Status Register (SWSR), when a memory image register is 0028H in the data space. Both the program space and data space are divided into two 32K pieces, and the I / O space consists of a 64K block. These 5 block spaces have a 3-bit field in SWWSR, used to define the number of insertion of each space insertion:

15 14 ~ 12 11 ~ 9 8 ~ 6 5 ~ 3 2 ~ 0

Keep / XPA (only 'C548,' C549)

I / O space (64K)

Data space (high 32K)

Data space (low 32)

Program space (32 digits)

Program space (low 32)

R r R / w r / w r / w r / w r / w

The minimum number of inserted wager states specified in the above SWWSR is 0 (not inserted in the waiting period), the maximum number is 7 (111b).

2.2 Procedure 2

Programming Purpose: Familiar with DSP assembler design techniques, improve output

Program function: Implementing a 8-digit LED bulb flashing from left to right loop

.title "bubble.asm"

.mmmregs

Stack .usect "stack", 5h

.bss y, 1

.def start

.DATA

PA0 .SET 0

.Text

START: STM # 7000, SWWSR; set-like standby

STM # 2, AR3; set the auxiliary register AR3 to 2 (multiply 2, realize left shift)

STM # 6, AR1; set the auxiliary register AR1 to 6 (left shift 7 times)

STM # 3, AR2; set the auxiliary register AR2 to 3 (4 times in loop)

LD AR3, T; set T (multiplication register) to 2

LOOP1: LD # 1, A; A register value is 1

STL A, @ y; y = 1

Portw @ y, pa0; output value to the output port in the Y address

STM # 10000, AR4; set the auxiliary register AR4 to 10000

LOOP3: RPT # 10000; Repeat the next program 10001 times

NOP; wait

Banz Loop3, * AR4-; Circulating AR4 value (10000) 1 times

Loop2: MPY @ Y, A; Deposit Y × T, its value is stored in A register

STL A, @ y; deposit a value in the Y address Portw @ y, pa0; output Y address value to the output port

STM # 10000, AR5; set the auxiliary register AR5 to 10000

LOOP4: RPT # 10000; Time delay in achieving the eighth lamp jump to the first light

NOP

Banz loop4, * Ar5-

Banz loop2, * ar1-

Banz loop1, * ar2-

End: b end

.end .end

Data addressing method:

The 'C54X has a total of 7 data addressing methods, as shown in the table:

Addressing method

use

Example

Instruction meaning

Immediately address

Mainly used for initialization

LD # 10, A

Transfer immediately 10 to the accumulator a

Absolute addressing

Use 16-digit address to address storage unit

STL A, * (Y)

Put the lower 16-bit in the accumulator A to the storage unit where the variable Y is located

Cumulator Addressing

Use the contents of the accumulator as the address

Readya X

Press the accumulator A as an address read program memory and stores the data memory unit where the variable X is located.

Direct address

Using data page pointer and stack pointer addresses

LD @ x, a

(DP X low 7-bit address) - a

Indirect addressing

Using the auxiliary register as the address pointer

LD * AR1, A

((AR1)) - A

Memory Image Register Addressing

Quick Addressing Memory Image Register

LDM ST1, B

(ST1) - B

Stack addressing

Press / pop-up data memory and MMR (Memory Image Register)

PSHM AG

(SP) -1 - SP, (AG) - TOS

The 'C54x address memory has two basic data forms: 16-digit and 32 digits. Most instructions can address 16 digits, but only double precision and long word instructions can address 32 digits.

When 32-bit addressing, processes high valid words before processing low valid words. If the first word addressing is in the eldest address, then the second word is in the next (higher) address; if the first words are in the odd address, then the second word is in the previous one ( Lower) address.

Cycle operation: Banz

When the program is designed, you often need to repeat some of the programs. It is very convenient to perform cycle technology and operations using BANZ (when the auxiliary register site 0 is transferred) instructions. If you want to execute n times, the count value should be N-1 in the repetition instruction.

Repeat:

The 'C54x has three repetitive operation instructions: RPT (Repeat the following instructions), RPTZ (Cumulator Desk 0 and Repeat the following instructions) and RPTB (block repeat instruction).

Duplicate instructions RPT or RPTZ allows repeated execution of the instruction following subsequently. If you want to execute n times, the count value should be N-1 in the repetition instruction.

2.3 Procedures

Programming Purpose: Implement DSP Time Input and Output Function

Program function: First read a data from the I / O port and store it into an address, then output data from this address to I / O port

.title "dspio.asm"

.mmmregs

PA0 .SET 0

PA1 .SET 1

Stack .usect "stack", 10h

.bss y, 1

.Text

Start: PORTR PA1, @ y; reads data from the I / O port and stores the address LD @ Y, A in Y; writing the data in Y, in the accumulator A (facilitating the change of the value of Y)

Portw @ y, PA0 outputs the data in Y's address to I / O port;

End: b end

.end .end

2.4 Procedures

Programming purpose: implement DSP cyclic input and output function

Program function: Let the DSP repeatedly read data from the input device, and store the data into an address, and output data to the output device from the address.

.title "dspio2.asm"

.mmmregs

PA0 .SET 0

PA1 .SET 1

Stack .usect "stack", 10h

.bss y, 1

.Text

Start: STM # 4000, AR1

LOOP1: PORTR PA1, @ y; loop reading and writing

LD @ y, a

Portw @ y, PA0

Banz Loop1, * AR1

End: b end

.end .end

2.5 procedures five

Programmation Purpose: Application DSP Realization of Accident Consequences

Programming Background: When the origin of large Loca occurs, the following functions need to be resolved to eliminate or relieve accidents:

(1) Pushing (RS), stop the nuclear fission process;

(2) Safety shell spray system to reduce safety shell pressure (COI);

(3) Inject emergency cooling water (ECI) to the core to cool the core;

(4) Safety shell recirculation cooling (COR), exports heat of the safety shell, controlling the temperature nuclear pressure of the safety shell;

(5) The core recirculation cooling (ECR) is subjected to the core recirculation cooling stage.

Functional incident tree diagram as shown below

Broken PB

Pile of critical rs

Safety shell antihypertensive COI

Forting emergency cooling ECI

Complete shell antihypertensive Cor

Carter recirculation cooling ECR

serial number

Whether the core is melted

Program function: Repeatedly read data from the input port (different functional responses, different function responses, respectively)

.title "loca.asm"

.mmmregs

PA0 .SET 0

PA1 .SET 1

Stack .usect "stack", 10h

.bss y, 1

.bss x, 1

.def start

.DATA

Table: .word 0, 128, 0, 128, 0, 32, 0, 32, 0, 128, 0; list of accident analysis

. Word 128, 0, 32, 0, 32, 0, 0, 0, 0

.word 4, 0, 4, 0, 0, 0, 0, 0, 4, 0

. Word 4, 0, 0, 0, 0, 0, 0, 0

. Word 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0

.word 2, 0, 2, 0, 0, 0, 0, 0, 0

. Word 0, 0, 0, 0, 0, 0, 0, 0

. Word 0, 0, 0, 0, 0, 0, 0, 0

. Word 0, 0, 0, 0, 0, 0, 0, 0

.word 16, 10, 16, 0, 0, 0, 0, 0, 16, 0

.word 16, 0, 0, 0, 0, 1, 0, 1, 0

.word 0, 0, 0, 0, 1, 0, 1, 0, 0

. Word 0, 0, 0, 0, 0, 0, 0, 0

. Word 0, 0, 0, 0, 0, 0, 0, 0

. Word 0, 0, 0, 0, 0, 0, 0, 0

. Word 0, 0, 0, 0, 0, 0, 0, 0

. Word 0, 0, 0, 0, 0, 0, 0, 0

. Word 0, 0, 0, 0, 0, 0, 0, 0

. Word 0, 0, 0, 0, 0, 0, 0, 0

. Word 0, 0, 0, 0, 0, 0, 0, 0

. Word 0, 0, 0, 0, 0, 0, 0, 0

. Word 0, 0, 0, 0, 0, 0, 0, 8, 0

. Word 8, 0, 0, 0, 0, 8, 0, 8, 0

.word 64, 0, 64, 0, 0, 0, 0, 0, 64, 0

.word 64, 0, 0, 0, 0, 0, 0, 0

.Text

START: STM # 1, AR1; set Ar1 1

STM # TABLE, AR2; pay the address of the label Table

Ar2

STM # 1, AR3; set Ar3 1

LOOP1: PORTR PA0, @ y; loop writes data from the input port

Y, the address is located

LD @ y, b; write the value in the Y address B

; Register (easy to see the value of Y)

LD @ Ar2, A; write Table address to A

Add @ y, a; putting the address of the table and reading

Data is added, and the result is deposited in A

STL A, @ Ar3; deposit a low 16 bits of AR3

Portw * Ar3, PA0; use AR3 as an address pointer addressed

And output the result to the output port

Banz Loop1, * AR1

End: b end

.end .end

转载请注明原文地址:https://www.9cbs.com/read-102557.html

New Post(0)