STM32F1 Programming Manual

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

Previous topic - Next topic

tha

Operation

คำสั่ง load และ store เหล่านี้ดำเนินการฟังชั่นเดียวกันกับ the memory access instructions with immediate offset (ดู LDR and STR, immediate offset บนหน้า 61). ข้อแตกต่างกันคือคำสั่งเหล่านี้มีเฉพาะ unprivileged access แม้ว่าเมื่อใช้ใน privileged software.

เมื่อถูกใช้ใน unprivileged software, คำสั่งเหล่านี้จะทำงานเหมือนกันกับ normal memory access instructions with immediate offset.

tha

Restrictions

ในคำสั่งเหล่านี้:
•   Rn ต้องไม่เป็น PC
•   Rm ต้องไม่เป็นทั้ง SP หรือ PC

Condition flags

คำสั่งเหล่านี้ไม่เปลี่ยนแปลง the flags.


tha

3.4.5 LDR, PC-relative

โหลด register จาก memory.

Syntax

LDR{type}{cond} Rt, label
LDRD{cond} Rt, Rt2, label; load two words

โดยที่:
•   'type' คือหนึ่งของต่อไปนี้:
     B: Unsigned byte, ศูนย์ขยายถึง 32 bits ในการ loads
     SB: Signed byte, sign ขยายถึง 32 bits (LDR เท่านั้น)
     H: Unsigned halfword, ศูนย์ขยายถึง 32 bits ในการ loads
     SH: Signed halfword, sign ขยายถึง 32 bits (LDR เท่านั้น)
     —: ละเว้น, สำหรับ word
•   'cond' คือ an optional condition code (ดู Conditional execution บนหน้า 56)
•   'Rt' คือ the register เพื่อ load หรือ store
•   'Rt2' คือ the second register เพื่อ load หรือ store
•   'label' คือ a PC-relative expression (ดู PC-relative expressions บนหน้า 56)

Operation

LDR โหลด a register ด้วยค่าจาก a PC-relative memory address. The memory address ถูกระบุโดย a label หรือโดย an offset จาก the PC.

The value เพื่อ load หรือ store สามารถเป็น a byte, halfword, or word. สำหรับ load instructions, bytes and halfwords  สามารถเป็นอย่างใดอย่างหนึ่ง signed หรือ unsigned (ดู Address alignment บนหน้า 55).

'label' ต้องอยู่ภายในช่วงที่จำกัดของ the current instruction. Table 26 แสดง the possible offsets ระหว่าง label และ the PC.

คุณอาจต้องใช้ the .W suffix เพื่อได้รับ the maximum offset range (ดู Instruction width selection บนหน้า 58).

Restrictions

ในคำสั่งเหล่านี้:
•   Rt สามารถเป็น SP หรือ PC สำหรับ word loads เท่านั้น
•   Rt2 ต้องไม่เป็นทั้ง SP หรือ PC
•   Rt ต้องแตกต่างจาก Rt2
เมื่อ Rt คือ PC ใน a word load instruction:
•   bit[0] ของ the loaded value ต้องเป็น 1 เพื่อการดำเนินการที่ถูกต้อง, และ a branch จะเกิดขึ้นกับ halfword-aligned address นี้
•   หากคำสั่งเป็นแบบมีเงื่อนไข มันต้องเป็นคำสั่งสุดท้ายใน the IT block

Condition flags

คำสั่งเหล่านี้ไม่เปลี่ยนแปลง the flags.

Examples


tha

3.4.6 LDM and STM

Load and store multiple registers.

Syntax

op{addr_mode}{cond} Rn{!}, reglist

โดยที่:
•   'op' คืออย่างใดอย่างหนึ่ง LDM (load multiple register) หรือ STM (store multiple register)
•   'addr_mode' คือใดๆของต่อไปนี้:
     IA: เพิ่ม address หลังจากแต่ละ access (นี้คือค่าเริ่มต้น)
     DB: ลด address ก่อนแต่ละ access
•   'cond' คือ an optional condition code (ดู Conditional execution บนหน้า 56)
•   'Rn' คือ the register ซึ่ง the memory address ตั้งฐานอยู่
•   '!' คือ an optional writeback suffix. ถ้ามี '!', the final address ที่ถูกโหลดจากหรือเก็บไปยังจะถูกเขียนกลับลงใน Rn.
•   'reglist' คือรายการของอย่างน้อยหนึ่ง registers ที่จะถูกโหลดหรือถูกเก็บ, โดยใส่ไว้ในวงเล็บปีกกา. มันสามารถบรรจุ register
     ranges. มันจะต้องคั่นด้วยเครื่องหมายจุลภาคหากมีมากกว่าหนึ่ง register หรือ register range (ดูตัวอย่างบนหน้า 68).

LDM and LDMFD เป็นคำพ้องความหมายสำหรับ LDMIA. LDMFD หมายถึงการใช้ของมันสำหรับการดึงข้อมูลจากสแต็กจากมากไปหาน้อยที่เต็ม.

LDMEA  เป็นคำพ้องความหมายสำหรับ LDMDB, และหมายถึงการใช้ของมันสำหรับการดึงข้อมูลจากสแต็กจากมากไปหาน้อยที่ว่างเปล่า.

