Write common assembly language (RISC) programs to a) sum the first n elements of an array A, and b) compute r = ab for unsigned integers a and b. Each program will consist of a driver and a subprogram. The drivers will 1) read one or more values from the keyboard, 2) call the subprogram, and 3) print a result. The subprograms must not: ● store into memory, ● use registers $1 – $9, or ● make system calls
Copyable Code:
a)
.DATA
array DW 100 DUP (?) ;declare array maximum size is 100
num DB DUP(?) ;declare Number
sum DB DUP(?)
.CODE
mov ah, 4 ;system call code for int read
INT 21H
sub al, 30H
mov num, al
mov ebx,0 ; array offset
mov ecx,[num] ;loop counter
LOOP:
mov ah, 4 ;system call code for int read
INT 21H
sub al, 30H
mov array[ebx], al ;save int in the array at offset ebx
addi ebx, 4 ;increment the offset by 4
dec ecx ;decrement the ecx counter
jnz LOOP ;jump to loop if not zero
push array ;push the array values
push num ;push given num
call SumValue
mov sum, eax ;save the sum in eax register
int 21H ;for display the sum
SumValue:
push ebp
mov ebp, esp
mov eax, 0 ;save value of sum
mov ebx, [ebp+4] ;load num
mov ecx, [ebp+8] ;load the array base address
loopSum:
mov edx, [ecx] ;load array values
add eax,edx ;add array element that is edx to eax
addi ecx, 4 ;increment offset by 4
dec ebx
jnz loopSum
mov esp, ebp
pop ebp
ret
b)
.DATA
a DB DUP(?) ;declare a
b DB DUP(?) ;declare b
r DB DUP(?) ;declare r
.CODE
mov ah, 4 ;system call code for read int a
INT 21H
sub al, 30H
mov a, al
mov ah, 4 ;system call code for read int b
INT 21H
sub al, 30H
mov b, al
push a ;push a value
push b ;push b value
call MULTIPLY ;call MULTIPLY function
mov [r], eax ;move the result r to eax
int 21H ;for display
MULTIPLY:
push ebp
mov ebp, esp
mov eax, [ebp+4] ; load b value
mov ebx, [ebp+8] ; load a value
mul eax,ebx ;for r = a* b that is eax = eax*ebx
mov esp, ebp
pop ebp
ret
Write common assembly language (RISC) programs to a) sum the first n elements of an array...
E2.15 In assembly code, write a program to count the number of elements in an array that are smaller than 16. The array is stored at memory locations starting from $1010. The array has 30 8-bit unsigned elements. Store the count in the memory location $C001.
PLEASE USE VERY BASIC REGISTERS AND CODE TO DO THE FOLLOWING Objectives: -write assembly language programs to: -define a recursive procedure/function and call it. -use syscall operations to display integers and strings on the console window -use syscall operations to read integers from the keyboard. Assignment Description: Implement a MIPS assembly language program that defines "main", and "function1" procedures. The function1 is recursive and should be defined as: function1(n) = (2*n)+9 if n <= 5 =...
Assembly Language/ Microprocessors - Question: (INVOKE): Write a procedure to accept three parameters of type DWORD. Read three unsigned integers from console and call the procedure to return their sum. Note that the sum must be returned in EAX register. Call procedure using INVOKE. Print the sum returned from procedure to the console
Write a PIC 18F452 assembly program that uses an array of signed integers of 10 elements and computes the sum of all the elements in the array.
Assembly Language////Write a program that read in 10 integers from the user. Save the numbers into an array; reverse the array and display the reversed array. .data arrayInt DWORD 10 DUP(?) Your program consists of 4 procedures: 1. main procedure: call procedures getInput, reverseArray, displayArray 2. getInput procedure: prompt user to enter 10 integer numbers, save the numbers into the memory for the arrayInt 3. reverseArray: reverse arrayInt 4. displayArray: display the reversed array
Write a c program to implement threads. Accept an array of 40 integers, write a thread method named sum of array elements. Divide the array into 4 equal elements and call threads to find the sum of each part. Store the sum in a variable called “arrays'. Print the sum in the main function. (10 points)
Assembly Language Program Help Write a procedure named CountNearMatches that receives pointers to two arrays of signed doublewords, a parameter that indicates the length of the two arrays, and a parameter that indicates the maximum allowed difference (called diff) between any two matching elements. For each element x(i) in the first array, if the difference between it and the corresponding y(i) in the second array is less than or equal to diff, increment a count. At the end, return a...
Q-1: Write a program in Assembly language using MIPS instruction set that reads 15 integer numbers from user and stores all the numbers in the array intArray. Now, read another integer number N from the user, find the total number of array elements that are greater or equal to the number N, and the total number of array elements that are lower than the number N You must have two procedures: i. ReadIntegerArray: this procedure should read integer array elements...
required to write an assembly program to find the maximum of anarray of integers by doing the following:1. Prompt user to input array size n (n <= 10)2. Prompt user to input element values of array A one by one3. Display the result on the console.This program must at least include one function. The main program will read the valuesof the array (as user inputs the element values) and stores them in the memory (datasegments section) and at the end...
MIPS Programming Assignment 4 (logical operations) Please write a complete MIPS assembly language programs for the following questions and print a hardcopy of your code to submit 1. Swap each pair of elements in the string "chararn be an even number of characters in "chararray". (see loop4.a) 2 "numbers" is an array of five words. Catculate the sum of aftetements in "number muttiples of 4. Use the and instruction, not div or remfor thisquestion(S 3. "number" is a word. Write...