CSC 3210 – Assignment #5 Fall 2017 due Tuesday, Oct 24th, 11:59 pm (No 24-late p
ID: 3598671 • Letter: C
Question
CSC 3210 – Assignment #5
Fall 2017
due Tuesday, Oct 24th, 11:59 pm (No 24-late period is provided for this assignment)
Objective: Learn memory organization/layout, data transfer concepts and instructions, memory access modes, memory allocation, memory size, type and length operators, and single and nested loop instruction.
Requirements:
1. (5 points) Write an assembly program that does the following:
- Define the following value 0506030704080102h in the .data segment using the 64-bit unsigned identifier.
- Find the sum of its words using the PTR operator. The sum should be D17h.
- Store the result in the appropriate N-bit register.
- The direction of adding two words goes from left to right.
o Submit the following:
Lastname1.asm
2. (5 points) Use a loop instruction with indirect addressing to reverse the elements of an array in place.
- Do not copy the elements to any other array.
- Use the SIZEOF, TYPE, and LENGTHOF operators to make the program as flexible as possible if the array size and type should be changed in the future.
- Use the XCHG instruction.
- The array’s elements are: B, A, D, C, F, E, H, G.
- The array’s elements after running the program should look like: A, B, C, D, E, F, G, H.
o Submit the following:
Lastname2.asm
3. (5 points) Implement the following expression in assembly language:
for (i = 5; i > 0; i--)
{
for(j = 3; j > 0; j--)
{
y = i + j ;
}
}
- Assume I and j are 32-bit registers and y is a list.
o Submit the following:
Lastname3.asm
Note:
Submit your source code by only uploading .ASM file using iCollege in the respective assignment dropbox:
o Lastname1.ASM (Ex. mussa1.ASM
(Need help using visual studios)
Explanation / Answer
package com.one;
class DList<T> {
private DNode<T> header, trailer;
private int size;
public DList() {
size = 0;
header = new DNode<T>(null, null, null);
trailer = new DNode<T>(null, header, null);
header.setNext(trailer);
}
public int size() {
return size;
}
public boolean isEmpty() {
return size == 0;
}
// give clients access to nodes, but not to the header or trailer
public DNode<T> getFirst() throws Exception {
if (isEmpty())
throw new Exception("Empty");
return header.getNext();
}
public DNode<T> getLast() throws Exception {
if (isEmpty())
throw new Exception("Empty");
return trailer.getPrev();
}
public DNode<T> getNext(DNode<T> v) throws Exception {
DNode<T> ans = v.getNext();
if (ans == null || ans == trailer)
throw new Exception("No such node");
return ans;
}
public DNode<T> getPrev(DNode<T> v) throws Exception {
DNode<T> ans = v.getPrev();
if (ans == null || ans == header)
throw new Exception("No such node");
return ans;
}
// methods to change the list
public void addBefore(T d, DNode<T> v) {
DNode<T> u = v.getPrev();
DNode<T> x = new DNode<T>(d, u, v);
u.setNext(x);
v.setPrev(x);
size++;
}
public void addAfter(T d, DNode<T> v) {
DNode<T> w = v.getNext();
DNode<T> x = new DNode<T>(d, v, w);
v.setNext(x);
w.setPrev(x);
size++;
}
public void addFirst(T d) {
addAfter(d, header);
}
public void addLast(T d) {
addBefore(d, trailer);
}
public T remove(DNode<T> v) throws Exception {
if (v == header || v == trailer)
throw new Exception("Sentinel");
DNode<T> u = v.getPrev();
DNode<T> w = v.getNext();
w.setPrev(u);
u.setNext(w);
size--;
return v.getData();
}
// LinkedList testing methods:
public String toString() {
String ans = "";
DNode<T> n = header;
ans += "(H)<-->";
do {
n = n.getNext();
if (n == trailer)
ans += "(T)";
else
ans += (n.getData() + "<-->");
} while (n != trailer);
return ans;
}
}