Question: Cortex-M3 assembly language All ALU-operations are performed on registers. Data transfer is done between a register and a memory location. This is real assembly language
Cortex-M3 assembly language
All ALU-operations are performed on registers. Data transfer is done between a register and a memory location. This is real assembly language that can (and must) be tested on LPCXpresso before submitting your answer. Attach your version of asm_test() in your answer.
Following instructions are available:
MOV Rd, Rn Copy a word from register Rn to register Rd.
ADDS Rd, Rn, Rm - Add register Rn to register Rm. Result is stored in register Rd. (Rd = Rn + Rm).
MUL Rd, Rn, Rd Multiply register Rn with register Rd. Result is stored in register Rd. (Rd = Rn * Rd).
You can use registers R0 R7. In the LPCXpresso test program the values from M0 M3 are passed to your program in registers R0 R3. R0 contains value from M0, R1 contains value from M1, etc. You can overwrite the values in registers R0 R7 if needed. Your assembly code must copy the result of computations to R0 before returning from the function.
MOV R7, R0 // copies a word register R0 to register R7
ADDS R4, R7, R2 // R4 = R7 + R2
Add the following code before main() of your LPCXpresso project.
Add the following code in main() of your LPCXpresso project to test your assembly code. Set a break point in the fail() and ok() functions to detect errors in the final test. Use instruction stepping mode for initial testing to inspect program behavior after each instruction. Your program works correctly if fail() is not called after any of the tests. Note that printf() does not display the text we print in this configuration. We add that line only to be able set a break point on the line.


_attribute_(( naked )) int asm_test(int vo, int v, int v2, int v3) // write your code between push and pop instructions asm volatile First argument goes to RO, ( second goes to R1 etc. "push {r4, r5, r6, r7} " // do not remove // do not add any code before this comment "mov r7, r3 " // example assembly code - replace with your own code "adds r4, rz, r2 " // example assembly code replace with your own code // add more code here // do not add any code after this comment "pop {r4, r5, r6, r7} " // do not remove "bx lr " // do not remove ); } void fail() { printf("Failed "); // set a break point here while(1); } void ok() { printf("All ok "); // set a break point here while(1); } int mo; int m1; int m2; int m3; = = mo = 1; m1 2; m2 = 3; m3 = 3; 4; mo asm_test(mo, mi, m2, m3); if(mo != 33) fail(); = = mo = 8; m1 5; m2 6; m3 = 21; asm_test(mo, mi, m2, m3); if(mo != 1443) fail(); = = = mo = 3; m1 4; m2 5; m3 1; mo = asm_test(mo, mi, m2, m3); if(mo != 63) fail(); = = = mo = 3; m1 = 5; m2 = 7; m3 8; mo = asm_test(mo, m1, m2, m3); if(mo != 376) fail(); = = = = mo = 33; m1 = 22; m2 11; m3 = 0; 0 asm_test(mo, mi, m2, m3); if(mo != 605) fail(); = mo = 42; m1 42; m1 = 55; m2 12; m3 = 1; mo = asm_test(mo, mi, m2, m3); if(mo != 6499) fail(); ok()
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
