CS计算机代考程序代写 Java assembly algorithm / Usage: /

/ Usage: /
/ – compile the Java files: /
/ javac Sim.java SimIO.java Run.java /
/ – execute /
/ java Run eg-01.txt /
/ /
/ This file contains a machine language program to calculate X / Y /
/ for two positive numbers. /
/ /
/ The quotient is stored at the address 10 and the rest at 101 /
/ /
/ Format of this file: : /
/ – Each line must contain at least one character. /
/ – If the first character is not blank (space) then all the charac- /
/ ters up to and including the last occurrence of the chracter are /
/ ignored — this is considered a comment. Here, the character / /
/ has been used but any non-blank character would do. /
/ – For this (optional) comment, there will be numbers, zero or more /
/ made of 1 or 2 digits, separated by blanks. These integers /
/ are read and saved in contiguous memory locations starting at /
/ the address 0. /
/ /
/ It is useful to place a single machine instruction per line. /
/ Hence, the first number of each line is its OPCODE. /
/ If the instruction has an operand, the opcode is followed by one /
/ or more numbers, representing the two high digits of the address /
/ and 2 other digits representing the low part of this address. /
/ For example, the operand 1234 will be written 12 34. /
/ /
/ In order to understand the meaning of each machine instruction /
/ you will find on each line the equivalent instruction in assembly /
/ language (as a comment). . /
/ /
/ This algorithm subtract of X the value Y until X is less than Y. /
/ The number of subtractions represents the quotient while the final /
/ value of X represents the rest. /
/ /
/ Here is the pseudo code for the machine language program. /
/ Some statements necessitate more than one machine instruction, /
/ the correspondence is indicated with labels. /
/ /
/ [ 1] set Quotient to zero /
/ [ 2] load X into the accumulator /
/ [ 3] subtract the value Y from the accumulator /
/ [ 4] if the value of the accumulator is negative go to [7] /
/ [ 5] add 1 to the Quotient /
/ [ 6] go to [3] /
/ [ 7] add Y to the accumulator /
/ [ 8] store the value of the accumulator into Reminder /
/ [ 9] display Quotient /
/ [10] display Reminder /
/ [11] halt /
/ /
/ Here is machine code /
/ /
/ Table of constants and variable (memory map) /
/ X = memory address 42 /
/ Y = memory address 43 /
/ Quot = memory address 44 /
/ Rem = memory address 45 /
/ Temp = memory address 46 /
/ /
/ Assembly language opcode operand /
/ parts /
/ high low /
/[1] CLA / 08
/ STA Quot / 39 00 44
/[2] LDA X / 91 00 42
/[3] SUB Y / 61 00 43
/[4] JN [7] / 19 00 29
/[5] STA Temp / 39 00 46
/ LDA Quot / 91 00 44
/ INC / 10
/ STA Quot / 39 00 44
/ LDA Temp / 91 00 46
/[6] JMP [3] / 15 00 07
/[7] ADD Y / 99 00 43
/[8] STA Rem / 39 00 45
/[9] DSP Quot / 01 00 44
/[10] DSP Rem / 01 00 45
/[11] HLT / 64
/X BYTE 25 / 25
/Y BYTE 07 / 07
/Quot BYTE 00 / 00
/Rem BYTE 00 / 00
/Temp BYTE 00 / 00