Question

In: Computer Science

You must write the code in 80x86 assembly language and must attach a screenshot of the...

You must write the code in 80x86 assembly language and must attach a screenshot of the output.

#

Pennies for Pay

Write a program that calculates how much a person earns in a month if the salary is one penny the first day, two pennies the second day, four pennies the third day, and so on with the daily pay doubling each day the employee works. The program should ask the user for the number of days the employee worked during the month, validate that it is between 1 and 31, and then display a table showing how much the salary was for each day worked, as well as the total pay earned for the month. The output should be displayed in pennies points, not in pennies.

Weight Loss

If moderately active persons cut their calorie intake by 500 calories a day, they can typically lose about 4 pounds a month. Write a program that has the users enter their starting weight and then creates and displays a table showing what their expected weight will be at the end of each month for the next 6 months if they stay on this diet.

Calories Burned

Running on a particular treadmill, you burn 4 calories per minute. Write a program that uses a loop to display the number of calories burned after 5, 10, 15, 20, 25, and 30 minutes.

Solutions

Expert Solution

Below is the assembly language code for given problem.

push    rbp

        mov     rbp, rsp

        sub     rsp, 16

        lea     rax, [rbp-12]

        mov     rsi, rax

        mov     edi, OFFSET FLAT:_ZSt3cin

        call    std::basic_istream<char, std::char_traits<char> >::operator>>(int&)

        mov     DWORD PTR [rbp-4], 1

        mov     DWORD PTR [rbp-8], 1

        mov     esi, OFFSET FLAT:.LC0

        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 const*)

        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     eax, DWORD PTR [rbp-12]

        test    eax, eax

        jle     .L2

        mov     eax, DWORD PTR [rbp-12]

        cmp     eax, 31

        jg      .L2

.L3:

        mov     eax, DWORD PTR [rbp-12]

        cmp     DWORD PTR [rbp-4], eax

        jg      .L2

        mov     eax, DWORD PTR [rbp-4]

        mov     esi, eax

        mov     edi, OFFSET FLAT:_ZSt4cout

        call    std::basic_ostream<char, std::char_traits<char> >::operator<<(int)

        mov     esi, OFFSET FLAT:.LC1

        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*)

        mov     rdx, rax

        mov     eax, DWORD PTR [rbp-8]

        mov     esi, eax

        mov     rdi, rdx

        call    std::basic_ostream<char, std::char_traits<char> >::operator<<(int)

        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> >&))

        sal     DWORD PTR [rbp-8]

        add     DWORD PTR [rbp-4], 1

        jmp     .L3

.L2:

        mov     eax, 0

        leave

        ret

Pic of output shown below:

For second question below is the assembly code:

push    rbp

        mov     rbp, rsp

        sub     rsp, 16

        lea     rax, [rbp-8]

        mov     rsi, rax

        mov     edi, OFFSET FLAT:_ZSt3cin

        call    std::basic_istream<char, std::char_traits<char> >::operator>>(int&)

        mov     DWORD PTR [rbp-4], 1

        mov     esi, OFFSET FLAT:.LC0

        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 const*)

        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> >&))

.L3:

        cmp     DWORD PTR [rbp-4], 6

        jg      .L2

        mov     eax, DWORD PTR [rbp-4]

        mov     esi, eax

        mov     edi, OFFSET FLAT:_ZSt4cout

        call    std::basic_ostream<char, std::char_traits<char> >::operator<<(int)

        mov     esi, OFFSET FLAT:.LC1

        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*)

        mov     rdx, rax

        mov     eax, DWORD PTR [rbp-8]

        sub     eax, 4

        mov     esi, eax

        mov     rdi, rdx

        call    std::basic_ostream<char, std::char_traits<char> >::operator<<(int)

        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> >&))

        add     DWORD PTR [rbp-4], 1

        mov     eax, DWORD PTR [rbp-8]

        sub     eax, 4

        mov     DWORD PTR [rbp-8], eax

        jmp     .L3

.L2:

        mov     eax, 0

        leave

        ret

Output:

for question 3 below is the assembly language code:

