Question

In: Computer Science

Write an assembly program using the super simple cpu instruction set for the following problem. Take...

  1. Write an assembly program using the super simple cpu instruction set for the following problem.

Take input an integer from the user. Output three times the input to the output box.

For example, if the user inputs 10 (base-10) then output box should show 30 (base-10).

Hint: 3 * p can be calculated by doing p+p+p.

ONLY write your assembly instructions here.

Solutions

Expert Solution

Every PC has a microchip that deals with the PC's arithmetical, sensible, and control exercises.

Every group of processors has its own arrangement of guidelines for dealing with different activities, for example, getting contribution from console, showing data on screen and performing different positions. These arrangement of directions are called 'machine language guidelines'.

A processor sees just machine language directions, which are strings of 1's and 0's. Nonetheless, machine language is excessively dark and complex for utilizing in programming advancement. Thus, the low-level low level computing construct is intended for a particular group of processors that speaks to different directions in emblematic code and a more justifiable structure.

Preferences of Assembly Language

  • Having a comprehension of low level computing construct makes one mindful of −
  • How programs interface with OS, processor, and BIOS;
  • How information is spoken to in memory and other outer gadgets;
  • How the processor gets to and executes guidance;
  • How guidelines access and cycle information;
  • How a program gets to outside gadgets.
  • Different preferences of utilizing low level computing construct are −
  • It requires less memory and execution time;
  • It permits equipment explicit complex positions in a simpler manner;
  • It is reasonable for time-basic positions;
  • It is generally appropriate for composing interfere with administration schedules and other memory occupant programs.

Fundamental Features of PC Hardware

The fundamental interior equipment of a PC comprises of processor, memory, and registers. Registers are processor parts that hold information and address. To execute a program, the framework duplicates it from the outer gadget into the inner memory. The processor executes the program guidelines.

The crucial unit of PC stockpiling is a digit; it could be ON (1) or OFF (0) and a gathering of 8 related pieces makes a byte on the majority of the advanced PCs.

In this way, the equality digit is utilized to make the quantity of pieces in a byte odd. In the event that the equality is even, the framework accepts that there had been an equality blunder (however uncommon), which may have been caused because of equipment deficiency or electrical aggravation.

The processor bolsters the accompanying information sizes −

  • Word: a 2-byte information thing
  • Doubleword: a 4-byte (32 digit) information thing
  • Quadword: a 8-byte (64 digit) information thing
  • Section: a 16-byte (128 bit) territory
  • Kilobyte: 1024 bytes
  • Megabyte: 1,048,576 bytes

Each number framework utilizes positional documentation, i.e., each position wherein a digit is composed has an alternate positional worth. Each position is intensity of the base, which is 2 for double number framework, and these forces start at 0 and increment by 1.

The accompanying table shows the positional qualities for a 8-digit paired number, where all pieces are determined to.

The value of a binary number is based on the presence of 1 bits and their positional value. So, the value of a given binary number is −

1 + 2 + 4 + 8 +16 + 32 + 64 + 128 = 255

which is same as 28 - 1.

Tending to Data in Memory

The cycle through which the processor controls the execution of directions is alluded as the get decipher execute cycle or the execution cycle. It comprises of three nonstop advances −

Bringing the guidance from memory

Interpreting or distinguishing the guidance

Executing the guidance

The processor may get to each or more bytes of memory in turn. Let us consider a hexadecimal number 0725H. This number will require two bytes of memory. The high-request byte or most noteworthy byte is 07 and the low-request byte is 25.

The processor stores information in turn around byte grouping, i.e., a low-request byte is put away in a low memory address and a high-request byte in high memory address. Along these lines, if the processor brings the worth 0725H from register to memory, it will move 25 first to the lower memory address and 07 to the following memory address.

Presentation

x: memory address

At the point when the processor gets the numeric information from memory to enroll, it again inverts the bytes. There are two sorts of memory addresses −

Total location - an immediate reference of explicit area.

Section address (or counterbalance) - beginning location of a memory portion with the balance esteem.

Gathering - Environment Setup

Nearby Environment Setup

Low level computing construct is reliant upon the guidance set and the design of the processor. In this instructional exercise, we center around Intel-32 processors like Pentium. To follow this instructional exercise, you will require −

An IBM PC or any identical viable PC

A duplicate of Linux working framework

A duplicate of NASM constructing agent program

There are numerous acceptable constructing agent programs, for example, −

Microsoft Assembler (MASM)

Borland Turbo Assembler (TASM)

The GNU constructing agent (GAS)

We will utilize the NASM constructing agent, for what it's worth −

Free. You can download it from different web sources.

All around recorded and you will get loads of data on net.

Could be utilized on both Linux and Windows.

Introducing NASM

In the event that you select "Advancement Tools" while introducing Linux, you may get NASM introduced alongside the Linux working framework and you don't have to download and introduce it independently. For checking whether you as of now have NASM introduced, make the accompanying strides −

Open a Linux terminal.

Type whereis nasm and press ENTER.

On the off chance that it is as of now introduced, at that point a line like, nasm:/usr/canister/nasm shows up. Else, you will see just nasm:, at that point you have to introduce NASM.

To introduce NASM, make the accompanying strides −

Check The netwide constructing agent (NASM) site for the most recent adaptation.

Download the Linux source file nasm-X.XX.ta.gz, where X.XX is the NASM form number in the file.

Unload the chronicle into a catalog which makes a subdirectory nasm-X. XX.

cd to nasm-X.XX and type ./design. This shell content will locate the best C compiler to utilize and set up Makefiles in like manner.

Type make to fabricate the nasm and ndisasm pairs.

Type make introduce to introduce nasm and ndisasm in/usr/neighborhood/canister and to introduce the man pages.

This ought to introduce NASM on your framework. Then again, you can utilize a RPM appropriation for the Fedora Linux. This adaptation is more straightforward to introduce, simply double tap the RPM document.


Related Solutions

Write a possible assembly language instruction or set of instructions to accomplish the following: a) Compare...
Write a possible assembly language instruction or set of instructions to accomplish the following: a) Compare the byte stored at the memory location pointed to by register R4 to the upper (higher) byte stored in register R5 b) Branch to instruction at label ‘ZERO’ if the lower byte of register R6 is zero c) Jump to the instruction at label ‘EVEN’ if the value in register R7 is an even number
Write in ARM assembly language the following operations without using multiplication instruction: a) A * 17...
Write in ARM assembly language the following operations without using multiplication instruction: a) A * 17 b). A * 23
Write a RARS assembly language program to solve the following: For a set of integers stored...
Write a RARS assembly language program to solve the following: For a set of integers stored in an array, calculate the sum of the positive numbers and the sum of the negative numbers, storing the results into memory. In the data segment of the program, define an array consisting of 25 integers (words) that are a mix of positive and negative values. You can select any values you wish but try to create a balance of positive and negative numbers....
2 – The CPU design team is designing an instruction set with three classes of instructions....
2 – The CPU design team is designing an instruction set with three classes of instructions. Parameters are given in the following table. Consider a program with 65% ALU instructions, 20% memory access instructions, and 15% control instructions. What is the average CPI for this CPU? Clock Rate: 4GHz CPI for ALU Inst.: 4 CPI for Memory Inst.: 8 CPI for Control Inst.: 2
Take the following C++ program and translate it into assembly language( pep9 ) #include using namespace...
Take the following C++ program and translate it into assembly language( pep9 ) #include using namespace std; char ch; int main() {    cin >> ch;    cout << "You inputted " << ch << endl;    ch++;    cout << "Next character is " << ch << endl; if (ch <= ‘Z’)         cout << “Could be luppercase\n”;    return 0; }
In MPLAB write and compile (using the simulator) an assembly language program with the following functionality:...
In MPLAB write and compile (using the simulator) an assembly language program with the following functionality: Configures pin RA2 of the PIC24to be an output to control an attached LED. Configures pin RB13 of the PIC24 to be an input to read the value on an attached switch (this switch will connect to ground when pressed). Configures pin RB13 to use the internal pull-up resistor. After configuration, the LED will be "off" when the push-button is pressed, and "on" when...
Coding Problem 1: In this program, you are asked to write a program in assembly (MIPS)...
Coding Problem 1: In this program, you are asked to write a program in assembly (MIPS) which works as a simple calculator. The program will get two integer numbers, and based on the requested operation, the result should be shown to the user. a. The program should print a meaningful phrase for each input, and the result. i. “Enter the first number” ii. “Enter the second number” iii. “Enter the operation type” iv. “The result is” b. The user should...
Take the following program and translate it into PEP/9 assembly language: #include <iostream> using namespace std;...
Take the following program and translate it into PEP/9 assembly language: #include <iostream> using namespace std; int theArray[] = { 5, 11, -29, 45, 9, -1}; void sumPos(int ary[], int len, int &sum) {    sum = 0;    for (int i = 0; i < len; i++)            if (ary[i] > 0)                sum = sum + ary[i]; } int main() {    int total;    sumPos(theArray, 6, total);    for (int k=0; k < 6; k++)      cout...
Take the following program and translate it into PEP/9 assembly language: #include using namespace std; int...
Take the following program and translate it into PEP/9 assembly language: #include using namespace std; int fib(int n) { int temp; if (n <= 0) return 0; else if (n <= 2) return 1; else { temp = fib(n – 1); return temp + fib(n-2); } } int main() { int num; cout << "Which fibonacci number? "; cin >> num; cout << fib(num) << endl; return 0; } You must use equates to access the stack and follow the...
Take the following C++ program and translate it into Pep/9 assembly language #include using namespace std;...
Take the following C++ program and translate it into Pep/9 assembly language #include using namespace std; int age; char first, last; int main() {    cin >> age;    cin >> first >> last;    cout << "Your age " << age << endl;    cout << "Initials " << first << last << endl;    if (age >= 30)        cout << “Cannot trust\n”;    return 0; }
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT