Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

I need with the following C++ commands :- ORG DEC HEX HEX\' EXTDEF EXTREF BACK,

ID: 3778098 • Letter: I

Question

I need with the following C++ commands :-

ORG

DEC

HEX

HEX'

EXTDEF

EXTREF

BACK, LDA NUM BUN

BACK NUM, HEX 2FA3

For each program below, type your assembler language code in a file in your CS2170 class account on bgunix and assemble, link and run it in csos. Name the files proj5a.src and proj5b.src. Add header comments with your name, project number, CS2170 and your class time. Also include comments describing the purpose of your program. Include descriptive comments to explain your lines of code. For each program, include a DMP instruction at the end of the program before the HLT instruction.

Debug and test your code until you are sure your results are correct. Then make a photo of each program using the commands below. On your print out, label and highlight or circle the memory location(s) in the memory dump that show your operands and results. Print the photo files and turn them in.

     

          $ photo proj5x.log                    ( to start the photo utility – e.g., proj5a.log for part a)

          $ pwd                                      ( to identify your current directory – should be the class dir)

          $ ls -l                                      ( to list all files in your directory – lower case Ls not ones)

          $                                              ( to leave a few blank lines press the Enter key )

          $

            $ csos

                        csos: assem proj5x.src

                        csos: link proj5x.obj

                        csos: run proj5x.exec

                        csos: quit                                                          ( to leave csos - may also type exit) )

          $ exit                                       ( to end the photo session)

Part A. Translate this C++ program into assembly language.   (10 pt)

      int x = 8, y = 14;                 // Switch the values of x and y and set them to the same value to test all

                                                // branches of your code

      if (x <= y)

            x = x + y;

      else

            y = y - 1;

Part B. Write a program to multiply two positive numbers using the repeated addition method (not shifting and adding as shown in the textbook). For example, to multiply 9 times 5, the program calculates the product by adding 9 five times ( 9 + 9 + 9 + 9 + 9). Store the result in an operand named PROD.   (10 pt)

To receive full credit for this assignment:

1.   All of the commands shown must be typed in during the photo session.

2.   An electronic copy of your photo, .src and related files must be in your bgunix CS2170 class directory by the due time.

3.   Printouts must be stapled and turned in at the beginning of class on the due date. Before coming to class, please staple all printouts and the Grade Sheet together with the Grade Sheet on the front to turn in.

4.   Late programs are not accepted. Partial credit is given so turn in a printout of your photo log files by the due time even if the program is not completed.

CS2170 Grade Sheet – Project 5

Due: Friday, December 2, 2016

Name _________________________________________                                    Class time_____________

_______        Files named correctly and in your class directory by the due time. Printouts with Grade Sheet stapled on top turned in. No credit given unless both printed and electronic copies are turned in on time.

_______        (3)     Part A – includes header comments and descriptive inline comments.

_______        (7)     Part A – correctly implements if operation. Operands and results labeled and highlighted or circled on printout.

_______        (3)     Part B – includes header comments and descriptive inline comments.

_______        (7)     Part B – correctly multiplies two positive numbers using the repeated addition method. Operands and results labeled and highlighted or circled on printout.

_______        (20)    Total Points

Explanation / Answer

PART A

.Ltext0:

                   .globl main

main:

.LFB0:

                   .cfi_startproc

                   pushq         %rbp

                            .cfi_def_cfa_offset 16

                            .cfi_offset 6, -16

                   movq %rsp, %rbp

                            .cfi_def_cfa_register 6

                  movl $8, -8(%rbp)

                   movl $14, -4(%rbp)

                   movl -8(%rbp), %eax

                   cmpl -4(%rbp), %eax

                   jg     .L2

                   movl -4(%rbp), %eax

                     addl %eax, -8(%rbp)

                   jmp .L3

             .L2:

                   subl   $1, -4(%rbp)

             .L3:

                   movl $0, %eax

                 popq   %rbp

                   .cfi_def_cfa 7, 8

                   ret

                   .cfi_endproc

.LFE0:

.Letext0:

PART B

Long int multiply (int a, int b)

{

long int PROD=0;

for (int i=0; i<b; i++)

{

       PROD+=a;

}

return PROD;

}