Question

In: Computer Science

Language Assembly ( required) Write and test a function, drawshape. The function has 2 parameters, the...

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.

Solutions

Expert Solution

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


Related Solutions

Language Assembly ( required) Write and test a function, drawshape. The function has 2 parameters, the...
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.
Write hack assembly language code for function (declaration) call (a function) return (from a function)
Write hack assembly language code for function (declaration) call (a function) return (from a function)
In MIPS assembly language, write a function that will display the max and min value in...
In MIPS assembly language, write a function that will display the max and min value in an array. Then write a function to calculate and display the average of all values in an array. This must be done in MIPS assembly language.
Q1: A. WRITE AN ASSEMBLY LANGUAGE PROGRAM TO EXCHANGE 16-BIT NUMBERS B. WRITE AN ASSEMBLY LANGUAGE...
Q1: A. WRITE AN ASSEMBLY LANGUAGE PROGRAM TO EXCHANGE 16-BIT NUMBERS B. WRITE AN ASSEMBLY LANGUAGE PROGRAM TO SOLVE THE EQUATION Z=A+B-(C/D)+E please write the answer separately part A its own code and part B its own code this is microprocessor the ASSEMBLY LANGUAGE emu8086 should be written like this EX: mov ax,100h mov bx,200h etc
arms64 assembly language Write a function to read a Sudoku board from an input string. The...
arms64 assembly language Write a function to read a Sudoku board from an input string. The input string must be exactly 81 characters long (plus the terminating null that marks the end of the string) and contains digits and dots (the `.` character represents an unmarked position). The input contains all 9 rows packed together. For example, a Sudoku board that looks like this: ``` ..7 ... ... 6.4 ... ..3 ... .54 ..2 ... .4. ... 9.. ... ..5...
Write a MIPS assembly language procedure that implements the Towers of Hanoi recursive function given the...
Write a MIPS assembly language procedure that implements the Towers of Hanoi recursive function given the following declaration: void towers(int n, char source, char dest, char spare); The function outputs a message describing each move. The source, destination, and spare poles are indicated with a character identifier of your choosing ('A', 'B', 'C' are common). Write a MIPS assembly language program that demonstrates the Towers of Hanoi procedure. Your program should ask the user for the number of disks. The...
Use MARS to write and simulate a MIPS assembly language program to implement the strlen function....
Use MARS to write and simulate a MIPS assembly language program to implement the strlen function. The program should ask for a user's input and print the length of the user's input. Write the main function to call strlen. The main function should: - Prompt the user for input - Pass that input to strlen using registers $a0. - Preserve (i.e. push onto the stack) any T registers that the main function uses. The strlen function should: - Preserve any...
C++ Write the definition of a function minMax that has five parameters. The first three parameters...
C++ Write the definition of a function minMax that has five parameters. The first three parameters are integers. The last two are set by the function to the largest and smallest of the values of the first three parameters. The function does not return a value. The function can be used as follows: int a=31, b=5, c=19 big, small; minMax(a,b,c,&big,&small); /* big is now 31 */ /* small is now 5 */ **ONLY THE FUNCTION
"sum_between" function Write a function named "sum_between" that receives 2 parameters - "start" (an int) and...
"sum_between" function Write a function named "sum_between" that receives 2 parameters - "start" (an int) and "end" (an int). It should return the sum (total) of all of the integers between (and including) "start" and "end". If "end" is less than "start", the function should return -1 instead. e.g. if you give the function a start of 10 and an end of 15, it should return 75 (i.e. 10+11+12+13+14+15)
Write an MSP430 assembly language program that implements the following 2 algorithms: 2) a macro called...
Write an MSP430 assembly language program that implements the following 2 algorithms: 2) a macro called "vdot" that calculates the "dot product" of two vectors "a" and "b", implemented as “arrays” (following the “C” language convention), of 3 elements. the macro should receive 2 pointers to the first element of each vector and return the result in R13.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT