Question

In: Computer Science

Assembly Language homework assignment has 2 parts which require 2 separate programs. Submit both source code...

Assembly Language
homework assignment has 2 parts which require 2 separate programs. Submit both source
code files .
Question 1 of 2. Integer arithmetic: [20 marks] Write an assembly language program that performs the following arithmetic operation on 4 integer numbers.
?????? = ((2∗?)+? )/(?+?)
1. Reserve memory for 4 integers and initialize them to numbers of your choice.
2. Reserve 4 bytes of memory for a single integer to store the result of the operation in a
READWRITE section of memory.
3. Load the numbers from memory and perform the above operation.
4. Store the result back into of memory.
For this part of the assignment, we shall work with 4 integers namely A, B, C, D. We can declare them as 4 separate variables or a single array with 4 numbers. We need to MULtiply the number A with 2 and then ADD the result to B. We also need to ADD C and D together to get the divisor. Following this we need to perform Signed DIVision of the two intermediate results in order to obtain the final result. This is an integer arithmetic operation, so division would not give you a floating-point result. All remainders are ignored. Division with a number higher than the dividend would result in 0. This follows traditional integer division as in C++.
Make sure your code works for any input number, not just the test cases. Your code will be tested on other test cases not listed here.
Please properly comment your code before submission.

Solutions

Expert Solution

.data
   #Declaring and Initializing A,B,C and D variables
   A:   .word   20
   B:   .word   24
   C:   .word   12
   D:   .word   4
   #Reserving space of 4 bytes to store the result of the operation
   result:   .space   4
   prompt:   .asciiz   "\nThe result is: "
  
.text
main:
   #Loading A,B,C and D variables from memory
   lw $t0,A
   lw $t1,B
   lw $t2,C
   lw $t3,D
      
   mul $t4,$t0,2           #Multiplying A by 2
   add $t4,$t4,$t1           #Adding B to the result in above operation
   add $t5,$t2,$t3           #Adding C and D variables
   div $t6,$t4,$t5           #Dividing ((2*A)+B) by (C+D)
  
   sw $t6,result           #Storing result into memory
  
   #Displaying the result to user
   li $v0,4
   la $a0,prompt
   syscall  
   li $v0,1
   move $a0,$t6
   syscall


Related Solutions

The language is Assembly Language. Thank you! Assignment 3: Run the following code. Record what each...
The language is Assembly Language. Thank you! Assignment 3: Run the following code. Record what each of the flag changes are for each command. INCLUDE Irvine32.inc .data .code main PROC mov al,255 add al,1 call DumpRegs sub al,1 call DumpRegs sub al,1 call DumpRegs exit main ENDP END main
Write an x86 assembly language program that performs equivalently to the C++ source code file shown...
Write an x86 assembly language program that performs equivalently to the C++ source code file shown below.Please note that commented out behavior must be implemented in x86 assembly language. There is no standard, portable way to perform some of these actions in C++. #include void main() { // Use registers for these in your x86 assembly language program // Only use the .data segment for string (character array) variables int eax; int esi; int ecx; int edi; // Loop the...
Explain the differences between an assembly language source code file, the listing file produced by 'nasm',...
Explain the differences between an assembly language source code file, the listing file produced by 'nasm', the object file (.o) and the final executable program.
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 }
Source code with comments explaining your code in C# Program 2: Buh-RING IT! For this assignment,...
Source code with comments explaining your code in C# Program 2: Buh-RING IT! For this assignment, you’re going to simulate a text-based Role-Playing Game (RPG). Design (pseudocode) and implement (source) for a program that reads in 1) the hero’s Hit Points (HP – or health), 2) the maximum damage the hero does per attack, 3) the monster’s HP and 4) the maximum monster’s damage per attack. When the player attacks, it will pick a random number between 0 and the...
Homework 3 – World Series and Inpatient Payment System This assignment has two parts: one that...
Homework 3 – World Series and Inpatient Payment System This assignment has two parts: one that takes information from the web and one that takes it from a file.   To select the type of information to gather, a menu will be used.    Although the assignment does not require the use of functions, they can be useful. ***** This question uses Python Programming Language. The website can not be provided in the question, but the website entails every World Series since...
Homework 3 – World Series and Inpatient Payment System This assignment has two parts: one that...
Homework 3 – World Series and Inpatient Payment System This assignment has two parts: one that takes information from the web and one that takes it from a file.   To select the type of information to gather, a menu will be used.    Although the assignment does not require the use of functions, they can be useful. ***** This question uses Python. The website can not be provided in the question, but the website entails every World Series since 1903, the...
Homework 3 – World Series and Inpatient Payment System This assignment has two parts: one that...
Homework 3 – World Series and Inpatient Payment System This assignment has two parts: one that takes information from the web and one that takes it from a file.   To select the type of information to gather, a menu will be used.    Although the assignment does not require the use of functions, they can be useful. ***** This question uses Python Programming Language. The website can not be provided in the question, but the website entails every World Series since...
Which programs (C and assembly, etc.) of xv6 has the codes for the boot procedure? Can...
Which programs (C and assembly, etc.) of xv6 has the codes for the boot procedure? Can we use printf() to print a message during the boot process and why?
Which programs (C and assembly, etc.) of xv6 has the codes for the boot procedure? Can...
Which programs (C and assembly, etc.) of xv6 has the codes for the boot procedure? Can we use printf() to print a message during the boot process and why?
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT