Y86小实验————引言

【说明】

             前些天拜读《深入理解计算机系统》这本神作,读到第四章的时候,作者提出了一个迷你的计算机系统设计原理,称之为Y86 ,我觉得挺好玩的。就自己实现了这个Y86小系统,内容包含两个可执行文件,

            一个是汇编器,运行后,可用指定汇编文件(Y86汇编码),来生成一个二进制内存映像,以及一个反汇编文件用于观察。

           一个迷你计算机系统,可以一条一条读取二进制映像中的指令,解析执行,模拟指令对内存,寄存器以及状态位的改变。执行后打印迷你系统的状态,以及内存信息。

 

 

【下载地址】

            我将源代码上传了,可以免费下载 http://download.youkuaiyun.com/detail/u013476840/6978643

            写的时间不长,没怎么测试,可能存在一些小BUG,大家发现了给我留个言,我修改,谢谢啦微笑

            代码写得不是太好,大家多多包涵。。。。。可怜

 

【使用示例】

            首先在主目录下make  生成 2个重要的文件 一个是 AS    一个是y86_Sys

            1】实例汇编文件test.S  ( 来自《深入理解计算机系统》第四章)

                 

# Execution begins at address 0
.pos 0
    init: irmovl Stack, %esp # Set up stack pointer
    irmovl Stack, %ebp # 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 %ebp
    rrmovl %esp,%ebp
    irmovl $4,%eax
    pushl %eax # Push 4
    irmovl array,%edx
    pushl %edx # Push array
    call Sum # Sum(array, 4)
    rrmovl %ebp,%esp
    popl %ebp
    ret
    
    # int Sum(int *Start, int Count)
    Sum: pushl %ebp
    rrmovl %esp,%ebp
    mrmovl 8(%ebp),%ecx # ecx = Start
    mrmovl 12(%ebp),%edx # edx = Count
    xorl %eax,%eax # sum = 0
    andl %edx,%edx # Set condition codes
    je End
    Loop: mrmovl (%ecx),%esi # get *Start
    addl %esi,%eax # add to sum
    irmovl $4,%ebx #
    addl %ebx,%ecx # Start++
    irmovl $-1,%ebx #
    addl %ebx,%edx # Count--40 
    jne Loop # Stop when 0
    End: rrmovl %ebp,%esp
    popl %ebp
    ret
    
   # The stack starts here and grows to lower addresses
    .pos 0x100
    Stack:


 

           2】汇编器

                       执行

                       生成的文件中有一个.dis 是反汇编

                       

|                        | # Execution begins at address 0
|0x00000:                | .pos 0
|0x00000: 30f400010000   |     init: irmovl Stack, %esp # Set up stack pointer
|0x00006: 30f500010000   |     irmovl Stack, %ebp # Set up base pointer
|0x0000c: 8024000000     |     call Main # Execute main program
|0x00011: 00             |     halt # Terminate program
|                        | # Array of 4 elements
|                        |     .align 4
|0x00014: 0d000000       |     array: .long 0xd
|0x00018: c0000000       |     .long 0xc0
|0x0001c: 000b0000       |     .long 0xb00
|0x00020: 00a00000       |     .long 0xa000
|0x00024: a05f           |     Main: pushl %ebp
|0x00026: 2045           |     rrmovl %esp,%ebp
|0x00028: 30f004000000   |     irmovl $4,%eax
|0x0002e: a00f           |     pushl %eax # Push 4
|0x00030: 30f214000000   |     irmovl array,%edx
|0x00036: a02f           |     pushl %edx # Push array
|0x00038: 8042000000     |     call Sum # Sum(array, 4)
|0x0003d: 2054           |     rrmovl %ebp,%esp
|0x0003f: b05f           |     popl %ebp
|0x00041: 90             |     ret
|                        |     
|                        |     # int Sum(int *Start, int Count)
|0x00042: a05f           |     Sum: pushl %ebp
|0x00044: 2045           |     rrmovl %esp,%ebp
|0x00046: 501508000000   |     mrmovl 8(%ebp),%ecx # ecx = Start
|0x0004c: 50250c000000   |     mrmovl 12(%ebp),%edx # edx = Count
|0x00052: 6300           |     xorl %eax,%eax # sum = 0
|0x00054: 6222           |     andl %edx,%edx # Set condition codes
|0x00056: 7378000000     |     je End
|0x0005b: 506100000000   |     Loop: mrmovl (%ecx),%esi # get *Start
|0x00061: 6060           |     addl %esi,%eax # add to sum
|0x00063: 30f304000000   |     irmovl $4,%ebx #
|0x00069: 6031           |     addl %ebx,%ecx # Start++
|0x0006b: 30f3ffffffff   |     irmovl $-1,%ebx #
|0x00071: 6032           |     addl %ebx,%edx # Count--40 
|0x00073: 745b000000     |     jne Loop # Stop when 0
|0x00078: 2054           |     End: rrmovl %ebp,%esp
|0x0007a: b05f           |     popl %ebp
|0x0007c: 90             |     ret
|                        |     
|                        |    # The stack starts here and grows to lower addresses
|0x00100:                |     .pos 0x100
|0x00100:                |     Stack:


 

                   3】迷你虚拟机运行 test.bin

                                

