Language Description

About Emu86

This is an open source project written by Gene Callahan, Abhishek Ramchandran, Varun Chopra, Nathan Conroy, Cindy Lee, and Nanda Kishore Kalidindi. The goal is to create a simple learning tool to introduce students to assembly language programming in a class on, say, operating systems or compilers, where the focus is not assembly language, and actually using an assembler would be a distraction from the main theme of the course. It includes a (growing) subset of x86 assembler instructions. It currently supports 2 x86 flavors: Intel and AT&T assembly language.
As of right now, we do not cover these AT&T addressing modes: (%ebx, %eax, 2) and var(, 1). If needed, please contact us.

x86 Assembly Guide

Here is a page from the University of Virginia Computer Science Department that gives a basic guide to Intel x86 assembly language, which we have followed in creating our emulator:
Guide to Intel x86 assembly.

In addition, here is a page from the Yale FLINT Group that gives a basic guide to AT&T x86 assembly language.
Guide to AT&T x86 assembly.

Sample Programs

Here are some sample programs written in our emulator, as illustrations of what can, at the moment, can be accomplished with it. (Of course, far lengthier programs are possible, but student exercises would typically be brief, like these samples.)

Intel Programs
AT&T Programs
MIPS Assembler Programs
MIPS Mnemonic Machine Language Programs
The Data Section

This section is preceded by the directive ".data". If you have a data section, you must start the program section with the directive ".text". The data section allows the declaration of names for memory locations.

We attempted to read from templates/data.txt but failed.

Instructions Available

Some of these are only partially done, i.e., some variant of an instruction may not work. We will do our best to note that where possible.
In the syntax descriptions, we have:

  • con: constant
  • lbl: label
  • mem: memory location
    A memory location may be designated by [num], where num is the actual address, or by [reg], where reg holds the memory address.
  • reg: register
Intel
Interrupts

int

Syntax
  • INT con
Description

The behavior of INT depends on both its "con" operand as well as the value of the EAX register. See the descriptions of specific interrupt commands below. We will build various "interrupt" handlers as needed. At present, we only have two: INT 22, with EAX set to 0, to get a key from the keyboard. And we only pretend the key is from the keyboard, since we are running on the Internet, and can't read the user's keyboard. And INT 32, to exit the program. There should be a 0 in EAX.

Data Movement

mov

Syntax
  • MOV reg, reg
  • MOV reg, con
  • MOV reg, mem
  • MOV mem, reg
  • MOV mem, mem
Description

Copies the value of op2 to the location mentioned in op1.


pop

Syntax
  • POP reg
  • POP mem
Description

POPS the topmost value out of the stack. Decrements the stack pointer. Can move the stack value to a memory location or register.


push

Syntax
  • PUSH reg
  • PUSH con
  • PUSH mem
Description

PUSHES the value into the stack with reference to the stack pointer position (ESP). Increments the stack pointer automatically, everytime a PUSH is called. Callable to store a memory value, register value, and constant value to the stack.


lea

Syntax
Control Flow

cmp

Syntax
  • CMP reg, reg
  • CMP reg, mem
  • CMP reg, con
Description

Compares op1 and op2, and sets (right now) the SF and ZF flags. It is not clear at this moment how to treat the OF and CF flags in Python, since Python integer arithmetic never carries or overflows!


jmp

Syntax
  • JMP lbl

je

Syntax
  • JE lbl
Description

Jumps if ZF is one.
Equivalent name: JZ


jne

Syntax
  • JNE lbl
Description

Jumps if ZF is zero.
Equivalent name: JNZ


jg

Syntax
  • JG lbl
Description

Jumps if SF == 0 and ZF == 0.
Equivalent name: JLNE


jge

Syntax
  • JGE lbl
Description

Jumps if SF == 0.


jl

Syntax
  • JL lbl
Description

Jumps if SF == 1.
Equivalent name: JGNE


jle

Syntax
  • JLE lbl
Description

Jumps if SF == 1 or ZF == 1.


