Skip to content

hczhcz/y86

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

79 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Yet another Y86 implementation

About Y86

Y86 is a simplified x86-like instruction set.

8 user-accessible registers:

EAX ECX EDX EBX ESP EBP ESI EDI

4 states:

AOK HLT ADR INS

Instructions:

halt nop rr/cmovXX irmovl rmmovl mrmovl OPTl jXX call ret pushl popl

ASM file example:

# Execution begins at address 0
       .pos 0
init:  irmovl Stack, %esp       # Set up stack pointer
       irmovl Stack, �p       # Set up base pointer
       call Main                # Execute main program
       halt                     # Terminate program

# Array of 4 elements
       .align 4
array: .long 0xd
       .long 0xc0
       .long 0xb00
       .long 0xa000

Main:  pushl �p
       rrmovl %esp,�p
       irmovl $4,�x
       pushl �x               # Push 4
       irmovl array,�x
       pushl �x               # Push array
       call Sum                 # Sum(array, 4)
       rrmovl �p,%esp
       popl �p
       ret

#/* $begin sum-ys 0 */
# int Sum(int *Start, int Count)
Sum:   pushl �p
       rrmovl %esp,�p
       mrmovl 8(�p),�x      # ecx = Start
       mrmovl 12(�p),�x     # edx = Count
       xorl �x,�x           # sum = 0
       andl �x,�x           # Set condition codes
       je End
Loop:  mrmovl (�x),%esi       # get *Start
       addl %esi,�x           # add to sum
       irmovl $4,�x
       addl �x,�x           # Start  
       irmovl $-1,�x
       addl �x,�x           # Count--
       jne Loop                 # Stop when 0
End:   rrmovl �p,%esp
       popl �p
       ret
#/* $end sum-ys 0 */

# The stack starts here and grows to lower addresses
       .pos 0x100
Stack:

For more details: Chapter 4 of CSAPP

Y86 Simulator

This is a 'lab' (homework) in SE101/ICS (Introduction to Computer Systems).

The original version is a 'pure' simulator, but I made a JIT compiler.

Build:

cc -m32 -o y86sim y86sim.c (tested under Clang 3.2 )

Run:

y86sim file.bin [max_steps]

Y86 Simulator (the 'max' version)

The 'max' version looks like the normal one, but there is no step counting and non-static error detecting in it.

It could execute most cases correctly and run (almost) as fast as native x86. But, it could not pass the ICS lab tests.

Y86 Assembler

This is also a 'lab' in SE101/ICS.

The implementation is based on the original framework in the course.

Build:

cc -m32 -o y86asm y86asm.c (tested under Clang 3.2 )

Run:

y86asm [-v] file.ys

-v print the readable output to screen.

License

The simulator is released under WTFPL. Keep calm and have fun with it :) Feel free to send issues and PR to me.

The assembler and the lab tests are not released under any license, so they can be used in education purpose only.

To SE101 students: DO NOT CHEAT! The code is stored in the anti-cheating code base. You know.

About

Yet another Y86 implementation

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages