Podcast
Questions and Answers
Which segment in an ELF file contains the binary machine code?
Which segment in an ELF file contains the binary machine code?
- RO segment
- Z segment
- text segment (correct)
- RW segment
Which of the following best describes the purpose of the Section Header Table in an ELF file?
Which of the following best describes the purpose of the Section Header Table in an ELF file?
- To define the entry point where program execution begins.
- To store environment variables used by the program during execution.
- To manage dynamic linking.
- To enable the compiler to locate the content of specific sections. (correct)
The RO segment in the ELF file typically contains:
The RO segment in the ELF file typically contains:
- The value of variables unalterable at runtime. (correct)
- Uninitialized variables.
- Variables that are statically allocated and modifiable.
- Variables that can be modified during runtime.
What is primarily stored in flash memory, and why is it stored there?
What is primarily stored in flash memory, and why is it stored there?
A 32-bit processor uses 32 bits for each memory address. What is the total addressable memory space?
A 32-bit processor uses 32 bits for each memory address. What is the total addressable memory space?
What is the primary advantage of using processor registers compared to accessing data memory?
What is the primary advantage of using processor registers compared to accessing data memory?
What type of data does the 'Z' segment hold in the ELF file?
What type of data does the 'Z' segment hold in the ELF file?
Which of the following best describes the concept of spatial locality in the context of data access?
Which of the following best describes the concept of spatial locality in the context of data access?
When a program is running, it is copied to primary memory, also known as:
When a program is running, it is copied to primary memory, also known as:
In the context of memory organization, if a memory location at address 0x080001B0
contains the byte value 0x70
, what does this indicate?
In the context of memory organization, if a memory location at address 0x080001B0
contains the byte value 0x70
, what does this indicate?
Why might a processor architecture limit the number of bits used to encode a register in a machine instruction?
Why might a processor architecture limit the number of bits used to encode a register in a machine instruction?
According to the register allocation rules, what should happen if the live ranges of two variables overlap?
According to the register allocation rules, what should happen if the live ranges of two variables overlap?
What is the primary function of the Stack Pointer (SP) register?
What is the primary function of the Stack Pointer (SP) register?
Which ARM Cortex-M processor architecture implements the ARMv7E-M architecture?
Which ARM Cortex-M processor architecture implements the ARMv7E-M architecture?
In the Cortex-M architecture, what memory address range typically corresponds to Flash memory?
In the Cortex-M architecture, what memory address range typically corresponds to Flash memory?
When a Cortex-M processor loads a program, where are initialized global variables primarily stored?
When a Cortex-M processor loads a program, where are initialized global variables primarily stored?
Which memory segment in a Cortex-M processor changes dynamically during runtime due to calls to malloc
or calloc
?
Which memory segment in a Cortex-M processor changes dynamically during runtime due to calls to malloc
or calloc
?
What is the primary characteristic of the stack in a Cortex-M processor?
What is the primary characteristic of the stack in a Cortex-M processor?
What is the main purpose of control registers in the peripheral memory of a Cortex-M system?
What is the main purpose of control registers in the peripheral memory of a Cortex-M system?
What is the size, in bits, of the general-purpose registers in a Cortex-M processor?
What is the size, in bits, of the general-purpose registers in a Cortex-M processor?
What digital component is used to construct a register capable of storing binary bits?
What digital component is used to construct a register capable of storing binary bits?
Which of the following best describes the primary role of a compiler in the context of translating C code to machine code?
Which of the following best describes the primary role of a compiler in the context of translating C code to machine code?
What is the main advantage of using a high-level language like C compared to assembly language or machine code?
What is the main advantage of using a high-level language like C compared to assembly language or machine code?
Consider a scenario where a C program contains a loop that iterates through an array. Which level of program code is MOST directly involved in the repetitive execution of the loop?
Consider a scenario where a C program contains a loop that iterates through an array. Which level of program code is MOST directly involved in the repetitive execution of the loop?
Why is machine code represented in binary digits (bits)?
Why is machine code represented in binary digits (bits)?
Which of the following characteristics distinguishes assembly language from machine code?
Which of the following characteristics distinguishes assembly language from machine code?
Given a simple C program that declares an integer variable and assigns it a value, at which stage does the variable's value get represented in binary format?
Given a simple C program that declares an integer variable and assigns it a value, at which stage does the variable's value get represented in binary format?
You have written a C program and need to create an executable file. What is the general sequence of steps involved?
You have written a C program and need to create an executable file. What is the general sequence of steps involved?
What is the primary purpose of 'linking' in the process of creating an executable file from C code?
What is the primary purpose of 'linking' in the process of creating an executable file from C code?
In a computer system with a 32-bit address space, what is the maximum amount of RAM that can be directly addressed?
In a computer system with a 32-bit address space, what is the maximum amount of RAM that can be directly addressed?
Why might a Harvard architecture be preferred over a Von-Neumann architecture in certain applications?
Why might a Harvard architecture be preferred over a Von-Neumann architecture in certain applications?
Which of the following memory sizes is closest to 1 Terabyte?
Which of the following memory sizes is closest to 1 Terabyte?
In a Von-Neumann architecture, what is a primary limitation concerning memory access?
In a Von-Neumann architecture, what is a primary limitation concerning memory access?
What is a key difference in memory organization between Von-Neumann and Harvard architectures that impacts their performance?
What is a key difference in memory organization between Von-Neumann and Harvard architectures that impacts their performance?
An embedded system utilizes an ARM Cortex-M series microcontroller with a modified Harvard architecture. It has 4KB of flash memory for instructions and 256KB of SRAM for data. What is a likely reason for choosing this configuration?
An embedded system utilizes an ARM Cortex-M series microcontroller with a modified Harvard architecture. It has 4KB of flash memory for instructions and 256KB of SRAM for data. What is a likely reason for choosing this configuration?
Consider a system that uses memory addresses to point to locations where data is stored. If a particular memory location stores the hexadecimal value 0x70
, what could this value potentially represent?
Consider a system that uses memory addresses to point to locations where data is stored. If a particular memory location stores the hexadecimal value 0x70
, what could this value potentially represent?
A program running on a 32-bit system attempts to access a memory location beyond the 4GB limit. What is the most likely outcome?
A program running on a 32-bit system attempts to access a memory location beyond the 4GB limit. What is the most likely outcome?
What is the primary function of a bootloader in a processor?
What is the primary function of a bootloader in a processor?
In assembly programming, what does the program counter (PC) typically point to when a program starts?
In assembly programming, what does the program counter (PC) typically point to when a program starts?
What is the purpose of the instruction LDR r1, =a
?
What is the purpose of the instruction LDR r1, =a
?
What action is performed during the 'Execute' stage of a load instruction?
What action is performed during the 'Execute' stage of a load instruction?
What does a 'dead loop' at the end of the main function typically indicate in an assembly program?
What does a 'dead loop' at the end of the main function typically indicate in an assembly program?
Flashcards
Kilo (K)
Kilo (K)
1,024 bytes.
Mega (M)
Mega (M)
1,048,576 bytes.
Giga (G)
Giga (G)
1,073,741,824 bytes.
Tera (T)
Tera (T)
Signup and view all the flashcards
Von-Neumann Architecture
Von-Neumann Architecture
Signup and view all the flashcards
Harvard Architecture
Harvard Architecture
Signup and view all the flashcards
32-bit Memory Address Space
32-bit Memory Address Space
Signup and view all the flashcards
ARM Cortex-M Series Family
ARM Cortex-M Series Family
Signup and view all the flashcards
ELF (Executable and Linkable Format)
ELF (Executable and Linkable Format)
Signup and view all the flashcards
Section Header Table
Section Header Table
Signup and view all the flashcards
text segment
text segment
Signup and view all the flashcards
RO segment
RO segment
Signup and view all the flashcards
RW segment
RW segment
Signup and view all the flashcards
Z segment
Z segment
Signup and view all the flashcards
Primary Memory (SRAM)
Primary Memory (SRAM)
Signup and view all the flashcards
32-bit Address Space
32-bit Address Space
Signup and view all the flashcards
C Program
C Program
Signup and view all the flashcards
Assembly Program
Assembly Program
Signup and view all the flashcards
Machine Code
Machine Code
Signup and view all the flashcards
C to Machine Code Translation
C to Machine Code Translation
Signup and view all the flashcards
Executable File
Executable File
Signup and view all the flashcards
High-Level Language
High-Level Language
Signup and view all the flashcards
Assembly Language
Assembly Language
Signup and view all the flashcards
Hardware Representation
Hardware Representation
Signup and view all the flashcards
Register
Register
Signup and view all the flashcards
Register Access Speed
Register Access Speed
Signup and view all the flashcards
Temporal Locality
Temporal Locality
Signup and view all the flashcards
Spatial Locality
Spatial Locality
Signup and view all the flashcards
Stack Pointer (SP)
Stack Pointer (SP)
Signup and view all the flashcards
LDR r1, =a
LDR r1, =a
Signup and view all the flashcards
PC and _main Function
PC and _main Function
Signup and view all the flashcards
Dead Loop at Program End
Dead Loop at Program End
Signup and view all the flashcards
Bootloader
Bootloader
Signup and view all the flashcards
Program Counter (PC)
Program Counter (PC)
Signup and view all the flashcards
ARM Cortex-M
ARM Cortex-M
Signup and view all the flashcards
Cortex-M Memory Addresses
Cortex-M Memory Addresses
Signup and view all the flashcards
Program Memory Segments
Program Memory Segments
Signup and view all the flashcards
Stack (FILO)
Stack (FILO)
Signup and view all the flashcards
Heap
Heap
Signup and view all the flashcards
Peripheral Memory
Peripheral Memory
Signup and view all the flashcards
Processor Registers
Processor Registers
Signup and view all the flashcards
Study Notes
- Study notes on how a program runs
Translating C to Machine Code
- The goal is to create an executable machine program
- A compiler creates the executable file
- Executables are platform-dependent and non-portable
- An executable that is compiled for one processor cannot run on a different microprocessor
- Executable file modifications may be required when switching platforms
Compiler
- Two steps in the process of compiling: Analysis and Synthesis
- Analysis, the goal is to create an Intermediate Representation (IR) that represents the original program in a simplified way
- IR aka low-level representation
- Analysis for C is assembly language
- Synthesis is the process of generating the executable from IR
- Synthesis involves performing transformations and optimizations
- Synthesis improves program execution speed or reduces program size
Executable File Format (ELF)
- The machine programs support a standard binary file specification
- Abbreviated as ELF for executable and linkable format
- ARM processors support ELF
- Two views: linking and execution
Views of ELF
- Linking: used at static link time to merge multiple files during compilation
- Execution: employed at runtime to create a process image in memory when a program is loaded and executed
- When a compiler constructs an executable file, Section Header Table can locate the content of a specific section in the ELF file by referencing: the section header table
- Text segment is binary machine code
- Read-Only segment (RO) contains the value of variables unalterable at runtime
- Read-Write (RW) segment is the initial values of statically allocated and modifiable variables
- Zero Initialised segment (Z) holds all uninitialised variables
Loading a Program into Memory
- Executable is saved to flash memory, typically several MBs
- Flash memory allows the processor to restart
- When running, the program is copied to primary memory, aka static memory, or SRAM
- Static memory (SRAM) typically has hundreds of KBs
Arrangement of Memory
- Memory is arranged serially in locations
- Each location has a unique address with 32 bits for a typical 32 bit processor
- Each location holds a byte
- It is byte-addressable
- The memory location stores a value that can represent program data or instructions
Memory Capacity
- The total addressable space is bytes, i.e., 4 GB for a 32 bit processor
- Memory is measured in KB (kilobytes), MB (megabytes), GB (gigabytes), and TB (terabytes)
- One kilobyte is 1,024 bytes
- One megabyte is 1,048,576 bytes
- One gigabyte = 1,073,741,824 bytes
- One terabyte = 1,099, 511,627,776 bytes
Computer Architecture
- Von Neumann computer architecture includes instructions and data that is stored in the same memory using 1 data bus.
- The Harvard computer architecture separates data and instructions into separate memories using 2 data buses and is employed in most microcontrollers.
Von Neumann architecture
- The processor cannot fetch an instruction and access data simultaneously
- All segments are loaded into the main memory
- Memory bandwidth is shared
- Inexpensive and straightforward
Harvard architecture
- There are dual sets of data buses
- Simultaneous fetch of instructions and data is possible
- Segments of Z and RW, are copied into the data memory
- Enhanced memory bandwidth = high/ speed performance
- More efficient
Harvard ARM Microcontrollers
- Instruction and data memory are small enough to fit within the same address space and share the same memory address bus
- 4KB for instructional memory with Flash Memory and 256 KB for data memory with SRAM
- Starting addresses of microcontrollers using Harvard Architecture: flash has 0x0800_0000 and SRAM has 0x2000_0000
Program loading in memory
- When the processor loads a program, all initialised, uninitialised global, and local variables are kept in data memory
- When the processor boots, it loads the first instruction of the program from the instruction memory, and the program starts to run.
- At runtime, there are 4 segments: Initialized data, uninitialized or zero-initialized data aka block starting symbol (BSS), heap, and stack.
- The size and location of initialised and uninitialised data remain unchanged. Heap and stack changes dynamically.
- The Stack is mandatory and follows the first-in-last-out (FILO) protocol
- The Heap is used only if dynamic assignemnt via malloc is used
Cortex M Memory Map
- No overlap between SRAM, Flash Memory and Peripherals allowing for a convenient peripheral interface
- Peripheral devices are a computer component and are separate from the computer's core architecture.
Peripheral Memory
- A set of registers that include: data registers for data exchange between the peripheral and the processor, control registers that configure or control the peripheral, and status registers that indicate the operation state of the peripheral.
- Peripheral Memory may also contain a small memory
- Memory access instructions are predefined for each peripheral.
Registers
- Also known as Processor Registers
- This is the fastest data storage using digital values
- General sizes are 16 bit, 32 bit and 64 bit
- Cortez -M registers are 32 bits
- The Processor reads or writes all bits of a register together
- There are 2 register types: General purpose (GP), used to store any instruction (temporary storage), and special purpose (SP), which has predetermined usage and has restricted access
- Registers are made of a series of flip-flops that operate in parallel to store binary bits
- CPUs are limited to only 32 registers
- Improves thermal behaviour due to highest temperature
- The rules to follow in assembly for register allocation are: Inspect the live range of a variable and the registers; most frequently used variables should be mapped to registers, the rest to data memory
Types Of Registers
- Stack pointer (SP), which is R13, holds the memory address of the top the stack.
- Memory add of inst after subroutine occurs in the link register (LR) which is R14
- The next instruction mem add occurs at the program counter PC
- Program status register (xPSR) - is for status bit flags, containing info if the are negative, zero, carry, and overflow errors.
- Base priority mask register (BASEPRI) - this is the priority threshold; lower values are a higher priority.
- The control register (CONTROL) controls the choice of MSP or PSP
- Priority mask register (PRIMASK) disables all interrupts, excluding hard and non-maskable interrupts (NMI)
- Fault mask register (FAUL TMASK) can disable all interrupts, excluding non-maskable interrupts (NMI).
- Cortex M general registers are R0-R12 for general purposes
- Link register (LR) and Program counter are R14 and R15, respectively.
Program Counter
- Plays a major role for Program execution
- Holds the memory address of the next instruction
- Processor fetches instructions consecutively from the instruction memory and automatically increments the program counter to where the next instruction is to be fetched
Program Execution Steps
- The program counter (PC) is a register that holds the memory address of the next instruction is to be fetched from the memory
- Steps 1: fetch instructions at the PC address
- Step 2: decode the instruction
- Step 3: execute the instruction in the CPU
- Pipelining allows hardware resources to be fully utilized
- One 32-bit instruction or two 16-bit instructions can be fetched at a time
Size specifications
- Each memory address in byte based addressing is equivalent to only 1 byte.
- The program counter is only incremented by one when addressing this way and the Microchip PIC series are examples.
- Each memory address in word based addressing is the same an 2 bytes and also a single work, and the memory program counter is incremented by 2.
- In DWord based memory addressing each address adds 4 bytes, and can be expressed as 32 bits or 1 DWord. The program counter is increased by 4 using Cortex M or Intel x86.
- A Qword is the size equivalent to 8 bytes with 64 bits, and each increment of the program counter is increased by 4, and has a fetch size of 8, and is seen on Intel x86 64 or ARM 64 bit processors.
Incrementing on ARM Cortex M
- The program counter always increments by 4.
- If bit [15-11] = 11101, 11110, or 11111, then, it is the first half-word of a 32-bit instruction.
- Otherwise, it is a 16-bit instruction.
Studying That Suits You
Use AI to generate personalized quizzes and flashcards to suit your learning preferences.