Question

format of input file: Col 1-8 label optional Col 9 blank Col 10 + optional Col...

format of input file:

Col 1-8 label optional

Col 9 blank

Col 10 + optional

Col 11-17 mneumonic

Col 18 blank

Col 19 #, @, = ... optional

Col 20-29 (operand) label, register, ',',X optional ...

Col 30-31 blank

Col 32-80 comments optional (NO PERIOD REQUIRED)

In java I am writing a program to construct a symbol table and calculate addressses based off this args[0]:

Imput file format

LABEL INSTRUCTION OPERAND

imput.txt file.

ADDRES START 100 //This is the starting address  
. tests pc forward addressing
. tests base addressing
. tests pc backward addressing
NOW +LDB #BEGIN load base register // +LDB is a 4 byte instruction so next lines address is 104 (if a +is infront of instruction 4 bytes otherwise 3 bytes)
XXX BASE BEGIN tell assembler //assembler directive so next line addess stil 104
YYY LDA BE A <- (m..m+2) //LDA is a 3 byte instruction so next address is 107
EN RESW 4 //(Reserve words)RESW normally 3 byte instuction but 4 words so 12 bytes or C in hex, next address is 113
BE WORD 2 // WORD is 3 byte constant no matter how many, next address is 116
BEGIN RESW 1 // one RESW so add 3 bytes to previous address, next address is 119
JUNK RESW 2200 // 2200 RESW's = 6600 bytes(3*2200) = 19C8 in hex. So 19C8 +119 = next address 1AE1
THERE RESW 1 //RESW = 3 bytes next address is 1AE4
ZZZ LDA JUNK //LDA = 3 bytes next address is 1AE7
MMM STA THERE // STA = 3 bytes next address is 1AEA
END NOW

I want to write to a output file that caluclates the address and puts them on the left side. of the origional input file.

sample output file:

0100 ADDRES START 100
. tests pc forward addressing
. tests base addressing
. tests pc backward addressing
0100 NOW +LDB #BEGIN load base register
0104 XXX BASE BEGIN tell assembler  
0104 YYY LDA BE A <- (m..m+2)   
0107 EN RESW 4   
0113 BE WORD 2   
0116 BEGIN RESW 1
0119 JUNK RESW 2200   
1AE1 THERE RESW 1   
1AE4 ZZZ LDA JUNK
1AE7 MMM STA THERE   
1AEA END NOW

0 0
Add a comment Improve this question Transcribed image text
Answer #1

char firCol[8];                   //first 8 characters including delimiters
    char space[1] = {' '};            //guaranteed space
    char secCol[1] = {' '};           //space or '+'
    char thirCol[7];                  //word of length -7 but if shorter includes delitimers
    char forCol[1] = {' '};           //guaranteed space
    char fifCol[10];                  //sames of 7 but length
    char comm[52];                    // length 52 char and delimitrer

    memset(firCol, ' ', 8);
    memset(thirCol, ' ', 7);
    memset(comm, ' ', 52);

    f = fopen(argv[1], "r");                                                         

    memset(info, 0, sizeof(struct Account) * TABLE_SIZE);

      while(EOF != fscanf(f, "%8c %1c %1c %7c %1c %10c %52c", firCol, space, secCol, thirCol, forCol, fifCol, comm))
      {
        pass1(info, firCol, space, secCol, thirCol, forCol, fifCol, comm);
      }

OUTPUT:

    100    ADDRES   START    100                               
    100    NOW      +LDB     #BEGIN              LOAD BASE REGISTER 
    104    XXX       BASE     BEGIN              TELL ASSEMBLER  
    104    YYY       LDA      BE                 A <- (M..M+2)    
    107    EN        RESW     4                  
    113    BE        WORD     2                              
    116    BEGIN     RESW     1
    119    JUNK      RESW     2200                              
    1ae1   THERE     RESW     1                              
    1ae4   ZZZ       LDA      JUNK                               
    1ae7   MMM       STA      THERE                              
    1aea                END      NOW   
Add a comment
Know the answer?
Add Answer to:
format of input file: Col 1-8 label optional Col 9 blank Col 10 + optional Col...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • The second phase of your semester project is to write pass one of a two‑pass assembler...

    The second phase of your semester project is to write pass one of a two‑pass assembler for the SIC assembler language program. As with Phase 1, this is to be written in C (not C++) and must run successfully on Linux. Pass one will read each line of the source file, and begin the process of translating it to object code. (Note: it will be to your advantage to have a separate procedure handle reading, and perhaps tokenizing, the source...

  • Group Project 1 The Micro-1 Processor Simulation <Micro-1 Computer> Here's the organization of a computer equipped...

    Group Project 1 The Micro-1 Processor Simulation <Micro-1 Computer> Here's the organization of a computer equipped with a Micro-1 processor Memory contains an array of integer cells: int cell[] = new int[CAP]; where CAP is the capacity of memory. Initially this is set to 256. Internally, the Micro-1 processor is equipped with eight 32-bit data/address registers and two 32 bit control registers: PC, the program counter, contains the address of the next instruction to execute. IR, the instruction register, contains...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT