Question: So I need to translate this code from java to a RISC-V simulator. The first picture is of what Im given and where in the
GLOBAL # Global location of the whole program STACK definition-_mm Oxffffffffffff0000 # The bottom of the stack Oxfffffffffffffff8 # The top of the stack BSTACK: DD TSTACK: DD # HEAP definition BHEAP: THEAP MAL LAST IDX DD DD OxffffOOOOOOOOOOOO # The top of the HEAP DD Oxffffffffffff0000 # The bottom of the HEAP # The last available index in # the heap # Memory allocation -- simple array for the heap representation MALLOC Id x5, x0, MAL LAST IDX # Load the value of the index ld x6, xo, BHEAP # Load the address of the base of the heap add x10 x5x aupc x7, MAL LAST IDX # Loading the address of the index into upper 20 # Calculating the allocated address for returning # bits word # shift to the right by 12 bits to the right # address # make the index always multiple of 4 # Increasing the index # store the new value of index # return to caller srli x7x712 sili x28,x12, 2 add / x5, x5, 28 sdx5 0 (x7 jalr x0 , 0(x1) x5 x5,x28 # START of the application START # Stack pointer Initialization 1dsp,TSTACK (xO) # Global pointer Initialization aupc x3, GLOBAL srli x3, x3, 12 # The rest of the code goes here public class FractionClient public static void main (String[l args) Fraction anew Fraction (3,8); Fraction bnew Fraction (1,2); a.add (b) System. out.print (a.getNumerator ) System.out.print('/") System.out.print (a.getDenominator )) GLOBAL # Global location of the whole program STACK definition-_mm Oxffffffffffff0000 # The bottom of the stack Oxfffffffffffffff8 # The top of the stack BSTACK: DD TSTACK: DD # HEAP definition BHEAP: THEAP MAL LAST IDX DD DD OxffffOOOOOOOOOOOO # The top of the HEAP DD Oxffffffffffff0000 # The bottom of the HEAP # The last available index in # the heap # Memory allocation -- simple array for the heap representation MALLOC Id x5, x0, MAL LAST IDX # Load the value of the index ld x6, xo, BHEAP # Load the address of the base of the heap add x10 x5x aupc x7, MAL LAST IDX # Loading the address of the index into upper 20 # Calculating the allocated address for returning # bits word # shift to the right by 12 bits to the right # address # make the index always multiple of 4 # Increasing the index # store the new value of index # return to caller srli x7x712 sili x28,x12, 2 add / x5, x5, 28 sdx5 0 (x7 jalr x0 , 0(x1) x5 x5,x28 # START of the application START # Stack pointer Initialization 1dsp,TSTACK (xO) # Global pointer Initialization aupc x3, GLOBAL srli x3, x3, 12 # The rest of the code goes here public class FractionClient public static void main (String[l args) Fraction anew Fraction (3,8); Fraction bnew Fraction (1,2); a.add (b) System. out.print (a.getNumerator ) System.out.print('/") System.out.print (a.getDenominator ))
Step by Step Solution
There are 3 Steps involved in it
Objective Translate the given Java code for a simple Fraction class into RISCV assembly using the memory allocation and structure defined in the provi... View full answer
Get step-by-step solutions from verified subject matter experts
