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

Using the following assembler code, please answer this. I need the code in C++ P

ID: 3778299 • Letter: U

Question

Using the following assembler code, please answer this. I need the code in C++ Program style NOT IN ANYOTHER WAY. **ONLY THE FOLLOWING ASSEMBLER CODES MUST BE USED**. Question is listed after the assembler code.

Assembler language as given in Mano, 3rd ed.

Comand machine code Descriptionsymbol I = 0 I=1 _____________________________AND  label 0xxx 8xxx   AND memory word to ACADD   label 1xxx 9xxx ADD memory word to ACLDA   label 2xxx Axxx LoaD memory word to ACSTA   label 3xxx Bxxx STore content of AC in memoryBUN   label 4xxx Cxxx Branch UNconditionallyBSA   label 5xxx Dxxx Branch and SAve return addressISZ   label 6xxx Exxx Increment and Skip if ZeroExample – direct and indirect addressing    ADD X   add value at location X to AC and put result in AC    ADD X I   add value pointed to by value in location X to AC, put result in ACComand machine code Description_____________CLA 7800 CLear ACCLE 7400 CLear ECMA 7200 CoMplement ACCME 7100 CoMplement ECIR 7080 CIrculate Right AC and ECIL 7040 CIrculate Left AC and EINC 7020 INcrement ACSPA 7010 Skip next instruction if AC is >= 0SNA 7008 Skip next instruction if AC is < 0SZA 7004 Skip next instruction if AC is ZeroSZE 7002 Skip next instruction if E is ZeroHLT 7001 HALT ComputerDMP F001 Causes a hex DUmP of memoryTRA F002 Causes a TRAce of the next 100   instructionsLMT F004 LiMiTs the number of instructions   executed to 10,000INP F800 INPut character to AC from file, does not   change the right byteOUT F400 OUTput character from ACSKI F200   SKip on Input flagSKO F100 SKip on Output flagION F080 Turn Interrupt ONIOF F040 Turn Interrupt OFfExample: CLA will clear the AC by setting AC to zero

Assembler directive commandsORG xxxx Gives memory location for beginning of

program. Required at start of all files.

DEC xxx Converts xxx (base 10) to binary and places it in

memory

HEX xxxx Converts xxxx (base 16) to binary and places it

in memoryHEX ‘label Places address of label in memoryENTRY   Indicates next instruction as first instruction to

be executed – only one ENTRY per program

END denotes the end of the program/ comment A / or ; in column 1 makes the line a comment. Text

following an instruction is also treated as a comment.

EXTDEF label    label is defined in this file and referenced in

another fileEXTREF label label if referenced in this file and defined in

another file

The assembler uses labels instead of addresses. Each label (a letter followed by aletter or a digit) must start in column 1 followed by a comma, followed by a space.These labels may then appear in an instruction. In the example below, BACK andNUM are both labels. BACK is a label for an instruction to branch to. NUM is alabel for a data value stored in memory. BACK, LDA   NUM . .   BUN BACK . . NUM,  HEX 2FA3


Setting Up Your bgunix Class Account
You must first execute the cs-config command and join the class directory  $ cs-config  $ class –join cs217r1   (for 10:30 section, cs217r2 for 11:30 section)To change to the class directory after you login, enter the command:  $ cd cs217r1    (or   cd cs217r2   for the 11:30 section)

Entering and EditingTwo editors, pico and vi, are available on bgunix to enter and edit your programs.Type one of these commands to create a new program file or edit an existing one. $ pico filename.src $ vi filename.src


Accessing csos Operating System
To use the assembler on bgunix, enter the command:

$ csos
If this does not work, set up the alias: alias csos=/home/cs/bin/csosYou can assemble, link and run your assembler program in this environment.
Steps for Assembling, Linking and Executing Your Assembler Programcsos:  assem filename.src / To assemble your program. Creates a file called   / filename.obj containing the object code.
csos:  link filename.obj / Creates an executable file called filename.exec   / Loads your program into location specified.csos:  run filename.exec / Runs the executable file filename.exec

Exit
To exit csos enter quit or exit.     csos: quit

Assembler Language Program Example
Type in this command to create an assembler source file: $ pico add2.srcIn the pico editor, type in the assembler language statements below./ This program adds two numbers together and stores the sum.
        ORG    200     Load program starting at loc 200        ENTRY ADD2        LDA    NUM1    Load NUM1 into accumulator        ADD    NUM2    Add NUM1 and NUM2        STA    SUM     Store the sum        DMP        HLTNUM1,   DEC    3NUM2,   DEC    5SUM,    DEC    0        END    ADD2

Exit the editor by pressing the control and x keys together and pressing Enter tosave your program.Run the csos Operating System by typing the command:

$ csos
Assemble, link and execute the assembler program in csos by typing thesecommands at the csos: prompt:csos:  assem add2.src
csos:  link add2.objcsos:  run add2.exec
Type quit or exit to leave csos and enter the pico command again to make anyneeded changes to your program.

QUESTION :-

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)

Explanation / Answer

PART A:

The above given C++ code is converted to assembly code and here x and y values are loaded into r1 and r2 registers and comparsion is done between them and corresponding output will be printed.

MOV r1,=0x08 ;load value 8 into r1 register

MOV r2,=0x0E ; load value 14 into r2 register

CMP r1,r2 ; compare r1,r2

BLE less ;branch if less than or equal to label less

SUB r2,r2,#1 ;if r1 > r2 then r2=r2-1

over B over ;infinte loop to saw the ouput

less ADD r1,r1,r2 ;If r1 <=r2 then r1=r1+r2

B over

END

PART B:

#include<iostream>

using namespace std;

void main()

{

int number,multiplier;

int PROD=0;

cout << "Enter the two numbers";

cin >> number >> multiplier;

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

{

PROD=PROD+number; // adding number to itself for multiplier number of terms

}

cout << "answer is :" << PROD;

}