STM and STMEA เป็นคำพ้องความหมายสำหรับ STMIA. STMEA และหมายถึงการใช้ของมันสำหรับการส่งข้อมูลไปยังสแต็กจากมากไปหาน้อยที่ว่างเปล่า.

STMFD เป็นคำพ้องความหมายสำหรับ STMDB, และหมายถึงการใช้ของมันสำหรับการส่งข้อมูลไปยังสแต็กจากมากไปหาน้อยที่เต็ม.

tha

Operation

LDM instructions โหลด the registers ใน reglist ด้วย word values จาก memory addresses ที่อ้างอิงจาก Rn.

STM instructions เก็บ the word values ใน the registers ใน reglist ไปยัง memory addresses ที่อ้างอิงจาก Rn.

For LDM, LDMIA, LDMFD, STM, STMIA, and STMEA the memory addresses ที่ใช้สำหรับการเข้าถึงจะอยู่ที่ช่วง 4-byte ตั้งแต่ Rn ถึง Rn + 4 * (n-1), โดยที่ n คือจำนวนของ registers ใน reglist. การเข้าถึงเกิดขึ้นตามลำดับของ increasing register numbers, โดยที่ the lowest numbered register จะใช้ the lowest memory address และ the highest number register จะใช้ the highest memory address. ถ้า the writeback suffix ถูกระบุ, ค่าของ Rn + 4 * (n-1) จะถูกเขียนกลับไปยัง Rn.

For LDMDB, LDMEA, STMDB, and STMFD the memory addresses ที่ใช้สำหรับการเข้าถึงจะอยู่ที่ช่วง 4-byte ตั้งแต่ Rn ถึง Rn - 4 * (n-1),  โดยที่ n คือจำนวนของ registers ใน reglist. การเข้าถึงเกิดขึ้นตามลำดับของ decreasing register numbers, โดยที่ the highest numbered register จะใช้ the highest memory address และ the lowest number register จะใช้ the lowest memory address. ถ้า the writeback suffix ถูกระบุ, ค่าของ Rn - 4 * (n-1) จะถูกเขียนกลับไปยัง Rn.

The PUSH and POP instructions สามารถถูกแสดงในรูปแบบนี้ (ดู PUSH and POP สำหรับรายละเอียด).

tha

Restrictions

ในคำสั่งเหล่านี้:
•   Rn ต้องไม่เป็น PC
•   reglist ต้องไม่บรรจุ SP
•   ในคำสั่ง STM ใดๆ, reglist ต้องไม่บรรจุ PC
•   ในคำสั่ง LDM ใดๆ, reglist ต้องไม่บรรจุ PC ถ้ามันบรรจุ LR
•   reglist ต้องไม่บรรจุ Rn ถ้าคุณระบุ the writeback suffix

เมื่อ PC คือ reglist ใน an LDM instruction:
•   bit[0] ของ the value ที่โหลดไปยัง the PC ต้องเป็น 1 เพื่อการดำเนินการที่ถูกต้อง, และ a branch จะเกิดขึ้นกับ halfword-
     aligned address นี้
•   หากคำสั่งเป็นแบบมีเงื่อนไข มันต้องเป็นคำสั่งสุดท้ายใน the IT block

Condition flags

คำสั่งเหล่านี้ไม่เปลี่ยนแปลง the flags.

Examples

       LDMR8,{R0,R2,R9}; LDMIA is a synonym for LDM
       STMDBR1!,{R3-R6,R11,R12}

Incorrect examples

       STMR5!,{R5,R4,R9}; value stored for R5 is unpredictable
       LDMR2, {}; there must be at least one register in the list

tha

3.4.7 PUSH and POP

Push registers ลงบน, และ pop registers จาก a full-descending stack.

Syntax

PUSH{cond} reglist
POP{cond} reglist

โดยที่:
•   'cond' คือ an optional condition code (ดู Conditional execution บนหน้า 56)
•   'reglist' คือรายการที่ไม่ว่างเปล่าของ registers, โดยใส่ไว้ในวงเล็บปีกกา. มันสามารถบรรจุ register ranges. มันจะต้องคั่นด้วย
     เครื่องหมายจุลภาคหากมันบรรจุมากกว่าหนึ่ง register หรือ register range (ดูตัวอย่างบนหน้า 68).

PUSH and POP เป็นคำพ้องความหมายสำหรับ  STMDB และ LDM (หรือ LDMIA) ที่มี the memory addresses สำหรับ the access อ้างอิงจาก SP, และที่มี the final address สำหรับ the access ถูกเขียนกลับไปยัง the SP. PUSH and POP เป็นคำช่วยจำที่ต้องการในกรณีเหล่านี้.

tha

Operation

PUSH เก็บ registers บน the stack ตามลำดับของ decreasing register numbers, โดยที่ the highest numbered register จะใช้ the highest memory address และ the lowest numbered register จะใช้ the lowest memory address.

POP โหลด registers จาก the stack ตามลำดับของ increasing register numbers, โดยที่ the lowest numbered register จะใช้ the lowest memory address และ the highest numbered register จะใช้ the highest memory address.

ดู LDM and STM บนหน้า 67 สำหรับข้อมูลเพิ่มเติม.