Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

C program, Write a program that computes M0 = (M0 + M1) * (M2 + (M1 * M3)). M0, M1, M2, and M3 are memory

C program, Write a program that computes M0 = (M0 + M1) * (M2 + (M1 * M3)).

M0, M1, M2, and M3 are memory addresses. Memory at each address contains a value to be used in computation.

image text in transcribedtemplete

__attribute__(( naked )) void asm_test(int *a, int *b, int *c, int *d) { // write your code between push and pop instructions asm volatile ( "push {r4, r5, r6, r7} " // do not remove "ldr r7, [r0] " // example assembly code - replace with your own code "adds r4, r7, r2 " // example assembly code replace with your own code // add more code here "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 main() { int m0; int m1; int m2; int m3; m0 = 1; m1 = 2; m2 = 3; m3 = 4; asm_test(&m0, &m1, &m2, &m3); if(m0 != 33) fail(); m0 = 8; m1 = 5; m2 = 6; m3 = 21; asm_test(&m0, &m1, &m2, &m3); if(m0 != 1443) fail(); m0 = 3; m1 = 4; m2 = 5; m3 = 1; asm_test(&m0, &m1, &m2, &m3); if(m0 != 63) fail(); m0 = 3; m1 = 5; m2 = 7; m3 = 8; asm_test(&m0, &m1, &m2, &m3); if(m0 != 376) fail(); m0 = 33; m1 = 22; m2 = 11; m3 = 0; asm_test(&m0, &m1, &m2, &m3); if(m0 != 605) fail(); m0 = 42; m1 = 55; m2 = 12; m3 = 1; asm_test(&m0, &m1, &m2, &m3); if(m0 != 6499) fail(); ok(); return 0; } 
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: . . LDR Rd, [Rn] - Read a word from memory address that is held in Rn to register Rd. STR Rn, [Rd] Store a word from register Rn to memory address that is held in Rd. 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 RO R7. In the LPCXpresso test program the memory addresses are passed to your program in registers RO - R3. RO contains Mo, R1 contains M1, etc. Note that Mo and M1 are addresses (pointers) so you need to use LDR to copy the value from memory to another register. You can overwrite the values in registers RO R7 if needed. You need to store the result of computation to the address MO, that was passed to your program in RO so you need to keep this pointer safe throughout your computations. This time your program does not return a value, return type is void, because we store the result using a pointer. Example: LDR R7, [RO] // copies a word from memory address in register RO to register R7. ADDS R4, R7, R2 // R4 = R7 + R2 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: . . LDR Rd, [Rn] - Read a word from memory address that is held in Rn to register Rd. STR Rn, [Rd] Store a word from register Rn to memory address that is held in Rd. 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 RO R7. In the LPCXpresso test program the memory addresses are passed to your program in registers RO - R3. RO contains Mo, R1 contains M1, etc. Note that Mo and M1 are addresses (pointers) so you need to use LDR to copy the value from memory to another register. You can overwrite the values in registers RO R7 if needed. You need to store the result of computation to the address MO, that was passed to your program in RO so you need to keep this pointer safe throughout your computations. This time your program does not return a value, return type is void, because we store the result using a pointer. Example: LDR R7, [RO] // copies a word from memory address in register RO to register R7. ADDS R4, R7, R2 // R4 = R7 + R2

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions

Question

=+ how might this lead to faster growth in productivity?

Answered: 1 week ago