Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Convert Hex To Dec in java with HashMap and put in .txt file... I'm making a compiler for assembler in JAVA. My program after several

Convert Hex To Dec in java with HashMap and put in .txt file...

I'm making a compiler for assembler in JAVA. My program after several processes leaves a text file as follows. 02TLIGHT2.ASM file with this:

CLO Start: MOV AL,0 (When a single number exists, a 0 is added before in the conversion to hexadecimal) OUT 01 MOV AL,FC OUT 01 JMP Start END

Im trying by means of my hashmap convert the commands to his assigned hexadecimal value and put it in a text file in the same format?

What i can be doing wrong?

Sample program output i need in 02TLIGHTHexa.ASM file:

FE

DO 00 00

F1 01

DO 00 FC

F1 01

C0 F6

+++++++++++++++++++++++++CODE+++++++++++++++++++++++++

/* * To change this license header, choose License Headers in Project Properties. * To change this template file, choose Tools | Templates * and open the template in the editor. */ package hexap;

import java.io.*; import java.util.ArrayList; import java.util.Arrays; import java.util.HashMap; import java.util.List; import java.util.regex.*; import static jdk.nashorn.internal.objects.NativeArray.map; //import static softwaresistemas.CambiaReg.CambiaReg; //import static softwaresistemas.eliminaContenido.eliminaContenido;

/** * * @author Naf_Ross */ public class HexaP {

/** * @param args the command line arguments */ public static void main(String[] args) throws FileNotFoundException, IOException { String linea; HashMap map=new HashMap(); map.put("MOV","D0"); map.put("ADD","A0"); map.put("SUB", "A1"); map.put("MUL", "A2"); map.put("DIV","A3" ); map.put("INC", "A4"); map.put("DEC", "A5"); map.put("AND","AA"); map.put("OR","AB"); map.put("XOR","AC"); map.put("NOT","AD" ); map.put("ROL","9A" ); map.put("ROR", "9B"); map.put("SHL", "9C"); map.put("SHR", "9D"); map.put("CMP","DA" ); map.put("JMP","C0" ); map.put("JZ", "C1"); map.put("JNZ","C2" ); map.put("JS","C3" ); map.put("JNS", "C4"); map.put("JO","C5" ); map.put("JNO", "C6"); map.put("CALL","CA" ); map.put("RET", "CB"); map.put("INT","CC" ); map.put("IRET","CD" ); map.put("POP","E1" ); map.put("PUSH","E0" ); map.put("PUSHF","EA" ); map.put("POPF","EB" ); map.put("IN","F0" ); map.put("OUT","F1" ); map.put("CLO","FE" ); map.put("HALT","00" ); map.put("NOP", "FF"); map.put("STI", "FC"); map.put("CLI", "FD"); map.put("ORG", ""); map.put("DB","" ); map.put("AL","00" ); map.put("BL","01" ); map.put("CL","02" ); map.put("DL","03" ); File archivoFuente = new File ("C:/Program Files/Ensamblador/02TLIGHT2.ASM"); FileReader fr = new FileReader (archivoFuente); BufferedReader br = new BufferedReader(fr); FileWriter archivoMaquina = new FileWriter("C:/Program Files/Ensamblador/02TLIGHTHexa.ASM"); PrintWriter pw = new PrintWriter(archivoMaquina);

while ((linea=br.readLine())!=null) { // while que leerea todo el archivo linea = linea.trim(); String[] lineaToPrint = linea.split(",|\\s"); String[] counterToPrint = linea.split(",|\\s"); int i; for(i=0; i

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Concepts of Database Management

Authors: Philip J. Pratt, Mary Z. Last

8th edition

1285427106, 978-1285427102

More Books

Students also viewed these Databases questions