Hello, I\'m suppose to write a basic IA23 assembly routine using gnu assembly. T
ID: 3603911 • Letter: H
Question
Hello, I'm suppose to write a basic IA23 assembly routine using gnu assembly. The name of the directory should be called prog2. For the asignment, an assembly code in the provided file prog2.s as shown in the following pic below.
The file should implement the following prototype:
int prog2 (int i, int j, int *k, int a[5], int *1);
This function should do the following three things:
1. Return j - i
2. Set *k = 3 * (*k);
* NOTE: Do NOT use any multiplication or division instructions.
3. Set *1 = a[0] + a[1] +a[2] +a[3] + a[4];
* It isn't required to use conditional jumping for this task, but it can be used for this program.
* When any any callee-save register is modified, its old value needs to be saved and restored.
* NOTE: please write comments for each instruction to explain its purpse. (use # when writing a comment)
------------------------------------------------
How to get this working in 3 distinct steps:
1. Write a function taking the above arguments, but the only thing it does is return j - i. The function can be tested by running the provided xtest program. (Hint: the return value should be stored in %eax.)
2. Try to use the address passed in as the k parameter to change the caller's variable. The integer needs to be stored at the address, multiply by 3 (without using any multiplication or division instruction), and then store the computed value at the adress.
3. Try to use the address passed in as the a parameter to read integers stored in the array. Note that the address is the starting address of the array, and you need to calculate an appropriate offset to read each array element.
----------------------------------
The output of how to run the tester is shown below.
globl prog2 prog2: pushl %ebp #implement hereExplanation / Answer
Partially completed Direction ENUM
*/
package edu.cuny.csi.csc330.lab5;
import edu.cuny.csi.csc330.lib.Randomizer;
public enum Direction {
NONE, NORTH, EAST, SOUTH, WEST ;
// !!! Add 4 more Direction Values - NORTHEAST, NORTHWEST, SOUTHWEST, SOUTHEAST
// methods
public Direction getFavorite() {
return SOUTH; // It's getting cold! ...
}
public Direction getNextRandom() {
Randomizer randomizer = new Randomizer();
/******************************
* !!!!!
* WHAT CHANGES NEED TO BE MADE HERE SO THAT THE 4 NEW RANDOM DIRECTIONS ARE CONSIDERED
*/
int direction = randomizer.generateInt(1, 4);
// 1 = south, 2 = west, 3 = north, 4 = east
if(direction == 1) { // south
return SOUTH;
}
else if(direction == 2) { // west
return WEST;
}
else if(direction == 3) { // north
return NORTH;
}
else { // east
return EAST;
}
}
public static void main(String [] args) {
int c = 0;
while(c++ < 100) {
System.out.println(Direction.NONE.getNextRandom() );
}
}
}
/
/
/
/
Drunk Walker
/
/
/
/
/
/
package edu.cuny.csi.csc330.lab5;
import java.math.*;
import java.util.*;
public class DrunkWalker {
private Intersection startIntersection;
private Intersection currentIntersection;
// !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
// add other data members here including Collection instances that you will use to
// to track history and statistics ...
private DrunkWalker() {
init();
}
/**
*
* @param avenue
* @param street
*/
public DrunkWalker(int avenue, int street) {
init();
}
private void init() {
// What should be do here to initialize an instance??
}
/**
* step in a random direction
*/
public void step() {
takeAStep();
/** !!!!!!!!!!!!!!!!!!!!!!!!!!!
* Now, update the Collections that manage the following:
*
* 1) add this next step/intersection to a "history" List that will contain the sequence of all
* steps taken by this DrunkWalker instance
*
* 2) add this next step to a Intersection -> Counter Map ... The Map
* Collection can and should be of Generics "Type" <Intersection, Integer>
* key = Intersection
* value = Count Value
* Need to do something like this:
* if intersection is not saved in Map yet as a key yet, add a key->value pair of Intersection->1
* else if intersection value is there, the existing key->value pair need to be replaced as
* Intersection->existing_count+1
*
*/
}
private void takeAStep() {
Direction dir = Direction.NONE.getNextRandom();
/** !!!!!!!!!!!!!!!!!!!!!!!!!!!!!
* now what do we do based on the random Direction created?
* How do we go about updating the "currentIntersection" instance to reflect the
* direction/step that was just selected?
*/
}
/** !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
* toString()
* @return
*/
/**
* generate string that contains current intersection/location info
*/
public String getLocation() {
// !!!!!!!!!!!!!!!!!
/**
return String.format("Current location: DrunkWalker [avenue=%d, street=%d]",
currentIntersection.getAvenue(), currentIntersection.getStreet() );
*/
return null;
}
/**
* Take N number of steps
* @param steps
*/
public void fastForward(int steps ) {
// Considering that we already have a step() method, how would we
// implement this method? Uhh, think reuse!
}
/**
* Display information about this current walker instance
*/
public void displayWalkDetails() {
/**
* This method needs to display the following information in a neat, readable format
* using calls to System.out.println() or System.out.printf()
*
* 1 - starting location
* 2 - current/ending location
* 3 - distance (value returned by howFar() )
* 4 - number of steps taken - which collection would be able to provide that information, and how?
* 5 - number of unique intersections visited -
* which collection would be able to provide that information, and how?
* 6 - Intersections visited more than once
*
*/
}
/**
* X Y Coordinate distance formula
* |x1 - x2| + |y1 - y2|
* @return
*/
public int howFar() {
/** |x1 - x2| + |y1 - y2|.
startAvenue = x1
avenue = x2
startStreet = y1
street = y2
return (Math.abs(startAvenue - avenue) ) + (Math.abs(startStreet - street));
*
*/
return 0;
}
public static void main(String[] args) {
// create Drunkard with initial position (ave,str)
DrunkWalker billy = new DrunkWalker(6,23);
for(int i = 1 ; i <= 3 ; ++i ) {
billy.step();
System.out.printf("billy's location after %d steps: %s ",
i, billy.getLocation() );
}
// get his current location
String location = billy.getLocation();
// get distance from start
int distance = billy.howFar();
System.out.println("Current location after fastForward(): " + location);
System.out.println("That's " + distance + " blocks from start.");
// have him move 25 random intersections
billy.fastForward(25);
billy.displayWalkDetails();
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.