Convert the following assembly code into symbol less code by replacing each symbol (variable or label) with its corresponding value (number). Also, please label the ROM address (line number) for each real instruction.
1. Sum.asm
Assembly Code(raw with symbols) | ROM Address(line number) | Assembly Code(cleaned and without symbols) |
// Computes sum = R2 + R3// (R2 refers to RAM[2]) @R2D=M@R3D=D+M // Add R2 + R3 @sumM=D // sum = R2 + R3 |
2. Max.asm
Assembly Code(raw with symbols) | ROM Address(line number) | Assembly Code(cleaned and without symbols) |
// Computes R2=max(R0, R1)// (R0,R1,R2 refer to// RAM[0],RAM[1],RAM[2]) @R0D=M@R1D=D-M@OUTPUT_FIRSTD;JGT@R1D=M@OUTPUT_D0;JMP(OUTPUT_FIRST)@R0D=M(OUTPUT_D)@R2M=D(INFINITE_LOOP)@INFINITE_LOOP0;JMP |
3. Rect.asm
Assembly Code(raw with symbols) | ROM Address(line number) | Assembly Code(cleaned and without symbols) |
// Draws a rectangle at// the top-left corner of // the screen.// The rectangle is 16// pixels wide and R0// pixels high. @R0D=M@INFINITE_LOOPD;JLE@counterM=D@SCREEND=A@addressM=D(LOOP)@addressA=MM=-1@addressD=M@32D=D+A@addressM=D@counterMD=M-1@LOOPD;JGT(INFINITE_LOOP)@INFINITE_LOOP0;JMP |
UML Diagram of Entire Assembler Program
A brief Java refresher:
Write Java code to implement the following enum: | |
What does the following code display? String code = t0;JMP //unconditional jump ;System.out.println(code.trim()); | |
How would you extract the JMP from the code string above? Write the Java code to do so. | |
What is assigned to the variable dest ? String code = D=M;JGT;int index = code.indexOf(=);String dest = (index != -1) ?code.substring(0, index) : null; |
Write pseudocode for the following helper methods:
String cleanLine(String rawLine)
- Command parseCommandType(String cleanLine)
- boolean isValidName(String symbol)
- String decimalToBinary(int number)
CInstructionMapper |
compCodes : HashMap<String, String> destCodes : HashMap<String, String> jumpCodes : HashMap<String, String> |
+ CInstructionMapper()+ comp(mnemonic : String) : String+ dest(mnemonic : String) : String+ jump(mnemonic : String) : String |
Write pseudocode for the following Code methods:
- Code()
- String comp(String mnemonic)
- String dest(String mnemonic)
- String jump(String mnemonic)
Write pseudocode for the following SymbolTable methods:
SymbolTable |
INITIAL_VALID_CHARS : String ALL_VALID_CHARS : String symbolTable : HashMap<String, Integer> |
+ SymbolTable()+ addEntry(symbol : String, address : int) : boolean+ contains(symbol : String) : boolean+ getAddress(symbol : String) : int isValidName(symbol : String) : boolean |
- SymbolTable()
- boolean addEntry(String symbol, int address)
- boolean contains(String symbol)
- int getAddress(String symbol)
- boolean isValidName(String symbol ) //same as earlier but rewrite using constants
Parser |
+ NO_COMMAND : char // N //constants+ A_COMMAND : char // A+ C_COMMAND : char // C+ L_COMMAND : char // L inputFile : Scanner //file stuff + debugging lineNumber : int rawLine : String cleanLine : String //parsed command parts commandType : char symbol : String destMnemonic : String compMnemonic : String jumpMnemonic : String |
+ Parser(inFileName : String) //drivers+ hasMoreCommands() : boolean+ advance() : void cleanLine() : void //parsing helpers parseCommandType() : void parse() : void parseSymbol() : void parseDest() : void parseComp() : void parseJump() : void + getCommandType() : char //useful getters+ getSymbol() : String+ getDest() : String+ getComp() : String+ getJump() : String + getRawLine() : String //debugging getters+ getCleanLine() : String+ getLineNumber() : int |
- cleanLine() : void //same as part 1 but rewrite using instance variables
- parseCommandType() : void //same as part 1 but rewrite using instance variables
Write pseudocode for the following Parser methods:
- Parser(String fileName)
- boolean hasMoreCommands()
- void advance()
- void parseSymbol()
- void parseDest()
- void parseComp()
- void parseJump()
- void parse()
- Command getCommandType()
- String getSymbol()
- String getDestMnemonic()
- String getCompMnemonic()
- String getJumpMnemonic()
- String getRawLine()
- String getCleanLine()
- int getLineNumber()
Reviews
There are no reviews yet.