call

Syntax
  • CALL lbl
Description

Pushes value of EIP to stack and jumps to the internal subroutine.


ret

Syntax
  • RET
Description

Pops value from stack to EIP and returns control to the the line after the subroutine call.

Arithmetic and Logic

add

Syntax
  • ADD reg, reg
  • ADD reg, mem
  • ADD reg, con

sub

Syntax
  • SUB reg, reg
  • SUB reg, mem
  • SUB reg, con

imul

Syntax
  • IMUL reg, reg
  • IMUL reg, mem
  • IMUL reg, con

and

Syntax
  • AND reg, reg
  • AND reg, mem
  • AND reg, con

or

Syntax
  • OR reg, reg
  • OR reg, mem
  • OR reg, con

xor

Syntax
  • XOR reg, reg
  • XOR reg, mem
  • XOR reg, con

shl

Syntax
  • SHL reg, reg
  • SHL reg, mem
  • SHL reg, con

shr

Syntax
  • SHR reg, reg
  • SHR reg, mem
  • SHR reg, con

not

Syntax
  • NOT reg

inc

Syntax
  • INC reg

dec

Syntax
  • DEC reg

neg

Syntax
  • NEG reg

idiv

Syntax
  • IDIV reg
Description

The idiv instruction divides the contents of the 64 bit integer EDX:EAX (constructed by viewing EDX as the most significant four bytes and EAX as the least significant four bytes) by the specified operand value. The quotient result of the division is stored into EAX, while the remainder is placed in EDX.

MIPS
Interrupts

SYSCALL

Syntax
  • SYSCALL
Description

Exits program

Data Movement

LW

Syntax
  • LW reg, reg
  • LW reg, disp(reg)
Description

Copies the value of op2 to the location mentioned in op1.


SW

Syntax
  • SW reg, reg
  • SW reg, disp(reg)
Description

Copies the value of op2 to the location mentioned in op1.

Control Flow

slt

Syntax
  • SLT reg, reg, reg
Description

Compares op2 and op3, and sets (right now) the SF and ZF flags. It is not clear at this moment how to treat the OF and CF flags in Python, since Python integer arithmetic never carries or overflows! Store the result of SF flag into op1


slti

Syntax
  • SLTI reg, con, reg
  • SLTI reg, reg, con
Description

Compares op2 and op3, and sets (right now) the SF and ZF flags. It is not clear at this moment how to treat the OF and CF flags in Python, since Python integer arithmetic never carries or overflows! Store the result of SF flag into op1


J

Syntax
  • J lbl
  • J loc

JAL

Syntax
  • JAL loc

Jr

Syntax
  • Jr reg

BEQ

Syntax
  • BEQ reg, reg, con
Description

Jumps if registers are equal.


BNE

Syntax
  • BNE reg, reg, con
Description

Jumps if registers are equal.

Arithmetic and Logic

ADD

Syntax
  • ADD reg, reg, reg

ADDI

Syntax
  • ADDI reg, reg, con

SUB

Syntax
  • SUB reg, reg, reg

MULT

Syntax
  • MULT reg, reg

AND

Syntax
  • AND reg, reg, reg

AND

Syntax
  • ANDI reg, reg, con

OR

Syntax
  • OR reg, reg, reg

OR

Syntax
  • ORI reg, reg, con

NOR

Syntax
  • NOR reg, reg, reg

XOR

Syntax
  • XOR reg, reg, reg

sll

Syntax
  • SLL reg, reg, con

srl

Syntax
  • SRL reg, reg, con

DIV

Syntax
  • DIV reg, reg
Description

The div instruction divides the contents of the two registers. The quotient result of the division is stored into LO, while the remainder is placed in HI.


mfhi

Syntax
  • MFHI reg
Description

Moves the value from the HI register into the destination register given.


mflo

Syntax
  • MFLO reg
Description

Moves the value from the LO register into the destination register given.

User Interface Features

Clicking on any register will display its value in binary.