Question: You will write a program in a high-level language (presumably Java, but Im open to other options) that reads a text file containing ARM assembly

You will write a program in a high-level language (presumably Java, but Im open to other options) that reads a text file containing ARM assembly code and produces a text file containing the corresponding machine language*. Each line of the output file should contain 32 characters (either 0 or 1) plus a newline character.

* Note: An actual assembler would produce a flat binary file, not a text file. But its easier for me to check a text file.

The program should handle the following correctly:

All registers (includes XZR, SP, LR)

The core instructions listed below

Labels for branch instructions

Providing an error message on invalid input (both syntax errors and other problems like an immediate value that doesn't fit in the bits for that instruction format)

Your code must be thoroughly commented.

Helpful hints:

Initially assume that the input is valid do the error checking last.

The only times the colon character : is used are in labels.

If using Java, the methods Integer.toBinaryString and Integer.parseInt (with two arguments) are very much your friends.

The hardest part of this assignment is getting the jump and branch labels right. My suggestion is to process the file in two passes. The first one needs to convert pseudoinstructions so that you know how many lines they take up; pass two can then correctly calculate the binary for the labels.

Core instructions

ADD

ADDI

ADDIS

ADDS

AND

ANDI

ANDIS

ANDS

B

B.cond (for all 16 cond)

BL

BR

CBNZ

CBZ

EOR

EORI

LDUR

LSL

LSR

ASR (opcode 49A)

MOV (becomes ORR w/ XZR)

MUL

ORR

ORRI

STUR

SUB

SUBI

SUBIS

SUBS

Test File:

alpha: ADD X0, X5, X10 ADDI X3, X6, #89 ADDIS X1, X29, #4095 ADDS X8, X2, X18 bravo: AND X14, X4, X30 charlie: ANDI X27, X19, #128 ANDIS X5, X12, #120 ANDS X15, X22, X26 B echo B.EQ alpha B.NE foxtrot B.HS bravo B.LO charlie B.MI alpha B.PL delta B.VS echo delta: B.VC foxtrot B.HI bravo B.LS bravo B.GE golf B.LT charlie B.GT delta B.LE foxtrot B.AL echo B.NV alpha BL bravo BR X8 CBNZ X10, golf echo: CBZ SP, charlie EOR X9, X7, X11 EORI LR, X13, #0 LDUR X16, [SP, #-80] LSL X17, X20, #21 LSR X28, X25, #3 ASR X21, X6, #63 MOV X5, X25 MUL X23, X10, X3 ORR X3, X22, X17 ORRI X16, X24, #45 foxtrot: STUR X23, [X0, #13] SUB X19, XZR, X17 SUBI X26, X9, #1234 SUBIS X29, X12, #3 golf: SUBS X4, X8, X18 

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!