ES 333 Lab Assignment 1: Hiteshi Meisheri, 23110135.
Q1. A.
Assuming initially all flags were reset. Flags updated AFTER execution of instruction.
Instruction MSB of N Z C V
CPSR
mov r0, #0x04; 0 = [0000] 0 0 0 0 R0=04H
mov r1, #0x2; 0 = [0000] 0 0 0 0 R1=02H
adds r2,r1,r0; 0 = [0000] 0 0 0 0 R2=06H
subs r3,r1,r0; 8 = [1000] 1 0 0 0 R3=FFFFFFFEH
muls r4,r1,r0; 0 = [0000] 0 0 0 0 R4=08H
B.
Assuming initially registers were reset. Values updated AFTER execution of instruction.
Flags unaffected.
Instruction R5 R6 Data at 0x00001000
ldr r5, =0x12345678; 0x12345678 0x00000000 aaaaaaaa
mov r6, #0x00001000; 0x12345678 0x00001000 aaaaaaaa
str r5,[r6]; 0x12345678 0x00001000 0x12345678
Q2. Only CMP affects flags.
Instruction MSB of CPSR R1 R2 Purpose
mov r1,#0x00; 0 [not updated] 0 0 Initialisation
mov r2,#0x00; 0 [not updated] 0 0 Initialisation
Loop: Label
add r2,r2,#0x01; 0 [not updated] 0,1,3,6,10 1,2,3,4,5 R2 holds natural numbers
add r1,r1,r2; 0 [not updated] 1,3,6,10,f 1,2,3,4,5 R1 holds their sum
cmp r2,#0x05; 6 = [0110] f 5 Sets Z and C if R2 == 5.
bne loop; 6 [not updated] f 5 Stop condition for loop.
Q3. Only ADDS updated flags here. The rest carried old values.
Instruction N Z C V
ADDS R0, R1, R2 0 0 0 0 R0=33H R1=11H R2=22H
MOVNE R3, R0 0 0 0 0 R0=00H R3=00H Mov executed.
ORREQ R0, R4, R5 0 0 0 0 R0=00H, R4=33H, R5=55H Not executed.
LSR R3, R6, #7 0 0 0 0 R3=200000H R6=10000000H
SBC R0, R4, R5 0 0 0 0 R0=FFFFFFDDH R4=33H R5=55H
MOVW R5, 0x5422 0 0 0 0 R5=5422H
MOVT R6, 0x524 0 0 0 0 R6=5240000H
ES 333 Lab Assignment 1: Hiteshi Meisheri, 23110135.
Q4. Flags remain unaffected. Values updated AFTER execution of instruction.
Instruction SP R0 R1 R2 R3 0x1000 0x1004 0xf0
mov r13, #0x1008 1008H X X X X X X X
mov r0, #0x20 1008H 20H X X X X X X
mov r1, #0x3d 1008H 20H 3DH X X X X X
push {r0} 1004H 20H 3DH X X X 20H X
push {r1} 1000H 20H 3DH X X 3DH 20H X
pop {r3} 1004H 20H 3DH X 20H 3DH 20H X
pop {r2} 1008H 20H 3DH 3DH 20H 3DH 20H X
add r2, r2, r3 1008H 20H 3DH 5DH 20H 3DH 20H X
mov r13, #0xf4 F4H 20H 3DH 5DH 20H 3DH 20H X
push {r2} FH 20H 3DH 5DH 20H 3DH 20H 5DH
Q5.
This program has been written considering the unsigned 8-bit size of given data.
Instruction Purpose
a.
mov r0, #0x00001000 Initialising registers with given values. R0 holds starting memory
mov r1, #0x79 address
mov r2, #0x58
mov r3, #0x1D
mov r4, #0x43
mov r5, #0x64
stmia r0,{r1-r5} Stores r1-r5 in memory from 0x1000 to 0x1014.
R0 doesn’t change.
b.
mov r9, #0x00; Initialising, R9 holds address of current biggest number.
mov r10,#0x00; R10= counter for outer loop.
mov r11, #0x500; R11 = Starting memory address of descending data
mov r12, #0x00; R12 holds value 0x00.
outer_loop: Label
mov r6,#0x00; R6 is the counter for the inner loop, R7 holds the current largest
mov r7,#0x00; value encountered (initialized to 0)
inner_loop: Label
ldr r8,[r0]; Loads r8 with value from address pointed by r0
cmp r7,r8; N=1 if current number > larger number.
movmi r7,r8; Executes if N=1. R7 is updated with largest value and r9 with its
movmi r9,r0; address.
add r0,r0,#0x04; R0 is updated to the next address.
add r6,r6,#0x01; Counter increment.
cmp r6, #0x05; Counter comparison with upper limit.
bne inner_loop; Continue condition is Z=0, ie when r6!=5.
sub r0,r0,#20; R0 returns to initial address.
str r7,[r11]; Largest number is stored at address held in r11, r11 is then
ES 333 Lab Assignment 1: Hiteshi Meisheri, 23110135.
add r11,r11,#4 updated to point at the next 32-bit block.
str r12,[r9] Address of current largest address is updated with #0x00 so that
it does not get picked repeatedly
add r10,r10,#1; Counter increment.
cmp r10, #0x05; Counter comparison with upper limit.
bne outer_loop; Continue condition is Z=0, ie when r10!=5.