STM32F1 Programming Manual

Started by tha, January 16, 2021, 06:11:52 AM

Previous topic - Next topic

tha

Restrictions

ในคำสั่งเหล่านี้:
•   Operand2 ต้องไม่เป็นทั้ง SP หรือ PC
•   Rd สามารถเป็น SP เฉพาะใน ADD และ SUB, และเฉพาะกับข้อจำกัดเพิ่มเติมต่อไปนี้:
     –   Rn ต้องเป็น SP ด้วย
     –   การเลื่อนใดๆใน operand2 ต้องถูกจำกัดถึงสูงสุดของสามบิตโดยใช้ LSL
•   Rn สามารถเป็น SP เฉพาะใน ADD และ SUB
•   Rd สามารถเป็น PC เฉพาะใน the ADD{cond} PC, PC, Rm instruction โดยที่:
     –   คุณต้องไม่ระบุ the S suffix
     –   Rm ต้องไม่เป็นทั้ง PC หรือ SP
     –   หากคำสั่งเป็นแบบมีเงื่อนไข มันต้องเป็นคำสั่งสุดท้ายใน the IT block
•   ด้วยข้อยกเว้นของ the ADD{cond} PC, PC, Rm instruction, Rn สามารถเป็น PC เฉพาะใน ADD and SUB,  และเฉพาะกับข้อ
     จำกัดเพิ่มเติมต่อไปนี้:
     –   คุณต้องไม่ระบุ the S suffix
     –   The second operand ต้องเป็น a constant ในช่วง 0 ถึง 4095

Note: 1 เมื่อใช้ the PC สำหรับการบวกหรือการลบ, bits[1:0] ของ the PC จะถูกปัดเศษเป็น b00 ก่อนดำเนินการ the calculation,
            กำหนด the base address สำหรับ the calculation word-aligned.
         2 ถ้าคุณต้องการสร้าง the address ของคำสั่ง, คุณต้องปรับ the constant ตามค่าของ the PC. Arm ขอแนะนำให้คุณใช้ the
            ADR instruction แทน ADD หรือ SUB ที่มี Rn เท่ากับ the PC, เนื่องจาก assembler ของคุณจะคำนวณ the correct
            constant สำหรับ the ADR instruction โดยอัตโนมัติ.


เมื่อ Rd คือ PC ใน the ADD{cond} PC, PC, Rm instruction:
•   bit[0] ของค่าที่เขียนไปยัง the PC จะถูกละเว้น
•   A branch เกิดขึ้นกับ the address ที่สร้างขึ้นโดยการบังคับ bit[0] ของค่านั้นเป็น 0

Condition flags

ถ้า S ถูกระบุ, คำสั่งเหล่านี้จะอัฟเดต the N, Z, C and V flags สอดคล้องกับ the result

Examples

       ADDR2, R1, R3
       SUBSR8, R6, #240; sets the flags on the result
       RSBR4, R4, #1280; subtracts contents of R4 from 1280
       ADCHIR11, R0, R3; only executed if C flag set and Z
                 ; flag clear

tha

Multiword arithmetic examples

Specific example 4: 64-bit addition แสดงสองคำสั่งที่บวก a 64-bit integer ที่บรรจุใน R2 and R3 กับ another 64-bit integer ที่บรรจุใน R0 and R1, และวาง the result ใน R4 and R5.

Specific example 4: 64-bit addition

       ADDSR4, R0, R2; add the least significant words
       ADCR5, R1, R3; add the most significant words with carry

Multiword values ไม่จำเป็นต้องใช้ registers ที่ต่อเนื่อง. Specific example 5: 96-bit subtraction แสดงคำสั่งที่ลบ a 96-bit integer บรรจุใน R9, R1, and R11 ออกจากอีกชุดหนึ่งที่บรรจุใน R6, R2, and R8. The example เก็บ the result ใน R6, R9, and R2.

Specific example 5: 96-bit subtraction

       SUBSR6, R6, R9; subtract the least significant words
       SBCSR9, R2, R1; subtract the middle words with carry
       SBCR2, R8, R11; subtract the most significant words with carry

tha

3.5.2 AND, ORR, EOR, BIC, and ORN

Logical AND, OR, exclusive OR, bit clear, and OR NOT.

Syntax

op{S}{cond} {Rd,} Rn, Operand2

โดยที่:
•   'op' คือหนึ่งของ:
     AND: Logical AND
     ORR: Logical OR or bit set
     EOR: Logical exclusive OR
     BIC: Logical AND NOT or bit clear
     ORN: Logical OR NOT
•   'S' คือ an optional suffix. ถ้า S ถูกระบุ, the condition code flags จะถูกอัฟเดตตามผลลัพธ์ของ the operation (ดู
     Conditional execution บนหน้า 56)
