程序代写代做代考 assembly interpreter Introduction

Introduction
CS 211 Homework 5
Assembly interpreter
Fall 2020
In this assignment, you’re asked to implement an interpreter for a 16-bit CPU’s assembly code. The CPU has registers but no access to main memory.
You can assume:
• all input is correctly formatted
• all arguments are the correct type
– we won’t try to jump to a non-existent location
– we won’t use a constant when a register is expected – we won’t use constants larger than registers can store
• no program will be more than 100 lines long • programs will be written in all lowercase
Registers
The machine has the following registers, all 16-bits wide, for storing signed integers (using two’s complement):
Register Purpose
ax General purpose bx General purpose cx General purpose dx General purpose
This CPU does not support referring to 8-bit subsets of 16-bit registers. 1

Instructions
Arguments to instructions are separated by a single space.
Moving data
Instruction Args Description
mov x y Copy x to y. This leaves x unchanged.
Note: y must be a register.
Arithmetic
Instruction Args add xy sub xy mul xy div xy
Description
Add x and y, place result in y
Subtract x from y, place result in y
Multiply x and y, place result in y
Divide x by y, place result in y (discards remainder)
Note: y must be a register.
Jumps
Jumps don’t use condition codes. Rather, they (may) take some arguments to compare. Also, instead of explicit labels, we use the line of the program (starting from 0) as a location to jump to.
Instruction Args jmp L
je Lxy jne Lxy jg Lxy jge Lxy jl Lxy jle Lxy
Note: L must be an integer.
2
Description
Jump to L JumptoLifx=y JumptoLifx̸=y JumptoLifx>y JumptoLifx≥y JumptoLifx