Please, implement these subroutine.
Program:
Sample output:
Code to copy:
ORG 100 / Origin of program is location 100
LDA x / load x into Accumulator(AC)
BSA ABS / branch to subroutine ABS
STA z / store the result returned by ABS into z
HLT / Halt the program
x, DEC -3
z, DEC 0
TEM, DEC 0
MSK, HEX 8000
ABS, HEX 0 / Subroutine to find absolute value
STA TEM / Save x into teparary variable TEM
AND MSK / To check sign bit, do masking x with 8000
SNA / skip next instrucntion, if sign bit(MSB) is 1
BUN ZER / otherwise( if MSB is 0), goto label ZER
LDA TEM / if MSB is 1, load x into AC
CMA / and calculate 2's complement
INC
BUN RET / goto label RET
ZER, LDA TEM / if MSB is 0, load x into AC and return
RET, BUN ABS I / return to Main
END
Program:
Sample output:
Code to copy:
ORG 100 / Origin of program is location 100
LDA x / load x into Accumulator(AC) and pass it to MAX
BSA MAX / branch to subroutine MAX
DEC 5 / pass 2nd argument(y) to MAX
STA z / store the result returned by MAX into z
HLT / Halt the program
x, DEC 3
z, DEC 0
TEX, DEC 0
TEY, DEC 0
TX, DEC 0
TY, DEC 0
ONE, DEC 1
MAX, HEX 0 / Subroutine to maximum of two numbers
STA TEX / Save x into temparary variable TEX
STA TX / save x into temparary variable TX
SZA / if x is 0, return y as maximum
BUN STY / otherwise, return
BUN REY /
STY, LDA ONE / load 1 into AC and calculate 2's complement
CMA
INC
STA ONE / save back -1 into ONE
LDA MAX I / load second parameter y
STA TEY / Save y into temparary variable TEY
STA TY / save x into temparary variable TY
SZA / if y is 0, return x as maximum
BUN LOP / otherwise goto LOP
BUN REX
LOP, LDA TX / load x into AC
ADD ONE / subtract 1 from x (x=x-1)
STA TX / update x
SZA / if x is 0, return y as maximum
BUN NEX / otherwise, goto NEX
BUN REY
NEX, LDA TY / load y into AC
ADD ONE / do y=y-1
STA TY / update y
SZA / if y is 0, return x as maximum
BUN LOP / otherwise, goto LOP
BUN REX
REX, LDA TEX / load x and return
BUN RET
REY, LDA TEY / load y and return
RET, BUN MAX I / return to Main
END
Program:
Sample output:
Code to copy:
ORG 100 / Origin of program is location 100
LDA x / load x into Accumulator(AC) and pass it to MIN
BSA MIN / branch to subroutine MIN
DEC 5 / pass 2nd argument(y) to MIN
STA z / store the result returned by MIN into z
HLT / Halt the program
x, DEC 3
z, DEC 0
TEX, DEC 0
TEY, DEC 0
TX, DEC 0
TY, DEC 0
ONE, DEC 1
MIN, HEX 0 / Subroutine to minimum of two numbers
STA TEX / Save x into temporary variable TEX
STA TX / save x into temporary variable TX
SZA / if x is 0, return x as maximum
BUN STY / otherwise, goto STY
BUN REX
STY, LDA ONE / load 1 into AC and calculate 2's complement
CMA
INC
STA ONE / save back -1 into ONE
LDA MIN I / load second parameter y
STA TEY / Save y into temporary variable TEY
STA TY / save x into temporary variable TY
SZA / if y is 0, return y as minimum
BUN LOP / otherwise goto LOP
BUN REY
LOP, LDA TX / load x into AC
ADD ONE / subtract 1 from x (x=x-1)
STA TX / update x
SZA / if x is 0, return x as minimum
BUN NEX / otherwise, goto NEX
BUN REX
NEX, LDA TY / load y into AC
ADD ONE / do y=y-1
STA TY / update y
SZA / if y is 0, return y as minimum
BUN LOP / otherwise, goto LOP
BUN REY
REX, LDA TEX / load x and return
BUN RET
REY, LDA TEY / load y and return
RET, BUN MIN I / return to Main
END
Program:
Sample output:
Code to copy:
ORG 100 /
Origin of program is location 100
LDA x / load x
into Accumulator(AC) and pass it to GCD
BSA GCD / branch
to subroutine MIN
DEC 21 / pass 2nd
arguement(y) to MIN
STA z / store the
result returned by MIN into z
HLT
/ Halt the program
x, DEC 12
z, DEC 0
TEX, DEC 0
TEY, DEC 0
TX, DEC 0
TY, DEC 0
ONE, DEC 1
GCD, HEX 0 / Subroutine to minimum
of two numbers
STA TEX / Save x
into temparary variable TEX
STA TX / save x
into temparary variable TX
LDA GCD I / load second
parameter y
STA TEY / Save y
into temparary variable TEY
STA TY / save x
into temparary variable TY
LDA ONE
CMA
INC
STA ONE
WHL, LDA TY / while loop
CMA
INC
ADD TX /
X-Y
SZA / if X-Y is
0, goto YMX
BUN IF /
otherwise, goto IF
LDA TX
CMA
INC
ADD TY /
Y-X
SZA
/ if Y-X is 0, goto RET
BUN IF /
otherwise, goto IF
BUN RET / otherwise( if x equals y)
goto RET(and return x)
IF, LDA TEX / store x into TX and y into TY
STA TX
LDA TEY
STA TY
/ check whehter x < y or not
LOP,LDA TX / load x into AC
ADD ONE /
subtract 1 from x (x=x-1)
STA TX / update
x
SZA / if x is 0,
goto XLE (x<y)
BUN NEX /
otherwise, goto NEX
BUN XLE
NEX, LDA TY / load y into AC
ADD ONE / do
y=y-1
STA TY / update
y
SZA
/ if y is 0, goto YLE(y<x)
BUN LOP /
otherwise, goto LOP
BUN YLE
XLE, LDA TEX / if x<y , do y=y-x
CMA
INC
ADD TEY
STA TEY /
y=y-x
STA TY / save
updated x and y into TX,TY respectively
LDA TEX
STA TX
BUN WHL / repeat
the loop
YLE, LDA TEY / if y<x, do x=x-y
CMA
INC
ADD TEX
STA TEX /
x=x-y
STA TX / save
updated x and y into TX,TY respectively
LDA TEY
STA TY
BUN WHL / repeat
the loop
RET, LDA TEX / return x
BUN GCD I / return to
Main
END
Please, implement these subroutine. Write assembly language subroutines to perform the calculations listed hereunder: Table 1:...
Assembly Language 64- bit system Description: You are responsible to implement several assembly functions to perform the simple arithmetic calculations for 2 64-bit integers. These functions will use the C function signature but the main logic within this function should be inline assembly code using the ASM block similar to the assembly example shown in class. 1. long XOR ( long op1, long op2 )- xor will return the result of bit exclusive OR of op1 / op2- can use...
1. Please write a Divide-and-Conquer Java algorithm solving the following problem: Given an "almost sorted" array of distinct integers, and an integer x, return the index of x in the array. If the element x is not present in the array, return -1. "Almost sorted" means the following. Assume you had a sorted array A[0…N], and then split it into two pieces A[0…M] and A[M+1…N], and move the second piece upfront to get the following: A[M+1]…A[N]A[0]…A[M]. Thus, the "almost sorted"...
Write code to implement the following function: /* * Generate mask indicating leftmost 1 in x. Assume w=32. * For example 0xFF00 -> 0x8000, and 0x6600 --> 0x4000. * If x = 0,then return 0. */ int leftmost_one(unsigned x); Your function should follow the above bit-level integer coding rules, except that you may assume that data type int has w=32 bits. Your code should contain a total of at most 15 arithmetic, bit-wise, and logical operations. In C++ and has...
Implement the following statements using MS430 assembly instructions. You may use more than one, but you should minimize the number of instructions required. You can use both native and emulated instructions. Use hex notation for all numbers 1. (a) Move the word located in register R14 to R15 (b) Increment the word in R6 by 2. (c) Perform a bitwise ANDing of the word located at address 0x0240 with the datum in R15, placing the results in R15. (d) Rotate...
Here is the code I made, but the test case is not working, it goes wrong when the binary string convert to decimal. please help. #include "stdafx.h" #include <iostream> #include <string> #include <math.h> #include <locale> using namespace std; // function for option 1 void decToBin(int number) { int array[16]; int i = 0; for (int counter = 0; counter < 16; counter++) { array[counter] = 0; } while (number > 0) {...
Preliminaries Download the template class and the driver file. Objective Learn how to traverse a binary search tree in order. Description For the template class BinarySearchTree, fill in the following methods: insert - Inserts values greater than the parent to the right, and values lesser than the parent to the left.parameters elem - The new element to be inserted into the tree. printInOrder - Prints the values stored in the tree in ascending order. Hint: Use a recursive method to...
Implement a rabin_hash method to make the following code work: int rabin_karp_batchmatch(int bsz, /* size of bitmap (in bits) to be used */ int k, /* chunk length to be matched */ const char *qs, /* query docoument (X)*/ int m, /* query document length */ const char *ts, /* to-be-matched document (Y) */ int n /* to-be-matched document length*/) { /*if the to-be-matched document is less than k length, return false*/ if (n < k) return 0; /*start our...
I NEED HELP WITH DEBUGGING A C PROGRAM! PLEASE HEAR ME OUT AND READ THIS. I just have to explain a lot so you understand how the program should work. In C programming, write a simple program to take a text file as input and encrypt/decrypt it by reading the text bit by bit, and swap the bits if it is specified by the first line of the text file to do so (will explain below, and please let me...
COULD YOU PLEASE HELP ME************************** write a better mode computation function that uses the ideas in the word file and improves on the mode computation function in the cpp file. ===========source.cpp #include <ctime> #include <iomanip> #include <iostream> #include <string> #include <random> using namespace std; default_random_engine e(static_cast<unsigned>(time(NULL))); void fill(int a[], int size, int value) { for(int i = 0; i < size; i++) a[i] = value; } void randomFill(int a[], int size, int lb, int up) { uniform_int_distribution<int> u(lb, up); for(int...
Please Modify TestPart2 to test the correctness and efficiency of FasterDefaultList. Thanks import java.util.List; import java.util.AbstractList; import java.util.Map; import java.util.HashMap; public class DumbDefaultList<T> extends AbstractList<T> { Map<Integer,T> map; public DumbDefaultList() { map = new HashMap<Integer,T>(); } public int size() { return Integer.MAX_VALUE; } public T get(int i) { return map.get(i); } public T set(int i, T x) { return map.put(i, x); } public void add(int i, T x) { Map<Integer, T> map2 = new HashMap<Integer,T>(); for (Integer k : map.keySet())...