0% found this document useful (0 votes)
18 views9 pages

LAB04 Report

Uploaded by

ahmadmujeebcbf
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
18 views9 pages

LAB04 Report

Uploaded by

ahmadmujeebcbf
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 9

Department of Electrical Engineering – ITU

EE243L: Microcontrollers and Interfacing Lab

Course Instructor: Dr. Ammar Rafique Dated:

Lab Engineer: Muhammad Umair Shoaib Semester: Spring 2024

Batch: BSEE22

Lab 4 – Conditional Statements in ARM Assembly Using Program

Control Instructions – II

Total
Name Roll number
(out of 35)

Checked on: __________________________

Signature: ____________________________
Task 1:
Code:
AREA main, CODE, READONLY
EXPORT __main
ENTRY

__main
; Sort Arr1
LDR r0, =Arr1
LDR r5, =Sorted_Arr1
MOV r6, #4 ; Increment
LDR r7, =Size1 ; Size of Arr1
MUL r7, r7, r6 ; Calculate total size

MOV r1, #0 ; Index

OuterLoop
MOV r2, #0 ; Check if any swaps occur
InnerLoop
LDR r3, [r0, r1] ; r3 = Arr1[j]
ADD r8, r1, r6 ; r8 = j + 1
LDR r4, [r0, r8] ; r4 = Arr1[j+1]
CMP r4, r3 ; Compare Arr1[j+1] with Arr1[j]
BGE NoSwap ; If Arr1[j+1] >= Arr1[j], no swap needed

; Swap Arr1[j] with Arr1[j+1]


STR r4, [r0, r1]
STR r3, [r0, r8]
MOV r2, #1 ; Set to indicate a swap occurred

NoSwap
ADD r1, r1, r6 ; Increment j
CMP r1, r7 ; Compare j with total size
BNE InnerLoop ; Repeat InnerLoop if j < total size
CMP r2, #0 ; If no swaps , array is sorted
BEQ Sorted
MOV r1, #0 ; Reset for next iteration
B OuterLoop ; Repeat OuterLoop

Sorted
; Store sorted Arr1
LDR r0, =Arr1
LDR r1, =Sorted_Arr1
MOV r6, #4 ; Increment
LDR r7, =Size1 ; Size of Arr1
MUL r7, r7, r6 ; total size

MOV r1, #0 ; Index


StoreLoop
LDR r3, [r0, r1]
STR r3, [r5, r1]

ADD r1, r1, r6 ; Increment index


CMP r1, r7
BNE StoreLoop

; Sort Arr2
LDR r0, =Arr2
LDR r5, =Sorted_Arr2
MOV r6, #4 ; Increment
LDR r7, =Size2 ; Size of Arr2
MUL r7, r7, r6 ; Calculate total size

MOV r1, #0 ; Index


OuterLoop2
MOV r2, #0 ; Flag to check if any swaps occur
InnerLoop2
LDR r3, [r0, r1] ; r3 = Arr2[j]
ADD r8, r1, r6 ; r8 = j + 1
LDR r4, [r0, r8] ; r4 = Arr2[j+1]
CMP r4, r3 ; Compare Arr2[j+1] with Arr2[j]
BGE NoSwap2 ; If Arr2[j+1] >= Arr2[j], no swap needed

; Swap Arr2[j] with Arr2[j+1]


STR r4, [r0, r1]
STR r3, [r0, r8]
MOV r2, #1 ; Set flag to indicate a swap occurred

NoSwap2
ADD r1, r1, r6 ; Increment j
CMP r1, r7 ; Compare j with total size
BNE InnerLoop2 ; Repeat InnerLoop2 if j < total size

CMP r2, #0 ; If no swaps occurred, array is sorted


BEQ Sorted2
MOV r1, #0 ; Reset flag for next iteration
B OuterLoop2 ; Repeat OuterLoop2

Sorted2
; Store sorted Arr2
LDR r0, =Arr2
LDR r1, =Sorted_Arr2
MOV r6, #4 ; Increment
LDR r7, =Size2 ; Size of Arr2
MUL r7, r7, r6 ; Calculate total size

MOV r1, #0 ; Index


StoreLoop2
LDR r3, [r0, r1]
STR r3, [r5, r1]

ADD r1, r1, r6 ; Increment index


CMP r1, r7
BNE StoreLoop2

; End of program
END

; Define data
Arr1 DCD 0, 21, 22, -55, 9, 19, -129
Size1 DCB (.-Arr1)/4
Arr2 DCD 22, 12, 77, -55, 66, -33, 22, 11
Size2 DCB (.-Arr2)/4
AREA data_one, DATA, READWRITE
Sorted_Arr1 DCD 0, 0, 0, 0, 0, 0, 0
Sorted_Arr2 DCD 0, 0, 0, 0, 0, 0, 0, 0

