Question

In: Computer Science

Program 1-100 integer accumulation using RISC-V assembly. Note: RARS only simulates 320-bit instructions of RISC-V, so...

Program 1-100 integer accumulation using RISC-V assembly.

Note: RARS only simulates 320-bit instructions of RISC-V, so make sure you use the instruction that operate work-size data type (mostly with `w` as the last character of the instruction mnemonic)

Solutions

Expert Solution

Greetings!!

Code:

#DATA SEGMENT

.data

sum: .ascii "Sum of numbers from 1-100: "

#CODE SEGMENT

.text

#MAIN STARTS HERE

main:

li t0,1               #load first number

li t1,0               #load 0 to hold sum

li t2,101           #load the upper limit

#PROCESSING..

loop:

beq t0,t2,done #check whether the number is equal to 101

add t1,t1,t0      #else sum it up in t1

addi t0,t0,1      #increment the number

j loop               #repeat

done:

#DISPLAY MESSAGE

la a0,sum        #load address of message

li a7,4              #parameter

ecall                #display

#DISPLAY SUM

add a0,zero,t1 #load sum to a0 for display

li a7,1              #parameter

ecall                #display

#TERMINATION

li a7,10                        #parameter

ecall                #terminate

Output screenshot:

Hope this helps


Related Solutions

Write a program in "RISC-V" assembly to convert an ASCII string containing a positive or negative...
Write a program in "RISC-V" assembly to convert an ASCII string containing a positive or negative integer decimal string to an integer. ‘+’ and ‘-’ will appear optionally. And once they appear, they will only appear once in the first byte. If a non-digit character appears in the string, your program should stop and return -1.
4 – The following 32-bit binary word written in hexadecimal format represents a single RISC-V assembly...
4 – The following 32-bit binary word written in hexadecimal format represents a single RISC-V assembly instruction. What is the RISC-V instruction format and specific assembly language instruction? 0x00156A33
Please convert the following C program into the RISC-V assembly code 1) #include <stdio.h> int main()...
Please convert the following C program into the RISC-V assembly code 1) #include <stdio.h> int main() { int i = 2, j = 2 + i, k; k = i * j; printf("%d\n", k + j); return 0; } 2) #include <stdio.h> int main() { int i = 2, j = 2 + i, k = j / 2; if (k == 1) { printf("%d\n", j) k = k * 2; if ( k == j) { printf("%d\n|, j); }...
The following 32-bit binary word written in hexadecimal format represents a single RISC-V assembly instruction. What...
The following 32-bit binary word written in hexadecimal format represents a single RISC-V assembly instruction. What is the RISC-V instruction format and specific assembly language instruction? 0xfe810113
Convert the following C program into the RISC-V assembly code. You should look up a table...
Convert the following C program into the RISC-V assembly code. You should look up a table to convert the lines manually and you can use "ecall" when appropriate (Don't make it too complicated than it needs to be): #include int main() { int x = 30, y = 17; printf("x * y = "); printf("%d\n", x*y); return 0; }
need a code MIPS assembly language program to implement algorithms of an 8-bit integer "positive integer"...
need a code MIPS assembly language program to implement algorithms of an 8-bit integer "positive integer" to calculate the square root for an-8 bit integer using The Radix-2 SRT-Redundant and Non-Redundant Algorithm to approximate square root
1. For the following C statement, write the corresponding RISC-V assembly code. Assume that the C...
1. For the following C statement, write the corresponding RISC-V assembly code. Assume that the C variables a, b, and c, have already been placed in registers x10, x11, and x12 respectively. Use a minimal number of RISC-V assembly instructions. a = b + (c − 2); 2. Write a single C statement that corresponds to the two RISC-V assembly instructions below. add e, f, g add e, h, e 3. Assume that registers x5 and x6 hold the values...
PART 1: Design a program (using only native MIPS instructions, no pseudo instructions) that will prompt...
PART 1: Design a program (using only native MIPS instructions, no pseudo instructions) that will prompt user to enter three decimal numbers. Each decimal number will not exceed six digits The program can't ask user how many digits will be entered. Both numbers must be stored in memory as NULL terminated strings. The first number must be stored at the memory address 0x10000000. The second number must be stored in the memory 0x10000008. The third number must be stored at...
In assembly 1.What is the effect of the following instructions executing on a modern x86 64-bit...
In assembly 1.What is the effect of the following instructions executing on a modern x86 64-bit system (describe what happens and the final contents of the registers involved)? Can you obtain the same end result using only two instructions, and no other registers? PUSH RAX PUSH RBX PUSH RCX XOR RAX,RAX XOR RBX,RBX XOR RCX,RCX POP RAX POP RAX POP RBX 2. What is the purpose of a segment register in protected mode memory addressing? 3. For a 32-bit Pentium4...
using Windows 32 bit framework , Write an assembly language program to find the second minimum...
using Windows 32 bit framework , Write an assembly language program to find the second minimum element (formally, second minimum is larger than the minimum but smaller than all the other elements in the array) of an array of size 100. Note: You can define the array as nbrArray DWORD 23 45 21 67 78 95 dup(?) and show that your program works for the first five elements. Display the second minimum in a message box using Input output macro
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT