Page 1 of 1

Java Code convert to Assembly Language - RISC-V Hi, I need help with converting the java code below to assembly language

Posted: Sun May 15, 2022 1:50 pm
by answerhappygod
Java Code convert to Assembly Language -
RISC-V
Hi, I need help with converting the java code below to assembly
language. The code is a number base converter, which is used to
converting a number in a base between 2 and 36 to base 10.
The notations used for numbers in this program are essentially
an extension or reduction of hex.
Java Code Convert To Assembly Language Risc V Hi I Need Help With Converting The Java Code Below To Assembly Language 1
Java Code Convert To Assembly Language Risc V Hi I Need Help With Converting The Java Code Below To Assembly Language 1 (13.81 KiB) Viewed 62 times
Example of test cases:
Please enter the base of the number you are using (0 to
exit): 10
Please enter the value: 143
The given value in base 10 is: 143
Please enter the base of the number you are using (0 to
exit): 5
Please enter the value: 414
The given value in base 10 is: 109
Please enter the base of the number you are using (0 to
exit): 26
Please enter the value: ab
The given value in base 10 is: 271
Please enter the base of the number you are using (0 to
exit): 26
Please enter the value: hk
The given value in base 10 is: 4621
Please enter the base of the number you are using (0 to
exit): 26
Please enter the value: Hk The given value in base 10 is:
4621
Please enter the base of the number you are using (0 to
exit): 36
Please enter the value: z The given value in base 10 is:
35
Please enter the base of the number you are using (0 to
exit): 36
Please enter the value: zxy
The given value in base 10 is: 46582
Please enter the base of the number you are using (0 to
exit): 36
Please enter the value: ZXY
The given value in base 10 is: 46582
Please enter the base of the number you are using (0 to
exit): 10
Please enter the value: -14
The given value in base 10 is: -14
Please enter the base of the number you are using (0 to
exit): 36
Please enter the value: -z
The given value in base 10 is: -35
Please enter the base of the number you are using (0 to
exit): 36
Please enter the value: z--
The value entered is not valid for the base entered
Please enter the base of the number you are using (0 to
exit): 5
Please enter the value: 415
The value entered is not valid for the base entered
Please enter the base of the number you are using (0 to
exit): 26
Please enter the value: absfd
The value entered is not valid for the base entered
Please enter the base of the number you are using (0 to
exit): 47
Please enter the base of the number you are using (0 to
exit): 37
Please enter the base of the number you are using (0 to
exit): 36
Please enter the value: 2 The given value in base 10 is:
2
Please enter the base of the number you are using (0 to
exit): 0
-- program is finished running (0) --
My original Java Code:
// BaseConvert.java
//
// Converts base 10 numbers to another base
// (at most 36 digits in the other base). The
// base 10 number and the base are input.
// ***********************************************
import java.util.Scanner;
public class BaseConvert
Explanation:
// BaseConvert.java
//
// Converts base 10 numbers to another base
// (at most 36 digits in the other base). The
// base 10 number and the base are input.
// ***********************************************
import java.util.Scanner;
public class BaseConvert
{
public static void main (String[] args)
{
int base; // the new base
int base10Num; // the number in base 10
int maxNumber; // the maximum number that will fit
// in 4 digits in the new base
int place0; // digit in the 1's (base^0) place
int place1; // digit in the base^1 place
int place2; // digit in the base^2 place
int place3; // digit in the base^3 place
String baseBNum = new String(""); // the number in the new
base
Scanner scan = new Scanner(System.in);
// read in the base 10 number and the base
System.out.println();
System.out.println ("Base Conversion Program");
System.out.println() ;
System.out.print ("Please enter a base (2-9): ");
base = scan.nextInt();
// Compute the maximum base 10 number that will fit in 4
digits
// in the new base and tell the user what range the number
they
// want to convert must be in
System.out.print ("Please enter a base 10 number to convert:
");
base10Num = scan.nextInt();
// Do the conversion (see notes in lab)
place0 = base10Num % base;
base10Num = base10Num/base;
place1 = base10Num % base;
base10Num = base10Num/base;
place2 = base10Num % base;
base10Num = base10Num/base;
place3 = base10Num % base;
baseBNum = baseBNum + place3 + place2 + place1 + place0;
// Print the result (see notes in lab)
System.out.println(baseBNum);
}
}
Base Single Digit that can be used in a number 2 0,1 3 0, 1, 2 ... 11 0,1,2,3,4,5,6,7,8,9,a 12 0,1,2,3,4,5,6,7,8,9,ab ... 34 0,1,2,3,4,5,6,7,8,9,a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w.x 35 0,1,2,3,4,5,6,7,8,9,a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y 36 0,1,2,3,4,5,6,7,8,9,a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z