Introduction to Embedded Design (Ch. 1 - 5)

Introduction to Embedded Design (Ch. 1 - 5)

COEN 20 - C - Personal

Martin Rios-Cardenas (lvl 5)
Ch 4

Preview this deck

Translate into assembly

u64 = 0;

Front

Star 0%
Star 0%
Star 0%
Star 0%
Star 0%

0.0

0 reviews

5
0
4
0
3
0
2
0
1
0

Active users

1

All-time users

2

Favorites

0

Last updated

3 years ago

Date created

Oct 20, 2020

Cards (62)

Ch 4

(35 cards)

Translate into assembly

u64 = 0;
Front
LDR R0,=0
STRD R0,R0,u64
Back

Translate into assembly 

s32 = s8;
Front
LDRSB R0,s8
STR R0,s32
Back

Translate into assembly 

s8 = s16;
Front
LDRSH R0,s16
STRB R0,s8

Back

Translate into assembly 

ps32++;
Front
LDR R0,ps32
ADD R0,R0,4
STR R0,ps32
Back

Translate into assembly 

u32 = 0;
Front
LDR R0,=0
STR R0,u32
Back
*ps32 = 0;
Front
LDR R0,=0
LDR R1,ps32
STR R0,[R1]
Back

Translate into assembly 

s32 = s16;
Front
LDRSH R0,s16
STR R0,s32
Back

Translate into assembly 

s8 = s32;
Front
LDR R0,s32
STRB R0,s8
Back

Translate into assembly 

ps8 = &s8;
Front
ADR R0,s8
STR R0,ps8
Back
*(ps8+1) = 0;
Front
LDR R0,=0
LDR R1,ps8
STRB R0,[R1,1]
Back

Translate into assembly 

ps8++;
Front

LDR R0,ps8

ADD R0,,R0,1

STR R0,ps8

Back

Translate into assembly

int32_t f4(int32_t a32[])
{
	return a32[1];
}
Front
f4:
LDR R0,[R0,4]
BX LR
Back
*(ps32+1) = 0;
Front
LDR R0,=0
LDR R1,ps32
STR R0,[R1,4]
Back
((int8_t*)&s32)[1] = 0;
Front
LDR R0,=0
ADR R1,s32
STRB R0,[R1,1]
Back

Translate into assembly

u32 = *pu16 + 2;
Front
LDR R0,pu16
LDRH R1,[R0]
ADD R1,R1,2
STR R1,u32
Back

Translate into assembly 

s64 = s32;
Front
LDR R0,s32
ASR R1,R0,31
STRD R0,R1,s64

 

Back

Translate into assembly 

u8 = u32;
Front
LDR R0,u32
STRB R0,u8
Back

Translate into assembly 

u32 = u16;
Front

LDRH R0,u16

STR R0,u32

Back

Translate into assembly

s8 = -1;
Front
LDR  R0,=-1
STRB R0,s8
Back

Translate into assembly

u16 = 0;
Front
LDR R0,=0
STRH R0,u16
Back

Translate into assembly 

u16 = u32;
Front
LDR R0,u32
STRH R0,u16
Back

Translate into assembly 

u32 = u8;
Front
LDRB R0,u8
STR R0,u32
Back

Translate into assembly 

s16 = s8;
Front
LDRSB R0,s8
STRH R0,s16
Back

Translate into assembly 

s32 = -1;
Front
LDR R0,=-1
STR R0,s32
Back

Translate into assembly 

s64 = -1;
Front
LDR R0,=-1
STRD R0,R0,s64
Back

Translate into assembly

pu8 = &u8;
Front
ADR R0,u8
STR R0,pu8
Back
*(ps32+s32) = 0;
Front
LDR R0,=0
LDR R1,ps32
LDR R2,s32
STR R0,[R1,R2,LSL 2]
Back

Translate into assembly 

s16 = -1;
Front
LDR R0,=-1
STRH R0,s16
Back

Translate into assembly 

s16 = s32;
Front
LDR R0,s32
STRH R0,s16
Back

Translate into assembly 

u32 = *(pu16 + 2);
Front
LDR R0,pu16
LDRH R1,[R0,4]
STR R1,u32
Back

Translate into assembly 

u16 = u8;
Front
LDRB R0,u8
STRH R0,u16
Back

Translate into assembly 

u64 = u32;
Front
LDR R0,u32
LDR R1,=0
STRD R0,R1,u64
Back

Translate into assembly

u8 = u16;
Front
LDRH R0,u16
STRB R0,u8
Back

Translate into assembly 

ps32 = &s32;
Front
ADR R0,s32
STR R0,ps32
Back

Translate to assembly

u8 = 0;
Front
LDR R0,=0
STRB R0,u8
Back

Ch 3

(19 cards)

Translate into assembly 

uint64_t f1(uint32_t a)
{
	uint32_t f2(uint32_t);
	return (uint64_t)f2(a+10);
}
Front
f1: PUSH {LR}
	ADD R0,R0,10 //R0 <— a+10
	BL f2 //R0 <— f2(a+10)
	LDR R1,=0
	POP {PC}
