Question

Problem 1: (20 marks) Part 1: (15 points) Compile the RISC-V assembly code for the following C code. Assume that n and k are

please code using risc-v language and make it as simple as possible

0 0
Add a comment Improve this question Transcribed image text
Answer #1

//RISC-V assembly code for the above-given question

//the execution program following as

//the code as follows fo rthe above given question

.file "code.cpp"
.text
.section .rodata
.type _ZStL19piecewise_construct, @object
.size _ZStL19piecewise_construct, 1
_ZStL19piecewise_construct:
.zero 1
.local _ZStL8__ioinit
.comm _ZStL8__ioinit,1,1
.text
.globl _Z4funcii
.type _Z4funcii, @function
_Z4funcii:
.LFB1493:
.cfi_startproc
pushq %rbp
.cfi_def_cfa_offset 16
.cfi_offset 6, -16
movq %rsp, %rbp
.cfi_def_cfa_register 6
subq $16, %rsp
movl %edi, -4(%rbp)
movl %esi, -8(%rbp)
cmpl $18, -4(%rbp)
jle .L2
movl $0, %eax
jmp .L3
.L2:
cmpl $1, -4(%rbp)
jg .L4
movl $1, %eax
jmp .L3
.L4:
cmpl $2, -8(%rbp)
jg .L5
movl -4(%rbp), %eax
jmp .L3
.L5:
cmpl $17, -8(%rbp)
jle .L6
movl $1, %eax
jmp .L3
.L6:
cmpl $3, -4(%rbp)
jg .L7
movl $5, %eax
jmp .L3
.L7:
movl -8(%rbp), %eax
leal 1(%rax), %edx
movl -4(%rbp), %eax
subl $2, %eax
movl %edx, %esi
movl %eax, %edi
call _Z4funcii
cvtsi2sd %eax, %xmm0
movsd .LC0(%rip), %xmm1
mulsd %xmm1, %xmm0
movsd %xmm0, -16(%rbp)
movl -8(%rbp), %eax
leal -3(%rax), %edx
movl -4(%rbp), %eax
addl $1, %eax
movl %edx, %esi
movl %eax, %edi
call _Z4funcii
cvtsi2sd %eax, %xmm0
movsd .LC1(%rip), %xmm1
mulsd %xmm1, %xmm0
movsd -16(%rbp), %xmm1
addsd %xmm0, %xmm1
cvtsi2sd -8(%rbp), %xmm0
movsd .LC2(%rip), %xmm2
mulsd %xmm2, %xmm0
addsd %xmm0, %xmm1
movl -4(%rbp), %eax
leal 3(%rax), %edx
testl %eax, %eax
cmovs %edx, %eax
sarl $2, %eax
cvtsi2sd %eax, %xmm0
addsd %xmm1, %xmm0
cvttsd2si %xmm0, %eax
.L3:
leave
.cfi_def_cfa 7, 8
ret
.cfi_endproc
.LFE1493:
.size _Z4funcii, .-_Z4funcii
.globl main
.type main, @function
main:
.LFB1494:
.cfi_startproc
pushq %rbp
.cfi_def_cfa_offset 16
.cfi_offset 6, -16
movq %rsp, %rbp
.cfi_def_cfa_register 6
subq $16, %rsp
movl $14, -8(%rbp)
movl $14, -4(%rbp)
movl -4(%rbp), %edx
movl -8(%rbp), %eax
movl %edx, %esi
movl %eax, %edi
call _Z4funcii
movl $0, %eax
leave
.cfi_def_cfa 7, 8
ret
.cfi_endproc
.LFE1494:
.size main, .-main
.type _Z41__static_initialization_and_destruction_0ii, @function
_Z41__static_initialization_and_destruction_0ii:
.LFB1975:
.cfi_startproc
pushq %rbp
.cfi_def_cfa_offset 16
.cfi_offset 6, -16
movq %rsp, %rbp
.cfi_def_cfa_register 6
subq $16, %rsp
movl %edi, -4(%rbp)
movl %esi, -8(%rbp)
cmpl $1, -4(%rbp)
jne .L12
cmpl $65535, -8(%rbp)
jne .L12
leaq _ZStL8__ioinit(%rip), %rdi
call _ZNSt8ios_base4InitC1Ev@PLT
leaq __dso_handle(%rip), %rdx
leaq _ZStL8__ioinit(%rip), %rsi
movq _ZNSt8ios_base4InitD1Ev@GOTPCREL(%rip), %rax
movq %rax, %rdi
call __cxa_atexit@PLT
.L12:
nop
leave
.cfi_def_cfa 7, 8
ret
.cfi_endproc
.LFE1975:
.size _Z41__static_initialization_and_destruction_0ii, .-_Z41__static_initialization_and_destruction_0ii
.type _GLOBAL__sub_I__Z4funcii, @function
_GLOBAL__sub_I__Z4funcii:
.LFB1976:
.cfi_startproc
pushq %rbp
.cfi_def_cfa_offset 16
.cfi_offset 6, -16
movq %rsp, %rbp
.cfi_def_cfa_register 6
movl $65535, %esi
movl $1, %edi
call _Z41__static_initialization_and_destruction_0ii
popq %rbp
.cfi_def_cfa 7, 8
ret
.cfi_endproc
.LFE1976:
.size _GLOBAL__sub_I__Z4funcii, .-_GLOBAL__sub_I__Z4funcii
.section .init_array,"aw"
.align 8
.quad _GLOBAL__sub_I__Z4funcii
.section .rodata
.align 8
.LC0:
.long 0
.long 1074397184
.align 8
.LC1:
.long 0
.long 1071644672
.align 8
.LC2:
.long 0
.long 1074003968
.hidden __dso_handle
.ident "GCC: (Ubuntu 7.3.0-16ubuntu3) 7.3.0"
.section .note.GNU-stack,"",@progbits

//End of program

-------------------------------------------------------------------------------------------------------

%%%%%%%%%%%% PLEASE GIVE ME POSITIVE RATING%%%%%%%%%%%%%%%%%

Add a comment
Know the answer?
Add Answer to:
Problem 1: (20 marks) Part 1: (15 points) Compile the RISC-V assembly code for the following C co...
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