In: Computer Science
Language Assembly ( required)
Write and test a function, drawshape. The function has 2 parameters, the shape's character and the length of the shape's longest line.
draw shape(1, x) looks displays
x
x
draw shape(2, y) displays
yy
y
yy
draw shape(3, z) displays
zzz
zz
z
zz
zzz
and so on.
draw_shape(int, char):
push rbp
mov rbp, rsp
sub rsp, 32
mov DWORD PTR [rbp-20], edi
mov eax, esi
mov BYTE PTR [rbp-24], al
cmp DWORD PTR [rbp-20], 1
jne .L2
movsx eax, BYTE PTR [rbp-24]
mov esi, eax
mov edi, OFFSET FLAT:_ZSt4cout
call std::basic_ostream<char, std::char_traits<char> >& std::operator<< <std::char_traits<char> > (std::basic_ostream<char, std::char_traits<char> >&, char)
mov esi, OFFSET FLAT:_ZSt4endlIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_
mov rdi, rax
call std::basic_ostream<char, std::char_traits<char> >::operator<<(std::basic_ostream<char, std::char_t raits<char> >& (*)(std::basic_ostream<char, std::char_traits<char> >&))
mov rdx, rax
movsx eax, BYTE PTR [rbp-24]
mov esi, eax
mov rdi, rdx
call std::basic_ostream<char, std::char_traits<char> >& std::operator<< <std::char_traits<char> > (std::basic_ostream<char, std::char_traits<char> >&, char)
jmp .L11
.L2:
mov eax, DWORD PTR [rbp-20]
mov DWORD PTR [rbp-4], eax
.L7:
cmp DWORD PTR [rbp-4], 0
jle .L4
mov DWORD PTR [rbp-8], 1
.L6:
mov eax, DWORD PTR [rbp-8]
cmp eax, DWORD PTR [rbp-4]
jg .L5
movsx eax, BYTE PTR [rbp-24]
mov esi, eax
mov edi, OFFSET FLAT:_ZSt4cout
call std::basic_ostream<char, std::char_traits<char> >& std::operator<< <std::char_traits<char> > (std::basic_ostream<char, std::char_traits<char> >&, char)
mov esi, OFFSET FLAT:.LC0
mov rdi, rax
call std::basic_ostream<char, std::char_traits<char> >& std::operator<< <std::char_traits<char> > (std::basic_ostream<char, std::char_traits<char> >&, char const*)
add DWORD PTR [rbp-8], 1
jmp .L6
.L5:
mov esi, OFFSET FLAT:_ZSt4endlIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_
mov edi, OFFSET FLAT:_ZSt4cout
call std::basic_ostream<char, std::char_traits<char> >::operator<<(std::basic_ostream<char, std::char_t raits<char> >& (*)(std::basic_ostream<char, std::char_traits<char> >&))
sub DWORD PTR [rbp-4], 1
jmp .L7
.L4:
add DWORD PTR [rbp-4], 2
.L10:
mov eax, DWORD PTR [rbp-4]
cmp eax, DWORD PTR [rbp-20]
jg .L11
mov DWORD PTR [rbp-8], 1
.L9:
mov eax, DWORD PTR [rbp-8]
cmp eax, DWORD PTR [rbp-4]
jg .L8
movsx eax, BYTE PTR [rbp-24]
mov esi, eax
mov edi, OFFSET FLAT:_ZSt4cout
call std::basic_ostream<char, std::char_traits<char> >& std::operator<< <std::char_traits<char> > (std::basic_ostream<char, std::char_traits<char> >&, char)
mov esi, OFFSET FLAT:.LC0
mov rdi, rax
call std::basic_ostream<char, std::char_traits<char> >& std::operator<< <std::char_traits<char> > (std::basic_ostream<char, std::char_traits<char> >&, char const*)
add DWORD PTR [rbp-8], 1
jmp .L9
.L8:
mov esi, OFFSET FLAT:_ZSt4endlIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_
mov edi, OFFSET FLAT:_ZSt4cout
call std::basic_ostream<char, std::char_traits<char> >::operator<<(std::basic_ostream<char, std::char_t raits<char> >& (*)(std::basic_ostream<char, std::char_traits<char> >&))
add DWORD PTR [rbp-4], 1
jmp .L10
.L11:
nop
leave
ret
please kindly dont downvote the code is correct if have any doubts please comment kinldy please dont downvote