Back

Translate into assembly. Assume function and b is int64_t

b = g4();
Front
BL g4
STRD R0,R1,b
Back

Translate into assembly. Assume its on int8_t

h2(&a);
Front
ADR R0,a
BL h2
Back

Translate into assembly

uint64_t f4(uint32_t u32)
{
	return (uint64_t)u32;
}
Front
f4:
LDR R1,=0
BX f4
Back

Translate into assembly. Assume it’s on int8_t

b = h4();
Front
BL h4
STRB R0,b
Back

Translate into assembly. Assume b is int32_t

b = f4();
Front
BL f4
STR R0,b
Back

Translate into assembly

int32_t f9(int32_t a)
{
	int8_t f10(int8_t);
	
	return a + (int32_t) f10(0);
}
Front
f9:
PUSH {LR,R4}
MOV R4,R0
LDR R0,=0
BL f10
ADD R0,R0,R4
POP {R4,PC}
Back

Translate into assembly. Assume a,b is uint64_t.

g3(a,b);
Front
LDRD R0,R1,a
LDRD R2,R3,b
BL g3
Back

Translate into assembly

uint32_t f7(uint32_t a, uint32_t b)
{
	uint32_t f8(uint32_t,uint32_t);
	
	return f8(b,a);
}

 

Front
f7:
PUSH {LR}
MOV R2,R0
MOV R0,R1
MOV R1,R2
BL f8
POP {PC}
Back
g2(&a);
Front
ADR R0,a
BL g2
Back
g1(a);
Front
LDRD R0,R1,a
BL g1
Back

Translate into assembly. Assume a,b is int32_t

f3(a,b);
Front
LDR R0,a
LDR R1,b
BL f3
Back

Translate into assembly 

uint64_t f11(int32_t a)
{
	uint32_t f12(uint32_t);
	return (uint64_t)f12(a+10);
}
Front
PUSH {LR}
ADD R0,R0,=10
BL f12
LDR R1,=0
POP {PC}
Back

Translate into assembly. Assume a is int32_t

f1(a);
Front
LDR R0,a
BL f1
Back

Translate into assembly. Assume it’s on int8_t

h1(a);
Front
LDRSB R0,a
BL h1
Back

Translate into assembly. Assume it’s on int8_t

h3(a,b);
Front
LDRSB R0,a
LDRSB R1,b
BL h3
Back

Translate into assembly 

int32_t f1(int32_t a)
	{
		int8_t f2(int8_t);
		return a + (int32_t)f2(0);
	}
Front
f1: PUSH {R4,LR}
	MOV R4,R0 //Moving from one register to another; preserving a
	LDR R0,=0 //Preparing parameter for f2
	BL f2 //R0 <—- f2(0)
	ADD R0,R0,R4 //R0 = f2(0) + a
	POP {R4,PC}
Back

Translate into assembly

int32_t f5(int32_t a, int32_t b)
{
	int32_t f6(int32_t);
	
	return f6(a) + f6(b);
}
Front
f5:
PUSH {R4,R5,LR}
MOV R4,R1
BL f6
MOV R5,R0
MOV R0,R4
BL f6
ADD R0,R0,R5
POP{R4,R5,PC}

Back

Translate into assembly. Assume a is int32_t

f2(&a);
Front
ADR R0,a
BL f2
Back

Ch 5

(8 cards)

Translate into assembly 

int64_t a,b;
a = a + b;

 

 

Front
LDRD R0,R1,a
LDRD R2,R3,b
ADDS R0,R0,R2
ADCS R1,R1,R3
STRD R0,R1,a
Back

Translate into assembly 

uint32_t a,b,c;
c = a * b;
Front
LDR R0,a
LDR R1,b
MUL R0,R0,R1
STR R0,c
Back
int32_t Discriminant(int32_t a,int32_t b, int32_t c)
{
	return b*b - 4*a*c;
}
Front

Discriminant;
MUL R1,R1

LSL R0,R0,2

MLS R0,R0,R2,R1

BX LR

 

Back

Translate into assembly 

int64_t a;
a -= 5;
Front

LDRD R0,R1,a

SUBS R0,R0,5

SBC R1,R1,0

STRD R0,R1,a

Back
int32_t a,b,c;
c = a / b;

 

Front
LDR R0,a
LDR R1,b
SDIV R0,R0,R1
STR R0,c
Back

Translate into assembly 

int32_t a,b,c;
c=a*b;
Front
LDR R0,a
LDR R1,b
MUL R0,R0,R1
STR R0,c
Back
uint32_t a,b,c ;
c = a / b ;
Front
LDR R0,a
LDR R1,b
UDIV R0,R0,R1
STR R0,c
Back
int32_t a,b,c;
c = a % b;
Front
LDR R0,a
LDR R1,b
SDIV R2,R0,R1
MLS R0,R2,R1,R0
STR R0,c
Back