Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Problem 5 : [ 4 mark of 1 0 : 1 public / 1 release + secret / 2 secret ] ( filename: asm.c (

Problem 5: [4 mark of 10: 1 public /1 release+secret /2 secret]
(filename: asm.c(c|pp))
In this problem, you will write a program that reads a list of mips assembly tokens from standard in, will
calculate the location of every label, and will substitute a labels location everywhere the label is used.
The output of this program is a symbol table on standard error, and a parameter list for compileLine (from
assignment 1) on standard out. Each numerical parameter must be printed as an unsigned 32 bit decimal number.
The symbol table must be printed on standard error. The label's lexeme and its address must be printed on the
same line, with the label lexeme first, a space character, then the location in memory as a decimal number. The
labels must be in the same order as they are defined.
The input to the program is a list of tokens: one token per line, with the token type, a space, the token lexeme,
and a unix newline character. The token types are the same as what's defined in Assignment 2 Problem 5, with
one addition. The NEWLINE token has been added to delineate new lines from the mips assembly input. The
NEWLINE token type doesn't have a lexeme.
Consider the mips assembly program:
foo:
beq $0, $1, bar
bar:
add $1, $2, $3
The tokenization of this program is:
LABEL foo:
NEWLINE
ID beq
REG $0
COMMA comma
REG $1
COMMA ,
ID bar
NEWLINE
LABEL bar:
NEWLINE
ID add
REG $1
COMMA ,
REG $2
COMMA ,
REG $3
NEWLINE
The output on standard error must be:
foo 0
bar 4
The output of the assembler on standard out will be a list of parameters for compileLine(), one line per call to
compileLine, space separated, with no quote characters. The integer parameters can be printed in hex or decimal.
Your output cannot contain any labels--it must replace every label use with the label address. For the example
input above, the output must be:
beq 010
add 123
You are not required to use any of the starter code: you can remove it or change it as you see fit. The correctness
of your program is evaluated by checking its output. We are not checking to see if you use compileLine() or not.
c++
racket
If any errors are present in the tokenized input mips assembly program, your assembler must print ERROR on
standard error. It must stop processing input and terminate. Your error message can include a description of the
error, at your digression.
Each mips instruction will be on only one line.
Your assembler is required to handle the .word directive. For the line .word X, your program should output word
Y 00, where Y is whatever value X is when interpreted as an unsigned 32 bit decimal number.
Two new tools are provided cs241.tokenizer and cs241.compileline. cs241.tokenizer accepts a mips assembly
program and prints a list of tokens suitable for this problem. cs241.compileline accepts the output of this
problem and assembles it into mips machine code.
Corrections/Clarifications:
Added clarification on how to output .word directives (June 6)
image text in transcribed

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

Step: 3

blur-text-image

Ace Your Homework with AI

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

Get Started

Students also viewed these Databases questions