0% found this document useful (0 votes)
30 views6 pages

COEN 311 LAB REPORT 3

The lab report focuses on addressing modes in ARM assembly language and working with 2D arrays. It aims to enhance understanding of data access methods, basic math instructions, and the translation of high-level code into assembly language. The hands-on experience emphasizes the importance of precision in low-level programming and the relationship between assembly language and hardware operations.
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)
30 views6 pages

COEN 311 LAB REPORT 3

The lab report focuses on addressing modes in ARM assembly language and working with 2D arrays. It aims to enhance understanding of data access methods, basic math instructions, and the translation of high-level code into assembly language. The hands-on experience emphasizes the importance of precision in low-level programming and the relationship between assembly language and hardware operations.
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/ 6

COEN 311 LAB REPORT 3

Addressing modes and 2D arrays

Nicolas GHARZOUZI
40232064

Due date: 25 March 2024


Introduction
In assembly language programming, there are different ways or "modes" for an instruction to get the data
it needs. So far, we've looked at two basic ways in previous labs. This lab will introduce us to more ways
of doing this. We'll start by revisiting the simple modes we already know.

Objectives
 Understand different ways to access data in ARM assembly language.
 Learn basic math instructions in assembly language.
 Learn how to use these methods and instructions to work with a 2D array of numbers stored in
the computer's memory.
 See how a compiler translates high-level language into assembly language.

Theory
The way an instruction in assembly language finds its data is called the "addressing mode." We've seen
some basic addressing modes like immediate mode, where the data is right in the instruction, and register
indirect mode, where the data's memory address is kept in a register. This lab will show us more complex
addressing modes and how they work. We'll also see how these modes are similar to using pointers in
languages like C++. Understanding these addressing modes helps us see how compilers turn high-level
code into assembly language, which is what the computer's processor can understand.

Results and Discussion


In this lab, we wrote and ran an assembly program that deals with a 2D array of integers. This task let us
practice different ways of accessing data in memory, highlighting how assembly language allows us to
work closely with the computer's hardware. By calculating where each piece of data was stored and how
to get to it, we learned the importance of being very careful and precise in assembly language. This
hands-on experience helped us understand the low-level operations that high-level languages, like C++,
handle automatically. It was a great way to see the power and complexity of programming at the
hardware level.
figure 1: ARM code that use the 2D array formula
Figure 2: GDB file and results

Questions
1) .data
mydata: .word 0xdeadbeef @ Define 'mydata' with a hexadecimal value
address_of_mydata: .word mydata @ Store the address of 'mydata' in 'address_of_mydata'

Here the value 0xDEADBEEF is assigned to mydata and address_of_mydata stores the address of
mydata.

Then we have the following code : LDR R1, =address_of_mydata


LDR R1, [R1]
LDR R2, [R1]
Here, LDR R1, = address_of_my_data loads the address of address_of_my_data into R1. LDR
R1, [R1] dereferences R1 to load the address of mydata into R1. And LDR R2, [R1] loads the
value at mydata (which is 0xDEADBEEF) into R2.

So the value stored in R2 is 0xdeadbeef.

2) The provided code fragment, "mydata:.word 0xdeadbeef 14," exemplifies the syntax often seen in
assembly or low-level programming, featuring the label "mydata" alongside a 32-bit word
(equivalent to 4 bytes) that includes the number 14 and the hexadecimal notation 0xdeadbeef.
Endianness refers to the sequence in which a processor stores data that spans multiple bytes. For
processors like the ARM found in the STM32F334 Nucleo board, as well as numerous other ARM-based
systems, a little-endian format is commonly employed. This format arranges data so that the least
significant byte (LSB) occupies the lowest memory address, with the most significant byte (MSB)
positioned at the highest memory address for any given multi-byte data item, such as a 32-bit word
0xdeadbeef.
In this format, the 32-bit hexadecimal figure 0xdeadbeef would be stored in memory starting from a base
address X as follows:
Address X: 0xef (Least significant byte)
Address X+1: 0xbe
Address X+2: 0xad
Address X+3: 0xde (Most significant byte)
Thus, the ARM processor within the STM32F334 Nucleo microcontroller board adopts a little-endian
configuration for its byte order, a choice that aligns with the common preference across ARM-based
platforms for its benefits in memory handling and software development efficiency.

Conclusion
This lab taught us about different ways to access data in assembly language, especially when dealing with
2D arrays. We saw firsthand how assembly language lets us control the computer's hardware directly,
though this requires careful planning and precision. The lab also showed us how compilers work to turn
high-level code into assembly language, bridging the gap between the programmer's intentions and the
processor's operations. Overall, the lab was a valuable lesson in both the capabilities and complexities of
low-level programming.

You might also like