Y86 Tools (Student Distribution) Copyright (c) 2002, R. Bryant and D. O Hallaron, All rights reserved. May not be used, modified, or copied without permission. This directory contains the student distribution of the Y86 tools. It is a proper subset of the master distribution, minus the solution files found in the master distribution. yas Y86 assembler yis Y86 instruction (ISA) simulator hcl2c HCL to C translator ssim SEQ simulator ssim+ SEQ+ simulator psim PIPE simulator y86-code/ Examples programs and and benchmark testing scripts ptest/ Scripts for detailed automated regression testing 1. Building the Y86 tools The Y86 simulators can be configured to support TTY and GUI interfaces. A simulator running in TTY mode prints all information about its run-time behavior on the terminal. Hard to understand what s going on, but useful for automated testing, and doesn t require any special installation features. A simulator running in GUI mode uses a fancy graphical user interface. Nice for visualizing and debugging, but requires installation of Tcl/Tk on your system. To build the Y86 tools, perform the following steps: NOTE: If your instructor prepared this distribution for you, then you can skip Step 1 and proceed directly to Step 2. The Makefile will already have the proper values for GUIMODE, TKLIBS, and TKINC for your system. Step 1. Decide whether you want the TTY or GUI form of the simulators, and then modify ./Makefile in this directory accordingly. (The changes you make to the variables in this Makefile will override the values already assigned in the Makefiles in the seq and pipe directories.) Building the GUI simulators: If you have Tcl/Tk installed on your system, then you can build the GUI form by initializing the GUIMODE, TKLIBS, and TKINC variables, as appropriate for your system. (The default values work for Linux systems.) Assigning GUIMODE=-DHAS_GUI causes the necessary GUI support code in the simulator sources to be included. The TKLIBS variable tells gcc where to look for the libtcl.so and libtk.so libraries. And the TKINC variable tells gcc where to find the tcl.h and tk.h header files. Building the TTY simulators: If you don t have Tcl/Tk installed on your system, then build the TTY form by commenting out all three of these variables (GUIMODE, TKLIBS, and TKINC) in the Makefile. Step 2: Once you ve modified the Makefile to build either the GUI or TTY form, then you can construct the entire set of Y86 tools by typing unix> make clean; make 2. Files Makefile Builds the Y86 tools README This file misc/ Source files for the Y86 assembler yas, the Y86 instruction simulator yis, and the isa.c file that is used by the -t option of the processor simulators to check the results against the ISA simulation. seq/ Code for the SEQ and SEQ+ simulators. Contains HCL files for labs and homework problems that involve modifying SEQ. pipe/ Code for the PIPE simulator. Contains HCL files for labs and homework problems that involve modifying PIPE. y86-code/ Example .ys files from CS:APP and scripts for conducting automated benchmark teseting of the new processor designs. ptest/ Automated regression testing scripts for testing processor designs.
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值