85.0k views
3 votes
For this assignment you are to write an Arm assembly language program that does the following:

- Stores on the stack a list of three words of memory initialized to the values 10,−20,30 in that order.
- At the end of the program, register r0 should hold the value of
first + second * third
where first, second, and third refer to the first, second, and third elements of the list.
- Note that your program must work correctly even if the values stored in the list are changed.

User Mrganser
by
7.2k points

1 Answer

5 votes

Final answer:

To solve the ARM assembly language task, the program must initialize a stack with values, perform arithmetic operations, and store the result in a register. The program provided in the example demonstrates how to do this using ARM assembly instructions, with special consideration for the stack pointer and memory assignments.

Step-by-step explanation:

The assignment requires you to write an assembly language program for the ARM architecture that performs specific operations using a stack. You need to initialize a stack with three words, corresponding to values 10, -20, and 30, and then compute an expression using these values. The result of the expression first + second * third should be stored in register r0 by the end of the program. Here's a basic template on how such a program could look like in ARM assembly:

AREA stack_program, CODE, READONLY
ENTRY

LDR r1, =10
STR r1, [sp, #-4]!
LDR r1, =-20
STR r1, [sp, #-4]!
LDR r1, =30
STR r1, [sp, #-4]!

LDR r1, [sp], #4
LDR r2, [sp], #4
LDR r3, [sp], #4

MUL r2, r2, r3
ADD r0, r1, r2

END

This is a simplified version and assumes the stack pointer (sp) is set correctly and there is enough space on the stack. Please double-check and verify the syntax and correctness with your specific ARM assembly language tools and conventions.

User Ivan Bartsov
by
8.0k points