Question

In 32-bit MASM assembly language, write a procedure that accelpts an offset and a lenght of...

In 32-bit MASM assembly language, write a procedure that accelpts an offset and a lenght of an array. The procedure return the sum of every 3rd elements( beginning at the 0th elements). Example: {1,2,3,4,5,6,7,8} 1+4+7=12
0 0
Add a comment Improve this question Transcribed image text
Answer #1

Given that

in 32 bit MASM assembly language and the procedure return the sum of every 3rd elements.

Given, Asked to write an assembly language code to perform the addition of every 3rd offset value and returns the sum.

Explanation: I used x86-64 GCC to compile this code. Hope this is the one you are looking.

Assembly Code:
sumOffset(int*, int):
push %rbp
mov %rbp, %rsp
mov QWORD PTR [%rbp-24], %rdi
mov DWORD PTR [%rbp-28], %esi
mov DWORD PTR [%rbp-8], 0
mov DWORD PTR [%rbp-4], 0
jmp .L2
.L3:
mov %eax, DWORD PTR [%rbp-4]
mov DWORD PTR [%rbp-36], %eax
mov DWORD PTR [%rbp-40], 1431655766
mov %eax, DWORD PTR [%rbp-40]
imul DWORD PTR [%rbp-36]
mov %ecx, %edx
mov %eax, DWORD PTR [%rbp-36]
sar %eax, 31
mov %edx, %ecx
sub %edx, %eax
mov DWORD PTR [%rbp-32], %edx
mov %eax, DWORD PTR [%rbp-32]
add %eax, %eax
add %eax, DWORD PTR [%rbp-32]
mov %edx, DWORD PTR [%rbp-36]
sub %edx, %eax
mov DWORD PTR [%rbp-32], %edx
cmp DWORD PTR [%rbp-32], 0
jne .L4
mov %eax, DWORD PTR [%rbp-4]
cdqe
sal %rax, 2
add %rax, QWORD PTR [%rbp-24]
mov %eax, DWORD PTR [%rax]
add DWORD PTR [%rbp-8], %eax
.L4:
inc DWORD PTR [%rbp-4]
.L2:
mov %eax, DWORD PTR [%rbp-4]
cmp %eax, DWORD PTR [%rbp-28]
jl .L3
mov %eax, DWORD PTR [%rbp-8]
leave
ret
.LC0:
.string "%d"
main:
push %rbp
mov %rbp, %rsp
sub %rsp, 416
mov DWORD PTR [%rbp-12], 3
mov DWORD PTR [%rbp-8], 0
lea %rsi, [%rbp-16]
mov %edi, OFFSET FLAT:.LC0
mov %eax, 0
call scanf
mov DWORD PTR [%rbp-4], 0
jmp .L9
.L10:
mov %eax, DWORD PTR [%rbp-4]
lea %rdx, [%rbp-416]
cdqe
sal %rax, 2
lea %rsi, [%rdx+%rax]
mov %edi, OFFSET FLAT:.LC0
mov %eax, 0
call scanf
inc DWORD PTR [%rbp-4]
.L9:
mov %eax, DWORD PTR [%rbp-16]
cmp DWORD PTR [%rbp-4], %eax
jl .L10
mov %esi, DWORD PTR [%rbp-16]
lea %rdi, [%rbp-416]
call sumOffset(int*, int)
mov %esi, %eax
mov %edi, OFFSET FLAT:.LC0
mov %eax, 0
call printf
mov %eax, 0
leave
ret

Add a comment
Know the answer?
Add Answer to:
In 32-bit MASM assembly language, write a procedure that accelpts an offset and a lenght of...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT