Embedded System - TE4707
Jurusan Teknik Elektro
Semester Genap 2021/2022
Dr.-Ing., Indar Sugiarto
μP Architecture – ISA
Instruction Set Architecture (ISA) is an abstract model of a computer – it defines
how μP is programmed
It is also related to the machine code – machine language instructions that can
be executed directly by the CPU
Let’s start using top-down approach: how programming works
C Programming Review
int main()
{
int a = 123;
return a;
}
How to compile it? In UNIX/Linux, it produces an ELF (Executable and Linking
Format) file.
What the program produces?
C Programming Review
The assembly version:
@ for raspberry pi version
@ setiap program utama harus memiliki main
.global main /* “main” harus dideklarasikan global */
main:
mov r0, #123
bx lr
How to compile it?
Look with cat, hexdump and objdump on the ELF or its .o
C Programming Review
How to compile and link:
$ as myProg.s -o myProg.o
$ ld -o simple -dynamic-linker /lib/ld-linux.so.3 /usr/lib/arm-linux-gnueabihf/crt1.o /usr/lib/
arm-linux-gnueabihf/crti.o -lc simple.o /usr/lib/arm-linux-gnueabihf/crtn.o
or:
$ as myProg.s -o myProg.o
$ gcc myProg.o -o myProg
Note:
crt1.o: Newer style of the initial runtime code. Contains the _start symbol which sets up
the env with argc/argv/libc _init/libc _fini before jumping to the libc main. glibc
calls this file 'start.s'.
crti.o: Defines the function prolog; _init in the .init section and _fini in the .fini section.
glibc calls this 'initfini.c'.
crtn.o: Defines the function epilog. glibc calls this 'initfini.c'.
https://wiki.osdev.org/Creating_a_C_Library
C Programming Review
Compiling - The modified source code is compiled into binary object code. This code is
not yet executable.
Linking - The object code is combined with required supporting code to make an
executable program. This step typically involves adding in any libraries that are required.
C Programming Review
General programming intro:
.data
#include <stdio.h>
string:
void main()
.asciz "\nHello World!\n"
{
.text
char *hi = “Hello world!”;
.global main
printf(“%s\n”,hi);
.extern printf
}
main:
push {ip, lr}
ldr r0, =string
bl printf
pop {ip, pc}
C Programming Review
How Makefile work?
Commonly used automatic variables:
$@ → the file name of the target of the rule
$< → the name of the first prerequisite
$^ → the names of all the prerequisites
https://www.gnu.org/software/make/manual/html_node/Automatic-Variables.html#Automatic-Variables
Who compile what?
What happened when we call extern?
an application binary interface (ABI) is an interface between two binary program modules; often, one of
these modules is a library (or operating system facility), and the other is a program that is being run by a
user.
An ABI defines how data structures or computational routines are accessed in machine code (a low-level,
hardware-dependent format); in contrast, an API defines this access in source code (a relatively high-level,
hardware-independent, often human-readable format).
An embedded-application binary interface (EABI) specifies standard conventions for file formats, data types,
register usage, stack frame organization, and function parameter passing of an embedded software
program, for use in an embedded system.
ARM provides its compiler (and linker) framework for their user
GNU (community) also has its own compiler/linker
Cross-compilation
Example for Interfacing
See:
http://www.science.smith.edu/dftwiki/index.php/Tutorial:_Assembly_Language_with_the_Raspberry_Pi
More into ISA
In the assembly version, we’ve seen:
How sections are made
How memory are referred (as labels)
What registers are used
What addressing modes are used
Condition and branching instruction
How ARM Procedure Call Standards are used (related to ABI)
Next, we’ll see:
Programmers Model
Instruction Set
System Design