Are There Mistakes in My ARM Cortex-M Machine Code Exercises?

In summary, the conversation revolved around a student learning machine code for Cortex-M and requesting help with exercises from a textbook. The student provided a list of op codes and asked for verification of their work. They also mentioned a second part involving the determination of R and the values of flag registers. Some uncertainty remained regarding certain op codes and the specifics of the second part.
  • #1
sandy.bridge
798
1

Homework Statement


Hey guys. I am just learning machine code for Cortex-M. There are a few exercises within the textbook, however, I am not entirely sure if I am doing them correctly. If you could possible look over my work to see if there are any mistakes, I would greatly appreciate it! They are supposed to be relatively simple, however, I am still not entirely sure.

Each line represents a specific set of machine code. I will provide the code adjacent in brackets.

R0----R1----R2
0x45-----------(MOV R0, #0x45)
0x45 0x02------(MOV R1, #0x02)
0x45 0x02 0x47 (ADD R2, R0, R1)
0x45 0x02 0x43 (SUB R2, R0, R1)
0x45 0x02 0x43 (SUBS R2, R0, R1)
0x45 0x02 0x05 (AND R2, R0, #0x01)
0x45 0x02 0x05 (ORR R0, R0, #0x01)
0x0F 0x02 0x05 (MOV R0, #0x0F)
0x0F 0x0F 0x05 (MOV R1, #0x0F)
0x0F 0x0F 0x05 (CMP R1, R0)
0x0F 0x0F 0x00 (SUBS R2, R0, R1)



The other part had to do with with flags. We are given A and B, two 8-bit numbers, where R = A + B. We have to determine what R would equal, and what the values of the flag registers would be (NZVC).

A---------- B---------- R---------- NZVC
10--------100---------110-------- 0000
0x40------0xA2--------0xC0-------0000
0xC3------0x6F--------0x32-------0001
100-- ----(-100)-------0---------- 0100
110-------146---------0---------- 0101
50---------206-------- 0---------- 0101
 
Physics news on Phys.org
  • #2
sandy.bridge said:

Homework Statement


Hey guys. I am just learning machine code for Cortex-M. There are a few exercises within the textbook, however, I am not entirely sure if I am doing them correctly. If you could possible look over my work to see if there are any mistakes, I would greatly appreciate it! They are supposed to be relatively simple, however, I am still not entirely sure.

Each line represents a specific set of machine code. I will provide the code adjacent in brackets.

R0----R1----R2
0x45-----------(MOV R0, #0x45)
0x45 0x02------(MOV R1, #0x02)
0x45 0x02 0x47 (ADD R2, R0, R1)
0x45 0x02 0x43 (SUB R2, R0, R1)
0x45 0x02 0x43 (SUBS R2, R0, R1)
0x45 0x02 0x05 (AND R2, R0, #0x01)
0x45 0x02 0x05 (ORR R0, R0, #0x01)
0x0F 0x02 0x05 (MOV R0, #0x0F)
0x0F 0x0F 0x05 (MOV R1, #0x0F)
0x0F 0x0F 0x05 (CMP R1, R0)
0x0F 0x0F 0x00 (SUBS R2, R0, R1)
What's your question? Were you supposed to indicate the values of the three registers for each of the op codes above?
sandy.bridge said:
The other part had to do with with flags. We are given A and B, two 8-bit numbers, where R = A + B. We have to determine what R would equal, and what the values of the flag registers would be (NZVC).

A---------- B---------- R---------- NZVC
10--------100---------110-------- 0000
0x40------0xA2--------0xC0-------0000
0xC3------0x6F--------0x32-------0001
100-- ----(-100)-------0---------- 0100
110-------146---------0---------- 0101
50---------206-------- 0---------- 0101
 
  • #3
Hi Mark44,

The table was left blank and we were merely given the code indicated in brackets. I then filled out the table accordingly. For the second portion, R = A + B. We were supposed to fill out R and indicate what value the flag registers would be. Sorry I was no more clear.
 
  • #4
I'm not familiar with Cortex-M, so caveat emptor.

Most of your entries in the table look OK, but there are a few that I'm uncertain of.

For this one -- (SUB R2, R0, R1) -- I'm guessing that the CPU calculates R0 - R1 and stores the result in R2. If so, then what you have for the registers looks fine.

For this one -- (SUBS R2, R0, R1) -- I don't know what the opcode SUBS means, signed subtract?

For this one -- 0x45 0x02 0x05 (ORR R0, R0, #0x01) -- I suspect this is different from OR, but I don't know how it's different. In any case, it looks to be ORing what's in R0 with 0x01, which would just result in the same thing, since what's in R0 is odd.

For the table with flag values, what were you given and what did you fill in?
 
  • #5


I would suggest that you review the textbook and any additional resources to ensure that you have a solid understanding of machine code for Cortex-M. It is important to have a strong foundation in this subject in order to accurately complete exercises and understand the results. Additionally, you could seek help from a teacher or a peer who is knowledgeable in this area to review your work and provide feedback. It is also important to pay attention to details and carefully follow instructions in order to avoid mistakes. Keep practicing and seeking help as needed, and your understanding and skills will improve over time.
 

FAQ: Are There Mistakes in My ARM Cortex-M Machine Code Exercises?

What is ARM Cortex-M machine code?

ARM Cortex-M machine code is a low-level instruction set used by ARM processors to execute tasks. It is written in binary format and is directly understood by the processor. It is used to control the flow of data and instructions, as well as to perform calculations and other operations.

How is ARM Cortex-M machine code different from other types of code?

ARM Cortex-M machine code is different from higher-level programming languages such as C or Java, which are written in text form and require a compiler to convert them into machine code. Machine code is also specific to a particular processor architecture, while higher-level languages can be used on a variety of platforms.

Can I write ARM Cortex-M machine code myself?

Yes, ARM Cortex-M machine code can be written by hand, but it is a complex and time-consuming process. It is usually generated by a compiler or assembly language program, which translates higher-level code into machine code. Writing machine code directly is typically reserved for low-level system programming or for optimizing critical sections of code.

What are the benefits of using ARM Cortex-M machine code?

Using ARM Cortex-M machine code allows for precise control over the processor and can result in faster and more efficient code. It also allows for direct access to hardware resources, making it useful for embedded systems programming. Additionally, machine code can be optimized for specific tasks, resulting in better performance compared to higher-level languages.

Is it necessary to learn ARM Cortex-M machine code to use an ARM processor?

No, it is not necessary to learn ARM Cortex-M machine code to use an ARM processor. Many higher-level programming languages, such as C and Python, have libraries and frameworks that support ARM processors. However, having a basic understanding of machine code can be beneficial in troubleshooting and optimizing code for ARM processors.

Back
Top