Embedded course assignment record

There are many problems and solutions in the first embedded (small) homework of this semester. A special article is open...
Some notes on ARM development tool ADS
Assembly job

There are many problems and solutions in the first embedded (small) homework of this semester. A special article is opened to record in case of forgetting.

catalogue

Some notes on ARM development tool ADS

(1) code32 means to use the ARM instruction set later!

(2) Click debug. If the following error occurs: error starting external process process error code 87 (0x57) can't read symbols for this tar, please run ADS again as an administrator.

(3) During compilation, if unknown opcode appears in the AREA, the solution: add a space in front of the AREA and do not write in the top grid, otherwise the compilation will not pass! In addition, it is best to leave a blank line at the beginning of the program file.

(4) When writing a program with embedded ARM assembly in C language, the name of the main function is not main, but xmain or_ Main, otherwise the compilation fails!

(5) Warning: l6305w: image doors not have an entry point. (not specified or not set due to multiple choices.) appears during compilation. I don't know how to solve this problem.

Assembly job

I have taught myself x86 assembly before, but I have never written a complete assembler. This job uses ARM assembly to write programs. Although it is quite different from x86 syntax, it is still easy to understand.

1. First assign a character, and then count the frequency of digital characters

Note that if the LDR instruction is used to read the string content of the data segment, the whole string will be read into the register, which is not convenient to separate single characters for counting. Because the LDR instruction loads the entire word into the register.

Now we need to put a byte into the register. By consulting the instruction set, we can find that LDRB and LDRSB can achieve this purpose. The difference is that the latter is read in signed bytes.

It is reasonable to say that both instructions should be OK, but I tried. Only LDRSB can read the whole word with LDRB. I don't know why. I hope someone familiar with the matter can explain.

AREA COPY, CODE, READONLY ENTRY CODE32 START LDR R5, =RESULT LDR R0, =DATA MOV R1, #0 ; Number of Statistics MOV R2, #twenty ; Number of cycles MOV R3, #0 ; Test whether it is a number, if so, it is a negative number B LOOP NUMBER ADD R1, R1, #one ; Numeric characters, plus one B NEXT LOOP LDRSB R4, [R0] ;Get data from source address ;Numeric character ASCII: 48-57 CMP R4, #47 BLE NEXT CMP R4, #58 BLE NUMBER NEXT ADD R0, R0, #one ; address SUB R2, R2, #one ; Cycle minus one CMP R2, #0 BNE LOOP STR R1, [R5] B EXIT EXIT B EXIT AREA COPYDATA, DATA, READONLY DATA DCB "012abc34def56dd78j90" RESULT DCD 0 END

During commissioning:

2. Joseph problem (ARM compilation)

n people form a circle, number from 1 to n, start counting from the person with number 1, and the person who reports to m leaves the team. The following people then count from 1, go down in turn, and write a program to find out what is the number of the last person left?

I'm a little ashamed, because time was tight at that time. I directly took the program written in x86 assembly on the Internet to change this topic (go to: Solving Joseph Ring problem with 80x86 assembly ). The data segment is divided into two parts. The FLAG segment marks the column and the RESULT records the column label.

Here is a Joseph problem solver with 10 people in a circle and listed at 4:00.

AREA COPY, CODE, READONLY ENTRY START LDR R8, =RESULT LDR R6, =FLAG MOV R0, #ten ; There are 10 people in total MOV R1, #four ; Listing number 4 MOV R2, #0 ; Start number MOV R3, #0 ; number off MOV R4, #0 ; Number of people listed MOV R5, #0 ; Used to save the out of line number L1 LDR R7, [R6, R2, LSL #2] ;R7 = value of address (R6+R2*4) CMP R7, #0 ; Detect whether it is out of line BNE NEXT ;If not, go to the next person ADD R3, R3, #one ; If yes, report the number and add one CMP R3, R1 ;Check whether the out of line number has been checked in BNE NEXT ;If not, go to the next person ADD R7, R7, #one ; If yes, the column is marked STR R7, [R6, R2, LSL #2] ; Record back to memory MOV R3, #0 ; Reset the number to zero MOV R5, R2 ;Save list number STR R5, [R8, R4, LSL #2] ADD R4, R4, #one ; Number of people listed plus one CMP R4, R0 ;Check whether the number of people in the queue is equal to the total number of people BEQ EXIT ;If yes, end the program NEXT ADD R2, R2, #one ; Go to the next person CMP R2, R0 ;Check whether the last person is counted BNE L1 ;If not, continue counting MOV R2, #0 ; If yes, the starting number starts from 0 B L1 EXIT B EXIT AREA COPYDATA, DATA, READWRITE FLAG DCD 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 RESULT DCD 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 END

3. Joseph problem (mixed C and ARM)

Change the above assembler into a mixture of C language and ARM assembly. Note that if LDR R8, [result] is written as LDR R8, =result, an error will be reported during compilation. I don't know why.

I have debugged, but I can't find the function entry all the time, and the PC pointer always points to the initial position, so I can't know whether the program is correct or not. It is useless to set Image entry point in Edit - > debugrel settings. I hope this problem can be solved one day.

#include <stdio.h> #include <stdlib.h> int _main() { int num[100]; int n=10, m=4, i; int count, locate, sum; int result[100]; for(i = 0; i < n; i++) num[i] = 0; __asm { LDR R8, [result] LDR R6, [num] LDR R0, [n] LDR R1, [m] LDR R2, [locate] LDR R3, [count] LDR R4, [sum] LOOP: LDR R7, [R6, R2] CMP R7, #0 BNE NEXT ADD R3, R3, #1 CMP R3, R1 BNE NEXT ADD R7, R7, #1 MOV R3, #0 ADD R4, R4, #1 ADD R8, R8, R4 STR R2, [R8] CMP R4, R0 NEXT: ADD R2, R2, #1 CMP R2, R0 BNE LOOP MOV R2, #0 B LOOP } for(i = 0; i < n; i++) printf("%d ", result[i]); return 0; }

29 October 2021, 22:38 | Views: 6651

Add new comment

For adding a comment, please log in
or create account

0 comments