Using the .half assembler directive in lieu of the .word directive (in the data
ID: 3794100 • Letter: U
Question
Using the .half assembler directive in lieu of the .word directive (in the data segment), and the half-word load and store (lh and sh), refactor the following code to deal with 16-bit integers. Notice this requires a "stride 2" rather than "stride 4" walk through the arrays, and will affect both the index version and the pointer version of the for loop. Run your code in QtSpim, and take a legible screen shot of the code window and data window after the code has run. Incorporate the screen shots in your PDF, but attach the source code as a separate file (as noted in the instructions). # # forloops.s # demonstrates 2 ways to implement for loops in MIPS assembler # Gerald R. Morris, Feb 2014 # .data v: .word 1, 2, 3, 4, 5, 6 # v[] array w: .space 4*6 # w[] array x: .space 4*6 # x[] array n: .word 6 # array size k: .word 2 # constant to be added .text main: lw $t0, n # $t0 = n lw $t1, k # $t1 = k (constant to add to v[i]) la $t2, v # $t2 = v[] base address la $t3, w # $t3 = w[] base address # first technique: index through loop li $t4, 0 iloop: sll $t5, $t4, 2 # $t5 = 4*i addu $t6, $t2, $t5 # $t6 = & v[i] (base + offset) addu $t7, $t3, $t5 # $t7 = & w[i] (base + offset) lw $t8, 0($t6) # $t8 = v[i] add $t8, $t8, $t1 # $t8 = v[i] + k sw $t8, 0($t7) # w[i] = v[i] + k addi $t4, $t4, 1 # i++ bne $t4, $t0, iloop # if iExplanation / Answer
import java.util.*; class Car { private String make; private String model; private String regNo; private int deposit; private int rate; public Car(String newMake, String newModel, String newRegNo, int newDeposit, int newRate) { make = newMake; model = newModel; regNo = newRegNo; deposit = newDeposit; rate = newRate; } public String getMake() { return make; } public String getModel() { return model; } public String getRegNo() { return regNo; } public int getDeposit() { return deposit; } public int getRate() { return rate; } } public class TestProject { public static void main(String args[]) { List carlist = new ArrayList(); carlist.add(new Car("Toyota", "Altis", "SJC2456X", 100, 60)); carlist.add(new Car("Toyota", "Vios", "SJG9523B", 100, 50)); carlist.add(new Car("Nissan", "Latio", "SJB7412B", 100, 50)); carlist.add(new Car("Murano", "SJC8761M", "Nissan", 300, 150)); carlist.add(new Car("Honda", "Jazz", "SJB4875N", 100, 60)); carlist.add(new Car("Honda", "Civic", "SJD73269C", 120, 70)); carlist.add(new Car("Honda", "Stream", "SJL5169J", 120, 70)); carlist.add(new Car("Honda", "Odyssey", "SJB3468E", 200, 150)); carlist.add(new Car("Subaru", "WRX", "SJB8234L", 300, 200)); carlist.add(new Car("Subaru", "Imprezza", "SJE8234K", 150, 80)); Scanner input = new Scanner(System.in); System.out.print("Enter model to rent: "); String model = input.nextLine(); for (Car s : carlist) { if (model.equals(s.getModel())) { System.out.println("Model " + model + " is available"); System.out.print("Enter number of days: "); int days = input.nextInt(); System.out.println("***************Details*****************"); int cost = (days * s.getRate()) + s.getDeposit(); System.out.println("Deposit DailyRate Duration TotalCost"); System.out.println(s.getDeposit() + " " + s.getRate()+ " " + days + " " + cost); System.out.print("Proceed to rent?( y/n ): "); String dec = input.next(); if (dec.equals("y")) { System.out.println("Enter Customer Name: "); String name = input.next(); System.out.println("Enter IC Number: "); int num = input.nextInt(); System.out.println("************Receipt*************"); System.out.println("Name ICNo Car RegNo Duration TCost"); System.out.println(name + " " + num + " " + model + " " + s.getRegNo() + " " + days + " "+cost); System.out.println("Serving Next Customer "); } else if (dec.equals("n")) { System.out.println("Serving Next Customer: "); } } } } }
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.