0
0
Embedded Cprogramming~20 mins

Cross-compilation mental model in Embedded C - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Cross-Compilation Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
Predict Output
intermediate
2:00remaining
Output of cross-compiled embedded C code with different endianness
Consider this embedded C code compiled on a host machine (little-endian) but running on a target machine (big-endian). What will be the output when the program prints the integer value stored in memory?
Embedded C
#include <stdio.h>

int main() {
    unsigned int x = 0x12345678;
    unsigned char *p = (unsigned char *)&x;
    printf("%02x %02x %02x %02x\n", p[0], p[1], p[2], p[3]);
    return 0;
}
A00 00 00 00
B78 56 34 12
CError: incompatible types
D12 34 56 78
Attempts:
2 left
💡 Hint
The host endianness does not affect runtime memory layout; consider the target's big-endian storage.
🧠 Conceptual
intermediate
1:30remaining
Understanding cross-compilation toolchain components
Which component in a cross-compilation toolchain is responsible for converting source code into machine code for the target architecture?
ACross-compiler
BTarget assembler
CHost linker
DHost debugger
Attempts:
2 left
💡 Hint
Think about which tool translates code to target machine instructions.
🔧 Debug
advanced
2:30remaining
Debugging a cross-compiled embedded program with wrong output
You cross-compiled a program for an embedded device. The program reads sensor data but always prints zero. Which of these is the most likely cause?
Embedded C
#include <stdio.h>

volatile int *sensor = (int *)0x40000000;

int main() {
    int value = *sensor;
    printf("Sensor value: %d\n", value);
    return 0;
}
AThe variable 'value' is not declared volatile.
BThe printf format specifier %d is wrong for int type.
CThe sensor address is incorrect for the target device memory map.
DThe program lacks a main function.
Attempts:
2 left
💡 Hint
Check if the memory address matches the target device's hardware layout.
📝 Syntax
advanced
1:30remaining
Identifying syntax error in cross-compiled embedded C code
Which option contains a syntax error that will prevent cross-compilation?
Embedded C
void setup() {
    int x = 10
    if (x > 5) {
        x = x + 1;
    }
}
AIncorrect braces placement in if statement
BMissing semicolon after 'int x = 10'
CUsing 'void' as return type in setup function
DUsing 'x' without declaration
Attempts:
2 left
💡 Hint
Look carefully at the end of each statement.
🚀 Application
expert
3:00remaining
Determining the number of instructions generated by cross-compilation
Given this simple embedded C function, how many assembly instructions will the cross-compiler likely generate for the return statement on a typical ARM Cortex-M target?
Embedded C
int add_one(int a) {
    return a + 1;
}
A2 instructions
B1 instruction
C3 instructions
D4 instructions
Attempts:
2 left
💡 Hint
Consider loading the argument, adding 1, and returning the result.