I wrote this program a long time ago. Post here for my archival purpose.
CPU will have 4 registers: AX, BX, CX, DX.
AX consists of two parts: AH and AL as does other registers.
The instructions op1 and op2 can be any of the following forms:
reg,reg reg,immed reg,mem mem,reg
immed (immediate value): decimal, hex number or character
This program will load asm codes from a file specified by user, get and trace every code line, parse this code line, process the code, print out in hex value and highlight changes in registers or memory caused by these codes.
support: mov, inc, dec, add, sub, mul, div, neg, and, or, xor, shl, shr, not
calculation will be performed in decimal. but display in hex.
asm code file
-asm is not case sensitive. except for immediate character.
-can be ended with “end” or not
-Between command and operand, operand and operand are spaces or tabs.
-Support inline(after code, not between code) or a separate-line comment: which always begin w/ “;”
-hex number must begin w/ a number and end w/ a character ‘h’. If hex number begins w/ a character, place 0 in front of it.
Ex: ffh have to be rewritten as 0ffh
-Character must be inside single quote. Ex: ‘a’.
If you enter more, only the first character will be used, the rest will be ignored.
Ex: ‘asdf’, only ‘a’ is used.