Assembly language programming I need help with this one. I need to upload c sour
ID: 3840823 • Letter: A
Question
Assembly language programming
I need help with this one.
I need to upload c source file. Thank you in advance. (one day ill buy you a Ferrari :D)
Simple Assembly Interpreter Develop a simple assembly code interpreter for a theoretical processor with the following properties. This processor only has seven instructions: lod imm32 Load a 32-bit immediate value lod mean 32 Load a 32-bit value from memory add imm32 Add a 32-bit inmediate add mem32 Add a 32-bit value from memory sub imm32 Subtract a 32-bit immediate sub med 32 Subtract a 32-bit value from memory sto mem32 Stores the result into a single memory location You can assume this simple processor has only one register and 256 32-blt memory locations. Your simple assembler will given an array containing lnstructlans and will convert the Instructions Into x86 code on the fly. You should be able to do this through a comblnation of C and Inline assembly. The only parts that have to be in assembly are the code elements for the above Instructions. For instance, a lod Instruction could become a moveax Instruction. The mem32 addresses are In terms of bytes. For Instance, an address of Dx10 would refer to the 17th byte, or the 5th Integer based Index. Immedlate values are hex numbers without a In front, Memory address are hex numbers with the Ox In front. char inesofCodeC lod 0x10 mem32 hex value add 1010 imm 32, hex value sub 11 imam 32, hex value sto 0x14" mem 32, hex value As noted, your project can use a combination of Cand assembly. You can useCstrinE processing functions from the C standard library. Your function should kook like the following: int simple Assembler(char LinesofCode, int lineCount, int memory) lines ORCode is an array of strings containing the code lines you are to execute. memory is a 256 element 32-bit integer array that is given to you. ineCount is the count of the number of lines in the linesofCode array. simpleAssembler should return a -1 if an error has occurred and 0 otherwise The following Visual Studio project wil help you get started.Explanation / Answer
Note: i need more time for terminate, i lack the function of verification of the hand of each player and compare who was the winner, the rest stay all right.
Source:
public class Poker {
String[] deck = { // cards
"AS","2S","3S","4S","5S","6S","7S","8S","9S","TS","JS","QS","KS",
"AH","2H","3H","4H","5H","6H","7H","8H","9H","TH","JH","QH","KH",
"AD","2D","3D","4D","5D","6D","7D","8D","9D","TD","JD","QD","KD",
"AC","2C","3C","4C","5C","6C","7C","8C","9C","TC","JC","QC","KC" };
private Player p1, p2;
public Poker(){ // construct
Scanner sc = new Scanner(System.in);
String name;
System.out.print("Enter player 1 name: ");
name = sc.nextLine(); //read a string
p1 = new Player(name);
System.out.print("Enter player 2 name: ");
name = sc.nextLine(); //read a string
p2 = new Player(name);
}
public void EnterData(int type){ // Enter User data
Scanner sc = new Scanner(System.in);
String card;
System.out.println();
if (type == 1)
System.out.println(p1.name+":");
else
System.out.println(p2.name+":");
for (int i=0; i<5; i++){
card = "";
while(true){
System.out.print("Enter a Card: ");
card = sc.nextLine(); //read a card
card = card.toUpperCase();
if (verifyCard(card)){
if (verifyDuplicate(card)){
System.out.println("Duplicate Card. Try again.");
}else
break;
}else
System.out.println("Invalid Card. Try again.");
}
if (type == 1)
p1.setCard(i, card);
else
p2.setCard(i, card);
}
}
public boolean verifyCard(String card){ // verify card exist
for (int i=0; i<deck.length; i++){
if (card.equals(deck[i]))
return true;
}
return false;
}
public boolean verifyDuplicate(String card){ // verify card duplicate
for (int i=0; i<5; i++){
if (p1.getCard(i) != -1 && card.equals(deck[p1.getCard(i)]))
return true;
if (p2.getCard(i) != -1 && card.equals(deck[p2.getCard(i)]))
return true;
}
return false;
}
public void printPlayerCards(){ // print values players
System.out.println();
System.out.println();
System.out.println(p1.name + ": " + p1.getCardString(0) + " "+ p1.getCardString(1) + " "+ p1.getCardString(2) + " "+ p1.getCardString(3) + " "+ p1.getCardString(4) + " ");
System.out.println(p2.name + ": " + p2.getCardString(0) + " "+ p2.getCardString(1) + " "+ p2.getCardString(2) + " "+ p2.getCardString(3) + " "+ p2.getCardString(4) + " ");
System.out.println();
System.out.println();
}
public void play(){ // play game
Scanner sc = new Scanner(System.in);
String resp;
while(true){
EnterData(1); // data player1
EnterData(2); // data player2
printPlayerCards();
// winner
System.out.print("Play again (Y/N)? ");
resp = sc.nextLine(); //read a response
resp = resp.toUpperCase();
if (resp.equals("N")) // play again Y/N?
break;
}
}
public static void main(String[] args){ // method main
Poker pk = new Poker();
pk.play();
}
class Player{ // class player
String name;
private Card c[]; // cards
public Player(String n){ // construct
name = n;
c = new Card[5]; // five cards
for (int i=0; i<c.length; i++)
c[i] = new Card(-1);
}
public String verifyHand(){ // :/
String hand="";
// i need more time for terminate
return hand;
}
public void setCard(int type, String value){ // set Card pos
c[type].setCard( extractPos(value) );
}
public int getCard(int type){ // return card pos
int ret = c[type].getCard();
return ret;
}
public String getCardString(int type){ // return card String
String ret = deck[c[type].getCard()];
return ret;
}
public int extractPos(String value){ // extract pos card in deck
for (int i=0; i<deck.length; i++)
if (value.equals(deck[i]))
return i;
return -1;
}
}
class Card{ // class Card
int cardPos;
public Card(int p){ // construct
setCard(p);
}
public int getCard(){ // return card pos
return cardPos;
}
public void setCard(int p){ // set card pos
cardPos = p;
}
}
}