push    rbp

        mov     rbp, rsp

        sub     rsp, 16

        mov     esi, OFFSET FLAT:.LC0

        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 const*)

        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     DWORD PTR [rbp-4], 1

.L3:

        cmp     DWORD PTR [rbp-4], 6

        jg      .L2

        mov     edx, DWORD PTR [rbp-4]

        mov     eax, edx

        sal     eax, 2

        add     eax, edx

        mov     esi, eax

        mov     edi, OFFSET FLAT:_ZSt4cout

        call    std::basic_ostream<char, std::char_traits<char> >::operator<<(int)

        mov     esi, OFFSET FLAT:.LC1

        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*)

        mov     rdx, rax

        mov     eax, DWORD PTR [rbp-4]

        sal     eax, 2

        mov     esi, eax

        mov     rdi, rdx

        call    std::basic_ostream<char, std::char_traits<char> >::operator<<(int)

        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> >&))

        add     DWORD PTR [rbp-4], 1

        jmp     .L3

.L2:

        mov     eax, 0

        leave

        ret

Thank You.


Related Solutions

MUST BE WRITTEN IN ASSEMBLY LANGUAGE ONLY AND MUST COMPILE IN VISUAL STUDIO You will write...
MUST BE WRITTEN IN ASSEMBLY LANGUAGE ONLY AND MUST COMPILE IN VISUAL STUDIO You will write a simple assembly language program that performs a few arithmetic operations. This will require you to establish your programming environment and create the capability to assemble and execute the assembly programs that are part of this course. Your \student ID number is a 7-digit number. Begin by splitting your student ID into two different values. Assign the three most significant digits to a variable...
Write hack assembly language code for eq lt gt
Write hack assembly language code for eq lt gt
write a program for the microcontroller-msp430fr6989 using code composer studio not assembly language. write a code...
write a program for the microcontroller-msp430fr6989 using code composer studio not assembly language. write a code that transmits a single character and lights the red LED upon receiving that character. The board will "talk" to itself. The green LED should turn on whenever a message is sent and the LCD will display the message being received.
write a assembly language program to convert GRAY to BCD code in 8051
write a assembly language program to convert GRAY to BCD code in 8051
This is to be done with MIPS assembly language. Write MIPS code which is equivalent to...
This is to be done with MIPS assembly language. Write MIPS code which is equivalent to the follow java program: int day = (int)(Math.random() * 7); switch (day) { case 1: System.out.println(“Monday”); break case 2: System.out.println(“Tuesday”); break case 3: System.out.println(“Wednesday”); break case 4: System.out.println(“Thursday”); break case 5: System.out.println(“Friday”); break case 6: System.out.println(“Saturday”); break case 0: System.out.println(“Sunday”); break }
Write a MIPS assembly language to transpose a square integer matrix in code
Write a MIPS assembly language to transpose a square integer matrix in code
Need to code this is assembly language. Using the windows32 framework, write a procedure to read...
Need to code this is assembly language. Using the windows32 framework, write a procedure to read a string and shift each character of the string by one. As an example, if your input string is Abcz, your output should be Bcda. Note that you must test your string for non-alphabetic characters (such as numbers and special characters). If there are non-alphabetic characters, you should terminate your program with an appropriate message. You should display your converted string using the output...
Write an assembly language program code to clear and set bit 7th and 19th in a...
Write an assembly language program code to clear and set bit 7th and 19th in a 32-bit variable called N.
Using x86 assembly language, create a flowchart and write an example of code that will sort...
Using x86 assembly language, create a flowchart and write an example of code that will sort 2 arrays of unsigned doubleword integers in ascending order and output the largest element in each array. Any sorting procedure can be used, but this procedure must be called twice for each array. The first time it is called, the first array should be sorted and the second time it is called, the second array must be sorted. As well as outputting which is...
Must use AT&T x64/GNU Assembly syntax. Write an assembly language program that reads in two integers,...
Must use AT&T x64/GNU Assembly syntax. Write an assembly language program that reads in two integers, A and B, and uses them to compute the following expressions. You must use the same values for A and B throughout all three expressions. 1) A * 5 2) (A + B) - (A / B) 3) (A - B) + (A * B)
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT