Sample Exercises for Quiz 2

ARM Pipelining, ARM Assembly Language Instructions, Branching,
Control Statements, Bitwise Logical Operations,
Intro to the Data Segment, Intro to The Stack

Translate the following C control statements into equivalent unoptimized ARM assembly.
Use only the "preferred" looping structure as specified in the Notes/Class.

x = 3;

while ( x > 17 ) {
   stmt1;
   stmt2;
   ++x;
}

stmt1_after_while;

--------------------------

x = 3;

do {
   stmt1;
   stmt2;
   ++x;
} while ( x > 17 );

stmt1_after_do-while;

--------------------------

for ( x = 0; x < 22; ++x ) {
   stmt1;
   stmt2;
}

stmt1_after_for;

--------------------------

if ( x < 16 ) {
   stmt1;
   stmt2;
}

stmt1_after_if;

--------------------------

if ( x < 16 ) {
   stmt1;
   stmt2;
} else {
   stmt3;
   stmt4;
}

stmt1_after_if-else;

--------------------------

x = 5555 * 12;

--------------------------

x = 4444 / 13;

--------------------------

x = 6666 % 14;

--------------------------

x = fubar( 35, -6006 );

--------------------------

What is the value (in hex) of r3 after each set of instructions:

ldr  r1, =0x12873465
ldr  r2, =0x56128734
and  r3, r1, r2


ldr  r1, =0x12873465
ldr  r2, =0x56128734
orr  r3, r1, r2


ldr  r1, =0x12873465
ldr  r2, =0x56128734
eor  r3, r1, r2


ldr  r3, =0xDEADBEEF
lsr  r3, r3, 11


ldr  r3, =0xDEADBEEF
asr  r3, r3, 8


ldr  r3, =0xDEADBEEF
lsl  r3, r3, 11


Write the ARM assembly bit checking instructions to test if bit 31
(most significant bit) of the value in register r2 is set and branch
to a label named negative if it is.
Use a bit mask and use one of AND, OR, or XOR.


What bit mask would you use to check if every evenly divisible by 4 bit
is on (bit 0, bit 4, bit 8, etc.)?
Bits are numbered from 31 (most significant bit) to 0 (least significant bit).

What is the difference between an instruction like add and adds?


Indicate which conditional branch instructions would transfer control to
loop if used in place of the b (branch always) instruction below.
In other words, if you were to replace the b instruction with
blt would it still branch to loop?  What about ble?
What about bgt? Etc. for all the conditional branches ...

mov    r3, 7                       mov    r3, 7
adds   r3, r3, -2                  cmp    r3, 5
b      loop                        b      loop

Conditional Branch Instructions
           blt     ble
           bgt     bge
           beq     bne
           blo     bls
           bhi     bhs
           bmi     bpl
           bvs     bvc
           bcs     bcc


Intro to The Data Segment

List the assembler directives that are used to allocate space for the various basic
data types (char -> double)? What are the alignment restrictions of the
various basic data types (char -> double)?

Write the ARM Assembly language instructions to allocate the following
*global* variables:

	char	a = 'A';
	long	b = 0x08675309;
	char	c = '\n';	/* Use the decimal ASCII value for this one */
	double	d = -14.65;
	char	e = '\x0A';
	short	f = 420;
	char fmt[] = "CSE30 Rocks\n"

Intro to The Stack

What are some of the reasons why we have to use the runtime Stack for local
variables (as opposed to just mapping all local variables to the registers)?

Write the standard prologue instructions given in the Notes/Class and
allocate 5 integers as local variables on the Stack.

Write the standard epilogue instructions given in the Notes/Class.