Observation:
This ARM assembly code implements a bubble sort algorithm to sort two arrays, Arr1 and Arr2. The
sorted results are stored in Sorted_Arr1 and Sorted_Arr2. The sorting process involves nested loops,
comparing adjacent elements, and swapping them if necessary. The sorted arrays are then stored in
designated memory locations. The code concludes with a data section defining the arrays and their
sizes.

SCREEN-SHOT

Task 2:
Code:
AREA main, CODE, READONLY
EXPORT __main
ENTRY
__main
; Load the base addresses of Arr1 and Arr2 into registers r0 and r1
LDR r0, =Arr1
LDR r1, =Arr2
; Initialize loop counters and bounds
MOV r8, #0 ; Initialize loop counter
MOV r7, #20 ; Set the loop bound to 20 (5 elements * 4 bytes each)
; Load the first elements of Arr1 and Arr2 into registers r2 and r3
LDR r2, [r0]
LDR r3, [r1]
loop
; Load elements from Arr1 and Arr2 using indexed addressing mode
LDR r2, [r0, r8]
LDR r3, [r1, r8]
; Multiply the loaded elements and store the result in r4
MUL r4, r2, r3
; Accumulate the multiplication results in r11
ADD r11, r11, r4
; Increment the loop counter by 4 (since each element is 4 bytes)
ADD r8, r8, #4
; Compare the loop counter with the loop bound
CMP r8, r7
; If the loop counter is not equal to the loop bound, branch to the loop label
BNE loop
; Store the final result in Arr3
LDR r10, =Arr3
STR r11, [r10]
Arr1 DCD 200, 122, -355, 433, -728
Arr2 DCD 500, -622, 220, -114, 781
Arr3 DCD 0
AREA data_one, DATA, READWRITE
END
Observation:
This ARM assembly code calculates the dot product of two arrays (Arr1 and Arr2) and stores the
result in Arr3. The loop iterates over the elements of the arrays, multiplies corresponding elements,
and accumulates the results. The loop counter and bounds are managed using registers, and the final
result is stored in the destination array (Arr3).
SCREEN-SHOT

Analysis:
1.

In the provided context, the method employed to determine the length of a byte array involves utilizing
the command ".-ArrayName." This command extracts the address of the last digit and subtracts the
address of the first digit, resulting in the byte size of the array.
If the array is comprised of words and has a size of 4, one can obtain the size of the word array by
dividing the byte size by 4. This approach effectively calculates the length of the array by considering
the byte size and adjusts accordingly for word arrays by dividing by the appropriate factor.

In the process of performing multiplication, the MUL instruction was employed. The rationale behind
selecting the MUL instruction lies in the absence of any newly introduced specialized command
dedicated explicitly to multiplication in our study. Given the simplicity and versatility of the MUL
instruction, it was a pragmatic choice for implementing multiplication within the code. This decision
aligns with the principle of utilizing well-established and commonly used instructions to achieve the
desired operation, contributing to code clarity and ease of comprehension.

2.
Assessment rubric for Lab
Performance CLO Able to complete the Able to complete the Tasks completion below Marks
tasks over 80% tasks 50 - 80% 50%
(4 – 5) (2 – 3) (0 – 1)
1. Realization of 1 Conceptually understands Needs guidance to Incapable of
experiment the topic under study and understand the purpose of understanding the purpose
develops the experimental the experiment and to of the experiment and
setup accordingly develop the required setup consequently fails to
develop the required setup
2. Conducting 1 Sets up the relevant Needs assistance in setting Unable to set up the
experiment hardware/software, writes up the software/hardware, hardware/software and to
and executes assembly/C makes minor errors in write and execute program
programs according to the writing programs according to task
requirement of tasks and according to the task requirements
examines the output requirements
rigorously
3. Data collection 1 Interprets program output Completes data collection Fails at observing output
and completes data with minor errors and states of experimental
collection as required in enters data in lab report setup and collecting data,
the lab task, ensures that with slight deviations unable to fill the lab report
the data is presented in the from provided guidelines properly
lab report according to the
specified instructions
4. Data analysis 1 Analyzes the data Analyzes data with minor Unable to establish a
obtained from experiment error and correlates it with relationship between
thoroughly and accurately theoretical values practical and theoretical
verifies it with theoretical reasonably. Attempts to results and lacks in-depth
understanding, accounts account for any understanding to justify
for any discrepancy in discrepancy in data from the results or to explain
data from theory with theory any discrepancy in data
sound explanation, where
asked
5. Computer use 1 Possesses sufficient Is able to work on relevant Cannot operate IDE
hands-on ability to work IDE with some assistance without significant
with the relevant IDE assistance
6. Teamwork 3 Actively engages and Cooperates with other Distracts or discourages
cooperates with other group members in a other group members from
group members in an reasonable manner conducting the
effective manner experiments
7. Lab safety and 3 Observes lab safety rules; Observes safety rules and Disregards lab safety and
disciplinary rules and adheres to the lab disciplinary guidelines disciplinary rules
disciplinary guidelines with minor deviations
aptly
Total
(out of 35)

You might also like