•   'cond' คือ an optional condition code (ดู Conditional execution บนหน้า 56)
•   'Rd' คือ the destination register.
•   'Rn' คือ the register ที่ถือ the first operand
•   'Operand2' คือ a flexible second operand (ดู Flexible second operand บนหน้า 51 สำหรับรายละเอียดของ the options).


tha

Operation

The AND, EOR, and ORR instructions ดำเนินการระดับบิต  AND, exclusive OR, and OR operations ต่อค่าใน Rn และ operand2.

The BIC instruction ดำเนินการ an AND operation ต่อ the bits ใน Rn ด้วยการกลับของบิทที่ตรงกันในค่าของ operand2.

The ORN instruction ดำเนินการ an OR operation ต่อ the bits ใน Rn ด้วยการกลับของบิทที่ตรงกันในค่าของ operand2.

tha

Restrictions

ห้ามใช้ทั้ง SP หรือ PC.

Condition flags

ถ้า S ถูกระบุ, คำสั่งเหล่านี้:
•   อัฟเดต the N and Z flags สอดคล้องกับ the result
•   สามารถอัฟเดต the C flag ในระหว่างการคำนวณของ operand2 (ดู Flexible second operand บนหน้า 51)
•   ไม่มีผลต่อ the V flag

Examples

       ANDR9, R2,#0xFF00
       ORREQR2, R0, R5
       ANDSR9, R8, #0x19
       EORSR7, R11, #0x18181818
       BICR0, R1, #0xab
       ORNR7, R11, R14, ROR #4
       ORNSR7, R11, R14, ASR #32

tha

3.5.3 ASR, LSL, LSR, ROR, and RRX

Arithmetic shift right, logical shift left, logical shift right, rotate right, and rotate right with extend.

Syntax

op{S}{cond} Rd, Rm, Rs
op{S}{cond} Rd, Rm, #n
RRX{S}{cond} Rd, Rm

โดยที่:
•   'op' คือหนึ่งของ:
     ASR: Arithmetic shift right
     LSL: Logical shift left
     LSR: Logical shift right
     ROR: Rotate right
•   'S' คือ an optional suffix. ถ้า S ถูกระบุ, the condition code flags จะถูกอัฟเดตตามผลลัพธ์ของ the operation (ดู
     Conditional execution บนหน้า 56)
•   'Rd' คือ the destination register.
•   'Rm' คือ the register ที่ถือ the value ที่จะถูกเลื่อน
•   'Rs' คือ the register ที่ถือ the shift length ที่จะใช้กับ the value Rm. เฉพาะ the least significant byte ถูกใช้และสามารถอยู่
     ในช่วง 0 ถึง 255.
•   'n' คือ the shift length. The range of shift lengths ขึ้นอยู่กับ the instruction ดังต่อไปนี้:
     ASR: Shift length from 1 to 32
     LSL: Shift length from 0 to 31
     LSR: Shift length from 1 to 32
     ROR: Shift length from 1 to 31

Note:  MOV{S}{cond} Rd, Rm เป็นไวยากรณ์ที่ต้องการสำหรับ LSL{S}{cond} Rd, Rm, #0.

tha

Operation

ASR, LSL, LSR, and ROR ย้าย the bits ใน the register Rm ไปทางซ้ายหรือทางขวาตามจำนวนตำแหน่งที่ระบุโดยค่าคงที่ n หรือ register Rs.

RRX ย้าย the bits ใน the register Rm ไปทางขวา 1.

ในคำสั่งทั้งหมดเหล่านี้, ผลลัพธ์จะถูกเขียนไปยัง Rd แต่ค่าใน register Rm ยังคงไม่เปลี่ยน สำหรับรายละเอียดเกี่ยวกับผลลัพธ์ที่ถูกสร้างขึ้นโดยคำสั่งต่างๆ (ดู Shift operations ในหน้า 52).

tha

Restrictions

ห้ามใช้ทั้ง SP หรือ PC.

Condition flags

ถ้า S ถูกระบุ:
•   คำสั่งเหล่านี้อัฟเดต the N and Z flags สอดคล้องกับ the result
•   The C flag ถูกอัฟเดตไปยังบิตสุดท้ายที่เลื่อนออก, ยกเว้นเมื่อ the shift length เป็น 0 (ดู Shift operations ในหน้า 52).

Examples

       ASRR7, R8, #9; arithmetic shift right by 9 bits
       LSLSR1, R2, #3; logical shift left by 3 bits with flag update
       LSRR4, R5, #6; logical shift right by 6 bits
       RORR4, R5, R6; rotate right by the value in the bottom byte of R6
       RRXR4, R5; rotate right with extend