Question

Write common assembly language (RISC) programs to a) sum the first n elements of an array...

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

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Solution a) Assembly Code for sum of first n element from array: DATA arraỵ DW 100 DUP (2) ;declare array maximum size is 100ca sumValue mov sum, eax isave the sum in eax register int 21H for display the sum SumValue: push ebp mex ebp, esp mov eax, 0b) Assemblv Code for r-a*b: DATA a DB DUP (?) declare a b DB DUP (?) declare b DB DUP (2) ;declare r . CODE mov ah, 4 systemCopyable 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

Add a comment
Know the answer?
Add Answer to:
Write common assembly language (RISC) programs to a) sum the first n elements of an array...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • E2.15 In assembly code, write a program to count the number of elements in 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...

    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....

    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...

    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...

    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

  • Programming Problem: SUMMING ARRAY ELEMENTS -       Use Assembly Language x86 (MASM) Write an assembly code...

    Programming Problem: SUMMING ARRAY ELEMENTS -       Use Assembly Language x86 (MASM) Write an assembly code calculates the sum of all array elements. Save the sum in the EAX register. ------------------------------------------------------------------------------- This is my code so far: INCLUDE Irvine32.inc N=10 .data array SDWORD N DUP(0,1,2,3,4,5,6,7,8,9) j DWORD ? k DWORD ? .code     main PROC         ; not complete          exit    main ENDP END main

  • Write a c program to implement threads. Accept an array of 40 integers, write a thread...

    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...

    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...

    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...

  • MIPS CODE required to write an assembly program to find the maximum of an array of integers by...

    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...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT