Cortex-M3 Assembly Language: Memory Access

Choose a study mode

Play Quiz
Study Flashcards
Spaced Repetition
Chat to Lesson

Podcast

Play an AI-generated podcast conversation about this lesson

Questions and Answers

Which of the following best describes the function of the LDR instruction in ARM assembly language?

  • Performs arithmetic operations on register values.
  • Stores data from a register to RAM.
  • Loads data from RAM to a register. (correct)
  • Moves data from one register to another.

What is the primary purpose of the STR instruction in ARM assembly?

  • To store data from a register into memory. (correct)
  • To define a string literal within the code.
  • To load data from memory into a register.
  • To perform a bitwise operation on a register.

The MOV instruction in ARM assembly always requires additional memory access instructions to retrieve data.

False (B)

In ARM assembly, what are the four fields typically found in a line of code, separated by spaces or tabs?

<p>Label, Opcode, Operands, Comments</p> Signup and view all the answers

In the ARM assembly instruction LDR R0, [R1, #4]!, the ! indicates a ______ addressing mode.

<p>pre-increment</p> Signup and view all the answers

Match each addressing mode with its description in ARM assembly:

<p>Immediate Addressing = The data itself is part of the instruction. Indexed Addressing = A register contains a pointer to the data's memory location. PC-Relative Addressing = Uses the program counter (PC) as a pointer to access data.</p> Signup and view all the answers

Which addressing mode involves the data being directly embedded within the instruction itself?

<p>Immediate Addressing (A)</p> Signup and view all the answers

In indexed addressing, the actual data is stored within the instruction itself.

<p>False (B)</p> Signup and view all the answers

Explain the role of a register in indexed addressing.

<p>The register contains a pointer (memory address) to the location of the data in memory.</p> Signup and view all the answers

In PC-relative addressing, the ______ register is used as a pointer.

<p>program counter</p> Signup and view all the answers

Which addressing mode is most suitable when the data's location is relative to the current instruction's address?

<p>PC-Relative Addressing (B)</p> Signup and view all the answers

Writing an initial value into a memory location and transferring data from one memory location to another are capabilities microcontrollers do not possess.

<p>False (B)</p> Signup and view all the answers

What is the purpose of comments in assembly language code?

<p>To explain the software's functionality and make the code more readable.</p> Signup and view all the answers

In the example assembly code, .global main declares the main label as ______.

<p>global</p> Signup and view all the answers

Referring to the optional modifiers for reading from/writing to memory; what does the H modifier signify?

<p>Unsigned 16-bit halfword (B)</p> Signup and view all the answers

With the SB optional modifier, values are zero-padded to 32 bits on load.

<p>False (B)</p> Signup and view all the answers

What does PC stand for in the context of PC-relative addressing mode?

<p>Program Counter</p> Signup and view all the answers

The instruction MOV R0, #0 will assign the value ______ to register R0.

<p>0</p> Signup and view all the answers

Which instruction is used to indefinitely loop the program execution in the provided sample ASSEMBLY program?

<p>B (D)</p> Signup and view all the answers

In general, Assembly language is considered a high-level programming language.

<p>False (B)</p> Signup and view all the answers

Flashcards

What does LDR do?

LDR is used to load data from RAM into a register

What does STR do?

STR is used to store data from a register into RAM.

What does MOV do?

MOV is used to move or copy data within the processor, without needing memory access.

What is immediate addressing?

Immediate addressing contains the data directly within the instruction.

Signup and view all the flashcards

What is indexed addressing?

Indexed addressing uses a register to hold a pointer to the memory location where the data resides.

Signup and view all the flashcards

What is PC-relative addressing?

PC-relative addressing is an indexed addressing mode that uses the Program Counter (PC) as the pointer.

Signup and view all the flashcards

Study Notes

  • These study notes cover accessing memories in Cortex-M3 and ARM assembly language.
  • The objective is to provide an overview of ARM instructions for reading from and writing to memory.

Assembly Language Syntax

  • Assembly language syntax has four fields: label, opcode, operands, and comments.
  • Fields are separated by spaces or tabs.
  • The label field is a unique name for each label.
  • The opcode field is the command to execute by the processor.
  • The operands field can be 0 to 4 values, separated by commas.
  • The comments field includes programmer explanations of the software.
  • Example: Func: MOV R0, #100 ; this sets R0 to 100

General Format of Assembly Program

  • The data memory section typically ranges from 0x20000000-0x20004FFF.
  • The program memory section typically ranges from 0x08000000-0x0801FFFF.
  • Key directives include .section .data for data, .section .text for code, .syntax unified, and .global main.

Reading and Writing to Memory

  • Microcontrollers write an initial value into a memory location (e.g., 0xAA to MEM[0x40]).
  • Microcontrollers transfer data from one memory location to another (e.g., from MEM[0x30] to MEM[0x40]).
  • Load data from RAM to a register using the LDR instruction.
    • Example: ldr r1, =0x20000000 (special form), ldr r0, [r1] (r0 = [0x20000000]).
  • Store data from a register to RAM using the STR instruction.
    • Example: str r0, [r1]// [0x20000000] = r0
  • Use the MOV instruction to get data from within the processor, without additional memory access instructions.
    • Example: mov r0, #0// r0 = 0, mov r1, r0// r1 = r0

Addressing Modes

  • Addressing mode specifies the memory location to write and read data.
  • There are three main types: Immediate Addressing, Indexed Addressing, and PC-Relative Addressing.

Immediate Addressing

  • The data is contained in the instruction.
    • Example: MOV R0, #100; R0 = 100, immediate addressing, which loads the value 100 directly into register R0.

Indexed Addressing

  • The data is in memory, and a register contains a pointer to the data.
    • Example: LDR R0, [R1]; R0 = word pointed to by R1.
  • Subtypes include with constant value, with register value, pre-increment, and post-increment.

PC-Relative Addressing

  • This is an indexed addressing mode using the PC (program counter) as the pointer.
    • Example: LDR R1, =Count; R1 points to variable Count. LDR R0, [R1] ; R0 = Count; pointed to by R1

Optional Modifiers

  • {type} indicates the data type, such as 32-bit word, unsigned 8-bit byte, signed 8-bit byte, unsigned 16-bit halfword, signed 16-bit halfword, and 64-bit data.
  • B: Unsigned 8-bit byte (0 to 255); zero-padded to 32 bits.
  • SB: Signed 8-bit byte (-128 to +127); sign-extended to 32 bits.
  • H: Unsigned 16-bit halfword (0 to 65535); zero-padded to 32 bits.
  • SH: Signed 16-bit halfword (-32768 to +32767); sign-extended to 32 bits.
  • D: 64-bit data utilizes two registers.

Activities

  • Use a simulator for assembly code (e.g., CPUlator) to write assembly programs.
  • Write a program to output a sequence to LEDs, reading values from data memory.
  • Write a program to swap the least and most significant 16-bits of a value (e.g., 0xCCFF3300) and display it on LEDs.

Studying That Suits You

Use AI to generate personalized quizzes and flashcards to suit your learning preferences.

Quiz Team

Related Documents

More Like This

Cortex Structures Quiz
3 questions
Introduction to Cortex-M Microcontroller
22 questions
Cortex cérébrale
127 questions

Cortex cérébrale

BeneficialTan2398 avatar
BeneficialTan2398
Cortex Moteur et Homonculus de Penfield
45 questions
Use Quizgecko on...
Browser
Browser