Objectives Learn how to access the memory using the Nios Assembly language Learn
ID: 3788209 • Letter: O
Question
Objectives Learn how to access the memory using the Nios Assembly language Learn how to use the stack and subroutines with the Nios Assembly language Useful References on Canvas Lecture notes on the Nios Assembly language Altera Nios Processor Document Altera Nios Instruction Document Assembly Subroutines In this lab, we write a program to calculate the following function f, where A and B are one dimensional arrays each with n 32-bit signed integers, and C and D are one-dimensional arrays each with m 32-bit signed integers. The result of function f is a 32-bit signed integer. f(n, A, B, m, C, D) = g(n. A, B) + g(m, C, D) Function g is defined as follows, where X and Y are one-dimensional arrays with each k 32-bit signed integers. The result of function g is a 32-bit signed integer. g(k, X, Y) = X * Y = X[0]*Y[0] + X[1]*Y[1] + ... + X[k - 1]*Y[k - 1] Arrays A, B, C, and D will be defined in the data section of your program. When your program finishes, the value of register r2 should be the result of function f.Explanation / Answer
num(int, int*, int*):
push rbp
mov rbp, rsp
mov DWORD PTR [rbp-20], edi
mov QWORD PTR [rbp-32], rsi
mov QWORD PTR [rbp-40], rdx
mov DWORD PTR [rbp-4], 0
mov DWORD PTR [rbp-8], 0
.L3:
mov eax, DWORD PTR [rbp-8]
cmp eax, DWORD PTR [rbp-20]
jge .L2
mov eax, DWORD PTR [rbp-8]
cdqe
lea rdx, [0+rax*4]
mov rax, QWORD PTR [rbp-32]
add rax, rdx
mov edx, DWORD PTR [rax]
mov eax, DWORD PTR [rbp-8]
cdqe
lea rcx, [0+rax*4]
mov rax, QWORD PTR [rbp-40]
add rax, rcx
mov eax, DWORD PTR [rax]
imul eax, edx
add DWORD PTR [rbp-4], eax
add DWORD PTR [rbp-8], 1
jmp .L3
.L2:
mov eax, DWORD PTR [rbp-4]
pop rbp
ret
main:
push rbp
mov rbp, rsp
push rbx
sub rsp, 304
mov DWORD PTR [rbp-12], 10
mov DWORD PTR [rbp-16], 12
lea rdx, [rbp-120]
lea rcx, [rbp-72]
mov eax, DWORD PTR [rbp-12]
mov rsi, rcx
mov edi, eax
call num(int, int*, int*)
mov ebx, eax
lea rdx, [rbp-312]
lea rcx, [rbp-184]
mov eax, DWORD PTR [rbp-16]
mov rsi, rcx
mov edi, eax
call num(int, int*, int*)
add eax, ebx
mov DWORD PTR [rbp-20], eax
mov eax, 0
add rsp, 304
pop rbx
pop rbp
ret
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.