禁止显示桌面图标等设置

禁止显示桌面:

        XP系统中,右键点击桌面空白处,将"排列图标"中"显示桌面图标"前的勾去掉,桌面上就没图标了。现在我想禁用显示桌面图标这项。

禁用右键的某项设置:

        开始-运行-输入gpedit.msc-用户配置-管理模版-双击桌面-在右边找到“隐藏和禁用桌面项目”的项,双击,将其设置为“已启用”,确定退出然后重启或注销一次就可以了
要想恢复的话就按上面步骤把刚才的启用改为禁用就可以了

将桌面快捷方式显示到任务栏:

        任务栏上右击,在菜单中选择“工具栏”选择“桌面”即可。

Python 借助Visa驱动在仪器控制中的应用

前言

今天有空又琢磨了一下 Python和Visa驱动在仪器控制中的用法。以前自学过Python,明白它的简洁、优雅和强大,可是一直没有机会好好用起来,今天就借助文档和网络加上还残存的一点记忆,慢慢摸索一下,再一次坚定了信念:python真的很好很强大!

另外,发现了记忆和理解力真是个好奇怪的东西,以前自学Python时有些概念不甚明白,有些名词也不明白其含义。借助Python用Pyvisa也对仪器进行过控制,但总是觉得还是没有真正理解和掌握他们的妙处,甚至并不敢将它们来真用于工作。于是,每每浏览网页或看新闻的时侯看到Python就觉得心被刺激一下,于是就捡起来看看温习温习,久而久之发现居然也慢慢掌握了,也不怕了,今天一通练习之后,好像突然突然醍醐灌顶了~(很可能因为今天睡到13:00+两包速溶咖啡刺激,导致的头脑比较清楚) 于是乎,诞生此作和相关实验。

开发环境安装与配置

1、下载并安装 Python2.5

        Python2.3也可以(Python2.6/2.7估计也可以,因为接下来安装的Pyvisa1.3依赖于Python2.3及其以上版本),但是,由于Python3.x版本在语法上和Python2.x版本变化比较大,现在作为python的另一个分支出现,因此,本文所涉及内容不能在Python3.x版本上运行(如Python3.2就不能进行本文的实验)。

      如果带电脑已经安装了其他版本的Python,最好先卸载,避免运行代码是版本冲突。

2、安装 VISA-430 full版(开发版)

        这是NI提供的专门用于仪器控制的驱动程序,可以免费从NI网站下载:http://joule.ni.com/nidu/cds/view/p/id/988/lang/en,对应下载链接:http://ftp.ni.com/support/softlib/visa/NI-VISA/4.3/win32/visa430full.exe (302MB)

        可以直接借助这个驱动通过对应的接口(USB,RS232,GPIB,LAN...),对连接在接口上的仪器进行控制。当然,仪器本身也需要有对应的连接接口和支持VISA的相关接口驱动标准(如,如果使用USB控制仪器,则仪器必须有USB接口,并且是USB-TMC类从设备,才能通过VISA进行控制)。

3、下载并安装 PyVISA

2.5?  哪里下载?

有打包好的基于Python2.6的安装包,下载页面:http://code.google.com/p/pythonxy/downloads/detail?name=pyvisa-1.3_py26.exe&can=2&q=,下载链接:http://pythonxy.googlecode.com/files/pyvisa-1.3_py26.exe

常见汇编开发工具 简介

转自http://www.aogosoft.com/masmplus/

MASMPlus 自带各种类型的开发例程和框架,可以迅速基于汇编开发各种应用程序(dos, win32, 窗口应用程序)或DLL,甚至windows驱动

MASMPlus 是一个使用纯 MASM 编写的 MASM Integrate Develop Environment.

  专业汇编程序员90%均使用 MASM,为它开发的编辑器非常多,其中最有名的是 RadASM, 而现在,真正能与 RadASM 同级的就只有 MASMPlus 了,理由是只有 MASMPlus 与 RadASM 一样编写了自定义编辑类,并且比它更出色,只有自已的类,才能在各方面尽情发挥,在量身定制方面,MASMPlus 更是费尽心思,笔者长时间从事工业硬件汇编程序编写,认识到对于专业汇编程序员而言,最重要的,就是代码书写,不需要华而不实的界面,不需要莫名其妙的功能,不需要可有可无的设置,更不需要所谓的封装,总的来说, MASMPlus 是半自动,这也是 MASMPlus 没有取名为 MASMIDE 的主要原因.

  MASMPlus 工程模式极为简单,简单但并不简陋,这种小巧方便的工程管理方式,能同时打开任意多个单个文件/工程,各自编译/链接互不相关,工程单个文件属性设置,带来的,是真正的多工程,一个工程,可以包含多个主程序,多个动态库,多个静态库,组的设置,各库之间关键字搜索相互独立,共享文件全局搜索,并可实现简单方便的混合编程.你需要做的只是稍稍设置参数,按 Ctrl+1 即可一步完成所有操作.MASMPlus 还可以导出工程为模板,可以完全用于工程的发布,因为导出时,MASMPlus 会将工程中所有文件全部打包进apt中,而这个文件交给其它人时,可以直接使用它创建新工程而不会破坏apt.同时,MASMPlus 的工程模块拥有独一无二的功能:保存附加信息,它在每次关闭工程时将工程所有文件的撤消缓冲保存到工程app中,用户在下次重新打开时可以继续上一次的撤消,如果中间没有使用其它工具编辑文件, MASMPlus 可以记录整个软件的编写过程.详细请参考 "使用工程" 一节.

  代码辅助书写方面,MASMPlus 可以说是做得最好的一个编辑器,函数原型参数突出显示,标志参数自动列出,全局搜索可以搜索整个工程,全部关键字列出慢慢浏览,自动大小写支持全部关键字,结构类型变量成员列出,鼠标提示关键字信息,同时,输入与列出遵守一定的编程规则,不会误导使用者,详细请参考 "语法提示规则" 一节.

  查找方面 MASMPlus 支持正则表达式查找与替换,这是一个自主开发的正则表达式引擎,同时它的库已带入 MASMPlus,MASMPlus 使用者可直接在自己的程序中使用,MASMPlus 的正则表达式语法与通用的略有不同,详细使用及规则请参考 "正则表达式" 一节.

  同时,MASMPlus 支持插件开发,通过装植插件,可以扩展程序功能,尤其是窗口类插件,这种创新的插件模型,可以让 MASMPlus 扩展成为任何编辑器,随着之后插件的增加,使用者会发现 MASMPlus 能打开各种各样的文件,如果您是专业程序员,想为 MASMPlus 编写插件,请参考 "PDK 开发手册" 一章.同时,官方已经预留了二个插件,一个是 "资源编辑器" ,另一个是 "调试器" ,不久这两个插件均会开发并内置在 MASMPlus 下述版本中.

Visual Studio2005 建立汇编开发环境

Warriors of the Visual Studio, Assemble! (Visual Studio的勇士们,汇编吧!)

转自:http://blog.csdn.net/KingWolfOfSky/archive/2009/07/12/4342511.aspx

If you've recently purchased Assembly Language for Intel-Based Computers, 5th edition, you probably want to get the software set up so you can start working. This tutorial should make the process easier. If you're in a hurry to get started, you only need to read Item 1.

  1. Required setup for 32-bit applications
  2. Building 16-bit applications (Chapters 12-16)
  3. Project properties settings
  4. Creating a project from scratch
  5. Generating a source listing file
  6. Using the Visual Studio debugger
  7. MASM syntax highlighting
  8. Assembling, linking, and debugging with a batch file

Found an error in this document? Please email me immediately. Except where noted, all instructions in this document apply equally to Visual Studio and Visual C++ Express.


Required Setup for 32-bit Applications

First, you must install some version of Visual Studio or Visual C++ Express:
  1. If you have installed Visual Studio 2008 Professional or Team Suite, these products also contain the Microsoft Assembler 9.0.
  2. If you have installed Visual C++ 2008 Express Service Pack 1, it includes MASM 9.0.
  3. If you have installed Visual C++ 2005 Express, you must also download the Microsoft Assembler 8.0
    (see below).
Downloading Microsoft Express Editions

You can verify that the Microsoft Assembler is installed by looking for the file ml.exe in the \vc\bin folder of your Visual Studio installation directory, such as c:\Program Files\Microsoft Visual Studio 9.0\vc\bin.

Downloading and installing the Microsoft Assembler 8.0: Visit Microsoft's MASM 8.0 download site. Follow the download and installation instructions on the Microsoft page. If the link is broken, please let us know by email. Note that this MASM download only works with Visual C++ 2005 Express. MASM 8.0 is almost identical to MASM 9.0.

Next: Install the Book's Example Programs

Click this link to get the latest copy of the book's link libraries and example programs. The examples are stored in a self-extracting archive file that automatically extracts to the c:\Irvine folder. Unless you have some objection to using that location, do not alter the path. (Lab managers: you can designate c:\Irvine directory as read-only.) If you plan to change the installation location, read our instructions relating to changing project properties.

The folllowing files will be copied into the c:\Irvine directory:

Filename

Description

GraphWin.inc

Include file for writing Windows applications

Irvine16.inc

Include file used with the Irvine16 link library (16-bit applications)

Irvine16.lib

16-bit link function library used with this book

Irvine32.inc

Include file used with the Irvine32 link library (32-bit applications)

Link16.exe
16-bit linker

Irvine32.lib

32-bit link function library used with this book

Macros.inc

Include file containing macros (explained in Chapter 10)

SmallWin.inc

Small-sized include file, used by Irvine32.inc

make16.bat
Batch file for building 16-bit applications

VirtualKeys.inc

Keyboard code definitions file, used by Irvine32.inc

A subdirectory named Examples will contain all the example programs shown in the book.

Building a Sample Assembly Language Program
Preliminary Step: Set Tab Size to 5

Start Visual C++ Express, and select Options from the Tools menu. Select Text Editor, Select All Languages, and select Tabs:

Set the Tab Size and Indent Size to 5.

Opening a Project

Visual Studio and Visual C++ Express require assembly language source files to belong to a project, which is a kind of container. A project holds configuration information such as the locations of the assembler, linker, and required libraries. A project has its own folder, and it holds the names and locations of all files belonging to it. We have created a sample project folder in the c:\Irvine\Examples directory, and its name is Project_Sample.

Do the following steps, in order:

  1. Start Visual Studio or Visual C++ Express.
  2. If you're using Visual Studio, select Open Project from the File menu. Or, if you're using Visual C++ Express, select Open, and select Project/Solution.
  3. Navigate to the c:\Irvine\Examples\Project_Sample folder and open the file named Project.sln.
  4. In the Solution Explorer window, click the + symbol next to the item named Project to expand it. Double-click the file named main.asm to open it in the editing window. (Visual Studio users may see a popup dialog asking for the encoding method used in the asm file. just click the OK button to continue.)

Tip: If the Solution Explorer window is not visible, select Solution Explorer from the View menu. Also, if you do not see main.asm in the Solution Explorer window, look at the tabs along the bottom of the window. Click the Solution Explorer tab.

You should see the following program in the editor window:

TITLE MASM Template				(main.asm)

; Description:
; 
; Revision date:

INCLUDE Irvine32.inc

.data
myMessage BYTE "MASM program example",0dh,0ah,0

.code
main PROC
    call Clrscr

    mov  edx,OFFSET myMessage
    call WriteString

    exit
main ENDP

END main

Later, we'll show you how to copy this program and use it as a starting point to write your own programs.

Build the Program

Next, you will build (assemble and link) the sample program:

  • If you're using Visual C++ Express, select Build Solution from the Build menu.
  • If you're using Visual Studio, select Build Project from the Build menu.

In the output window at the bottom of the screen, you should see messages similar to the following, indicating the build progress:

1>------ Build started: Project: Project, Configuration: Debug Win32 ------
1>Assembling...
1>Assembling: .\main.asm
1>Linking...
1>Embedding manifest...
1>Build log was saved at "file://g:\masm\Project_sample\Debug\BuildLog.htm"
1>Project - 0 error(s), 0 warning(s)
========== Build: 1 succeeded, 0 failed, 0 up-to-date, 0 skipped ==========

If you do not see these messages, the project has probably not been modified since it was last built. No problem--just add a space somewhere in the document, save it, and try the Build command again.

Run the Program

Select Start without Debugging from the Debug menu. The following console window should appear, although your window will be larger than the one shown here:

The "Press any key to continue..." message is automatically generated by Visual C++ Express.

Congratulations, you have just run your first Assembly Language program.

Press any key to close the Console window.

When you assembled and linked the project, a file named Project.exe was created inside the project's \Debug folder. This is the file that executes when you run the project. You can execute Project.exe by double-clicking its name inside Windows Explorer, but it will just flash on the screen and disappear. That is because Windows Explorer does not pause the display before closing the command window.

Creating New Projects of Your Own

Before long, you will want to create your own projects. The easiest way to do this is to copy the entire c:\Irvine\Examples\Project_Sample folder to a new location. Copy it to a folder in which you have read/write permissions. (If you're working in a college computer lab, a useful location is a portable USB drive. Then you can modify the program, build, and run it again.

Step 5: Running the Sample Program in Debug Mode

In this step, you will set a breakpoint inside the sample program. Then you will use the Visual C++ debugger to step through the program's execution one statement at a time.

  1. To begin stepping through your program in Debug mode, press the F10 key.
  2. A yellow arrow will appear next to the first program statement (call Clrscr).The arrow indicates that the statement is next to be executed.
  3. Press the F10 key (called Step Over) to execute the current statement. Continue pressing F10 until the program is about to execute the exit statement.
  4. A small black window icon should appear on your Windows status bar. Open it and look at the contents of the Command window. You should see the words "MASM program example" in the window.
  5. Press F10 one more time to end the program.

Registers

If you want to display the CPU registers, do the following: Start debugging the program, then select Windows from the Debug menu. Select Registers from the drop-down list. The bottom window will display the register contents. Right click this window and check the item Flags to enable the display of conditional flags.

You can interrupt a debugging session at any time by selecting Stop Debugging from the Debug menu. You can do the same by clicking the blue square button on the toolbar. To remove a breakpoint from the program, click on the red dot so that it disappears.

Setting a BreakPoint

If you set a breakpoint in a program, you can use the debugger to execute the program a full speed (more or less) until it reaches the breakpoint. At that point, the debugger drops into single-step mode.

  1. Click the mouse along the border to the left of the call WriteString statement. A large red dot should appear in the margin.
  2. Select Start Debugging from the Debug menu. The program should run, and pause on the line with the breakpoint, showing the same Yellow arrow as before.
  3. Press F10 until the program finishes.

You can remove a breakpoint by clicking its red dot with the mouse. Take a few minutes to experiment with the Debug menu commands. Set more breakpoints and run the program again. For the time being, you can use the F11 key to step through the program in the same way the F10 key did.

Building and Running Other Programs

Suppose you want to run another example program, or possibly create your own program. You can either edit and modify main.asm, or you can remove main.asm from the project and insert some other .asm file into the project.

  • To remove a program from a project without deleting the file, right-click its name in the Solution Explorer window. In the context menu, select Exclude from Project. If you change your mind and decide to add it back to the project, right-click in the same window, select Add, select Existing item, and select the file you want to add.
  • To remove a program from a project and delete the source code file, select the file with the mouse and press the Del key. Or, you can right-click the file name and select Remove.
Adding a File to a Project

The easiest way to add an assembly language source file to an open project is to drag its filename with the mouse from a Windows Explorer window onto the name of your project in the Solution Explorer window. A reference to the file (not a copy) will be inserted in your project's directory. Try this now:

  1. Remove the main.asm file from your project.
  2. Add a reference to the file c:\Irvine\Examples\ch03\AddSub.asm to the project.
  3. Build and run the project.

Here is what you should see in the Console window, except that only your EAX register will have the same value as ours:

When you press a key, the console window will close.

Copying a source file

If you want to make a copy of an existing file, use Windows Explorer to copy the file into your project directory. Then, right-click the project name in Solution Explorer, select Add, select Existing Item, and select the filename.

Return to top or read about Project Properties settings.


Building 16-bit Applications (Chapters 12-16)

Only Chapters 12 through 16 require the building of 16-bit applications. Except for a few exceptions, which are noted in the book, your 16-bit applications will run under Windows XP and Windows Vista.

If you plan to build 16-bit applications, you need to add two new commands to the Tools menu in Visual C++ Express (or Visual Studio). To add a command, select External Tools from the Tools menu. The following dialog will appear, although many of the items in your list on the left side will be missing:

Step 1: Create the Build 16-bit ASM Command

Click the Add button and fill in the Title, Command, Arguments, and Initial directory fields as shown in the screen snapshot. If you click the buttons with arrows on the right side of the Arguments and Initial directory fields, a convenient list appears. You can select an item without having to worry about spelling:

Click the Apply button to save the command.

Step 2: Create the Run 16-bit ASM Command

Click the Add button again, and create a new command named Run 16-bit ASM:

Click the OK button to save the command and close the External Tools dialog.

Testing Your new 16-Bit Commands

To test your new 16-bit commands, open the file named 16-bit.asm from the ch03 folder in the book's example programs. Select Build 16-bit ASM from the Tools menu. The following command window should appear, showing the successful execution of the assembler and linker, followed by a listing of all files related to this program:

Press a key to close the window. Next, you will run the program. Select Run 16-bit ASM from the Tools menu. The following window will appear, although the contents of all registers except EAX will be different:

Press a key to close the window.

You have completed the setup for building and running 16-bit assembly language programs.

Return to top

Project Properties Settings

You might be interested to know more about how Visual C++ projects are set up for assembly language programs.

Assuming that our sample project is still open, select Project Properties from the Project menu. Expand the entry under Configuration Properties. Then expand the entry named Microsoft Macro Assembler. This is what you should see:

Click the entry named General under Microsoft Macro Assembler . Notice that the Include Paths option has been set to the c:\Irvine directory. This tells the assembler where to find files having a filename extension of ".inc". Here is a sample:

Next, select the Listing File entry, also in the Microsoft Macro Assembler group. Notice that the Assembled Code Listing File entry (shown below) has been assigned a macro name (starting with $) that identifies the name of the source input file, with a file extension of .lst. So, if your program were named main.asm, the listing file would be named main.lst:

Find the Linker entry under Configuration Properties. Select the Input entry, and notice that two filenames have been added to the Additional Dependencies entry. The user32.lib file is a standard MS-Windows file. The irvine32.lib file is the link library file supplied with this book. There must be at least one space separating the file names:

Next, select Linker under Configuration Properties, and then select General. The Additional Library Directories option equals c:\Irvine, so the linker can find the Irvine32.lib library file:

Select Linker under the Configuration Properties and select Debugging. Notice that the Generate Debug Info option is set to Yes:

Select System under the Linker entry. Notice that the SubSystem option has been set to Console:

We use the Console setting because it is easy for assembly language programs to write output to a text console (Command) window. This is the window you see when running cmd.exe from the Start > Run menu in Windows.

Click the OK button to close the Project Property Pages window.

Return to top


Generating a Source Listing File

Prior to 7/26/06, the sample Visual Express projects in the book's download file did not generate source listing files. Here's how to change that behavior in a single project:

Open the project. From the menu, select Project, select Project Properties. In the list box, select Microsoft Macro Assembler, then select Listing File. Set the Assembled Code Listing file option to $(InputName).lst .

Return to top


Creating a Project from Scratch

You do not have to create your own projects completely by yourself. Quite frankly, it's a lot of work. We've placed a copy of the Project_sample project in each folder of the book's example programs. You can just add your own program to one of these projects.

You can name a project anything you want, of course, but we will assume your project is named MyProject in the following examples, and that you will save it in the c:\temp directory. The commands are a little different, depending on which software you use:

Visual C++ Express 2005 & 2008

1.  Select New from the File menu, and select Project.

2.  In the New Project window, select General, and select Empty Project as the project type:

You probably will want to leave the Create directory for solution option unchecked.

3.  Click the OK button to create the empty project.

Visual Studio 2005 & 2008
  1. Select New Project from the File menu.
  2. In the New Project dialog (shown in the image below), select Other Languages, select Visual C++, select General, and select Empty Project.
  3. Give a name to the project and select the location. Do not change any other options.
  4. Click the OK button.

You probably will want to leave the Create directory for solution option unchecked.

Both Visual Studio and Visual C++ Express
  1. Use Windows Explorer or My Computer to copy the file main.asm from the \examples\Project_sample folder into the project folder you must created. (In our example, the folder is named MyProject).
  2. Back in Visual Studio or Visual C++ Express, right click your project name in the Solution Explorer window. Select Add, select Existing Item, and select main.asm. (The file may not show up until you input *.asm in the filename box.) Click the Add button to add it to your project.At this point, you may see the following Matching Custom Build Rules window. If you do, select the MASM rule and click the OK button: Then, proceed directly to Step 4.
  3. Select Custom Build Rules from the Project menu. You will see a list of Rule files, which will vary depending on which software you are using. Place a check next to Microsoft Macro Assembler:

Click the OK button to close this window.

4.  Next, you need to add some customizations. We will assume you installed the book's files in the c:\Irvine directory. Make all changes shown in the Project Properties Settings section of this document. If you installed the book's sample programs in some other location than c:\Irvine, you'll need to make appropriate changes to the project properties.

5.  Select Build Solution. If your Output window is similar to the following message, you did everything right:

1>------ Build started: Project: MyProject, Configuration: Debug Win32
1>Linking...
1>Embedding manifest...
1>Build log was saved at "file://c:\temp\MyProject\Debug\BuildLog.htm"
1>MyProject - 0 error(s), 0 warning(s)
========== Build: 1 succeeded, 0 failed, 0 up-to-date, 0 skipped

Return to top


MASM syntax highlighting

When a text editor uses syntax highlighting, language keywords, strings, and other elements appear in different colors. Visual Studio and Visual C++ Express can highlight MASM reserved words and strings, as shown in the following example:

This won't happen automatically, but you can create a syntax definition file named Usertype.dat that contains MASM keywords. Then when Visual Studio (or Visual C++ Express) starts, it reads the syntax file and highlights MASM keywords.

Here are the required steps to set up MASM syntax highlighting in Visual Studio or Visual C++ Express:

1) Download the Usertype.dat file given here to a folder in which you have read/write permissions. If you are using Windows Vista, download to My Documents, or C:\temp, or any folder that doesn't have security restrictions.

2) Copy Usertype.dat to the C:\Program Files\Microsoft Visual Studio 9.0\Common7\IDE folder. If you are using Windows Vista, it will display a verification window before copying the file.

3) Open Visual Studio or Visual C++ Express, select Options from the Tools menu, select Text Editor, and select File Extension. On the right side of the dialog (shown below), enter asm as the extension, select Microsoft Visual C++ from the Editor list, and click the Add button. Click the OK button to save your changes.

Close Visual Studio and restart it. Open your project and display an ASM file. You should see syntax highlighting in the editor.


Assembling, Linking, and Debugging with a Batch File

Many people like to use a Windows batch file to assemble and link programs. A batch file is a text file containing a sequence of commands that execute as if they had been typed at the command prompt. In fact, they are powerful enough to contain variables, loops, IF statements, and so on.

The easiest way to run a batch file is to first open a Command window and then type the name of the batch file (along with arguments) at the command prompt. To open a Command window, you must execute a program named cmd.exe. We will make that easy for you.

Step 1:Download a ZIP file containing the following items:

  • A shortcut to cmd.exe, which opens a Command window in the current directory
  • asm32.bat, a batch file for assembling and linking programs
  • main.asm, a sample assembly language program

There are two different versions of the ZIP file:

  • If you're using Visual Studio 2008 or Visual C++ 2008 Express (SP1), click here.
  • If you're using Visual Studio 2005 or Visual C++ 2005 Express, click here.

Step 2: Extract the ZIP file into the c:\Irvine\Examples directory on your computer.

Step 3: Do the following:

  • Copy asm32.bat to any directory on your system path. By doing this, you make it possible for MS-Windows to recognize asm32 as a valid command when typed at the MS-Windows command prompt.(If you want to find out which directories are on the current system path, type path and press Enter at the system command prompt.)
  • Double-click the shortcut to cmd.exe. A Command window should appear.
  • At the command prompt in this window, type asm32 and press Enter. This will execute the asm32 batch file and display help information.
This file assembles, links, and debugs a single assembly language
source file. Before using it, install Visual Studio 2008 in the following
directory: 

    C:\Program Files\Microsoft Visual Studio 9.0


Next, install the Irvine 5th edition link libraires and include
files in the following directory: C:\Irvine


Finally, copy this batch file to a location on your system path.
We recommend the following directory: 


C:\Program Files\Microsoft Visual Studio 9.0\VC\bin


Command-line syntax:

  asm32 [/H | /h | -H | -h] -- display this help information

  asm32 filelist -- assemble and link all files
  asm32 /D filelist -- assemble, link, and debug
  asm32 /C filelist -- assemble only

<filelist> is a list of up to 5 filenames (without extensions),
separated by spaces. The filenames are assumed to refer to files
having .asm extensions. Command-line switches are case-sensitive.

Type the following command to assemble and link a source file named main.asm:

    asm32 main

You should see the following messages:

 Assembling: main.asm
The file main.obj was produced.
..................................
Linking main.obj to the Irvine32, Kernel32, and User32 libraries.
The file main.exe was produced.
..................................

In fact, several files were produced.

  • main.obj - the object file
  • main.ilk - incremental link status file
  • main.pdb - debug symbol file

If there were errors in the program, you would see error messages generated by the assembler. Here is an example:

 Assembling: main.asm
main.asm(9) : error A2008: syntax error : myMessage
main.asm(15) : error A2006: undefined symbol : myMessage

You would then open the main.asm file with a text editor (such as Notepad), fix the errors, and run the asm32 batch file again.

Although we used a file named main.asm in this example, the asm32.bat batch file will work for any assembly language file, regardless of the name. The only requirement is that your assembly language source file have a .asm filename extension.

Assembling Programs in Other Directories

No doubt, you will want to assemble programs in various different disk folders, not just the batch_sample folder used in the foregoing example. All you need to do is copy the cmd.exe shortcut we gave you to your working directory, where your assembly language source files are located. When you double-click to run the shortcut, it will open a Command window in the current folder.

Assembling, Linking, and Debugging

In addition to assembling and linking, you can use the asm32.bat file to launch your program in the Visual Studio debugger. Try the following command:

    asm32 /D main

If the program assembles and links with no errors, your program should load in Visual Studio. The first time you do this with a new program, the source code will not appear. All you have to do is press the F10 key to begin debugging, and your program should appear with a yellow band across the first executable line:

(Depending on how Visual Studio is configured, you might have to press F8 to do the same thing.)

From here, you can step through the program. When you get to the call to WriteString, you can even trace into its code by pressing the F11 key (trace to). When you finish, close Visual Studio.

From this time on, when you load the same program in the Visual Studio debugger, your source code will appear right away.

Assembling without Linking

Occasionally, you may want to assemble programs but not link them. This happens, for example, when you are creating a multimodule project and you want to assemble each asm file into an obj file separately before linking them into the final exe program. Or, you might be assembling a module to be inserted into a link library (like Irvine32.lib).

To assemble a source file only, inser the /C option before the name of the file being assembled:

    asm32 /C main

You should see the following output:

 Assembling: main.asm
The file main.obj was produced.
..................................

If you are interested in learning more about how batch file commands work, here are some reference links we found:

Links go out of date quickly, but you can google for Windows batch files and get plenty of hits.

转自:http://blog.csdn.net/KingWolfOfSky/archive/2009/07/12/4342511.aspx

CintaNote用来做每天的工作笔记和简单的学习笔记 很好用

1、可以设置快捷键启动或缩小他,或新建笔记

2、软件界面简洁,清爽,基于文本的笔记。可以分类排序。

3、可以设置 笔记的 tag,然后按照tag分类查找,内置搜索很实用

image

设置热键:

image

Windows主机端与自定义USB HID设备通信详解

转自:http://blogold.chinaunix.net/u3/98810/showart_1963291.html

特此感谢作者:jmyu2006.cublog.cn

------------------------------------ 正文 --------------------------------------------

说明:

- 以下结论都是基于Windows XP系统所得出的,不保证在其他系统的适用性。

- 在此讨论的是HID自定义设备,对于标准设备,譬如USB鼠标和键盘,由于操作系统对其独占,许多操作未必能正确执行。

1 所使用的典型Windows API

CreateFile

ReadFile

WriteFile

以下函数是DDK的内容:

HidD_SetFeature

HidD_GetFeature

HidD_SetOutputReport

HidD_GetInputReport

其中,CreateFile用于打开设备;ReadFile、HidD_GetFeature、HidD_GetInputReport用于设备到主机方向的数据通信;WriteFile、HidD_SetFeature、HidD_SetOutputReport用于主机到设备方向的数据通信。鉴于实际应用,后文主要讨论CreateFile,WriteFile,ReadFile,HidD_SetFeature四个函数,明白了这四个函数,其它的可以类推之。

2. 几个常见错误

当使用以上API时,如果操作失败,调用GetLastError()会得到以下常见错误:

6: 句柄无效

23: 数据错误(循环冗余码检查)

87: 参数错误

1784: 用户提供的buffer无效

后文将会详细说明这些错误情况。

3. 主机端设备枚举程序流程

4. 函数使用说明

CreateFile(devDetail->DevicePath, //设备路径

GENERIC_READ | GENERIC_WRITE, //访问方式

FILE_SHARE_READ | FILE_SHARE_WRITE, //共享模式

NULL,

OPEN_EXISTING, //文件不存在时,返回失败

FILE_FLAG_OVERLAPPED, //以重叠(异步)模式打开

NULL);

在这里,CreateFile用于打开HID设备,其中设备路径通过函数SetupDiGetInterfaceDeviceDetail取得。CreateFile有以下几点需要注意:

- 访问方式: 如果是系统独占设备,例如鼠标、键盘等等,应将此参数设置为0,否则后续函数操作将失败(譬如HidD_GetAttributes);也就是说,不能对独占设备进行除了查询以外的任何操作,所以能够使用的函数也是很有限的,下文的一些函数并不一定适合这些设备。在此顺便列出MSDN上关于此参数的说明:

If this parameter is zero, the application can query file and device attributes without accessing the device. This is useful if an application wants to determine the size of a floppy disk drive and the formats it supports without requiring a floppy in the drive. It can also be used to test for the file's or directory's existence without opening it for read or write access。

- 重叠(异步)模式:此参数并不会在此处表现出明显的意义,它主要是对后续的WriteFile,ReadFile有影响。如果这里设置为重叠(异步)模式,那么在使用WriteFile,ReadFile时也应该使用重叠(异步)模式,反之亦然。这首先要求WriteFile,ReadFile的最后一个参数不能为空(NULL)。否则,便会返回87(参数错误)错误号。当然,87号错误并不代表就是此参数不正确,更多的信息将在具体讲述这两个函数时指出。此参数为0时,代表同步模式,即WriteFile,ReadFile操作会在数据处理完成之后才返回,否则阻塞在函数内部。

ReadFile(hDev, //设备句柄,即CreateFile的返回值

recvBuffer, //用于接收数据的buffer

IN_REPORT_LEN, //要读取数据的长度

&recvBytes, //实际收到的数据的字节数

&ol); //异步模式

在这里,ReadFile用于读取HID设备通过中断IN传输发来的输入报告。有以下几点要注意:

1、ReadFile的调用不会引起设备的任何反应,即HID设备与主机之间的中断IN传输不与ReadFile打交道。实际上主机会在最大间隔时间(由设备的端点描述符来指定)内轮询设备,发出中断IN传输的请求。“读取”即意味着从某个buffer里面取回数据,实际上这个buffer就是HID设备驱动中的buffer。这个buffer的大小可以通过HidD_SetNumInputBuffers来改变。在XP上缺省值是32(个报告)。

2、读取的数据对象是输入报告,也即通过中断输入管道传入的数据。所以,如果设备不支持中断IN传输,那么是无法使用此函数来得到预期结果的。实际上这种情况不可能在HID中出现,因为协议指明了至少要有一个中断IN端点。

3、IN_REPORT_LEN代表要读取的数据的长度(实际的数据正文+一个byte的报告ID),这里是一个常数,主要是因为设备固件的信息我是完全知道的,当然知道要读取多少数据(也就是报告的长度);不过也可以通过另外的函数(HidD_GetPreparsedData)来事先取得报告的长度,这里不做详细讨论。因为很难想象在不了解固件信息的情况下来做自定义设备的HID通信,在实际应用中一般来说就是固件与PC程序匹配着来开发。此参数如果设置过大,不会有实质性的错误,在recvBytes参数中会输出实际读到的长度;如果设置过小,即小于报告的长度,会返回1784号错误(用户提供的buffer无效)。

4、关于异步模式。前面已经提过,此参数的设置必须与CreateFile时的设置相对应,否则会返回87号错误(参数错误)。如果不需要异步模式,此参数需置为NULL。在这种情况下,ReadFile会一直等待直到数据读取成功,所以会阻塞住程序的当前过程。

WriteFile(hDev, //设备句柄,即CreateFile的返回值

reportBuf, //存有待发送数据的buffer

OUT_REPORT_LEN, //待发送数据的长度

&sendBytes, //实际收到的数据的字节数

&ol); //异步模式

在这里,WriteFile用于传输一个输出报告给HID设备。有以下几点要注意:

1、 与ReadFile不同,WriteFile函数被调用后,虽然也是经过驱动程序,但是最终会反映到设备中。也就是说,调用WriteFile后,设备会接收到输出报告的请求。如果设备使用了中断OUT传输,则WriteFile会通过中断OUT管道来进行传输;否则会使用SetReport请求通过控制管道来传输。

2、 OUT_REPORT_LEN代表要写入的数据长度(实际的数据正文+一个byte的报告ID)。如果大于实际报告的长度,则使用实际报告长度;如果小于实际报告长度,会返回1784号错误(用户提供的buffer无效)。

3、 reportBuf[0]必须存有待发送报告的ID,并且此报告ID指示的必须是输出报告,否则会返回87号错误(参数错误)。这种情况可能容易被程序员忽略,结果不知错误号所反映的是什么,网上也经常有类似疑问的帖子。顺便指出,输入报告、输入报告、特征报告这些报告类型,是反映在HID设备的报告描述符中。后文将做举例讨论。

4、 关于异步模式。前面已经提过,此参数的设置必须与CreateFile时的设置相对应,否则会返回87号错误(参数错误)。如果不需要异步模式,此参数需置为NULL。在这种情况下,WriteFile会一直等待直到数据读取成功,所以会阻塞住程序的当前过程。

HidD_SetFeature(hDev, //设备句柄,即CreateFile的返回值

reportBuf, //存有待发送数据的buffer

FEATURE_REPORT_LEN); //buffer的长度

HidD_SetOutputReport(hDev, //设备句柄,即CreateFile的返回值

reportBuf, //存有待发送数据的buffer

OUT_REPORT_LEN); //buffer的长度

HidD_SetFeature发送一个特征报告给设备,HidD_ SetOutputReport发送一个输出报告给设备。注意以下几点:

1、 跟WriteFile类似,必须在reportBuf[0]中指明要发送的报告的ID,并且和各自适合的类型相对应。也就是说,HidD_SetFeature只能发送特征报告,因此报告ID必须是特征报告的ID;HidD_SetOutputReport只能发送输出报告,因此报告ID只能是输出报告的ID。

2、 这两个函数最常返回的错误代码是23(数据错误)。包括但不仅限于以下情况:

- 报告ID与固件描述的不符。

- 传入的buffer长度少于固件描述的报告的长度。

据有关资料反映(非官方文档),只要是驱动程序对请求无反应,都会产生此错误。

5. 常见错误汇总

- HID ReadFile

- Error Code 6 (handle is invalid)

传入的句柄无效

- Error Code 87 (参数错误)

很可能是createfile时声明了异步方式,但是读取时按同步读取。

- Error Code 1784 (用户提供的buffer无效):

传参时传入的“读取buffer长度”与实际的报告长度不符。

- HID WriteFile

- Error Code 6 (handle is invalid)

传入的句柄无效

- Error Code 87(参数错误)

- CreateFile时声明的同步/异步方式与实际调用WriteFile时传入的不同。

- 报告ID与固件中定义的不一致(buffer的首字节是报告ID)

- Error Code 1784 (用户提供的buffer无效)

传参时传入的“写入buffer长度”与实际的报告长度不符。

- HidD_SetFeature

- HidD_SetOutputReport

- Error Code 1 (incorrect function)

不支持此函数,很可能是设备的报告描述符中未定义这样的报告类型(输入、输出、特征)

- Error Code 6 (handle is invalid)

传入的句柄无效

- Error Code 23(数据错误(循环冗余码检查))

- 报告ID与固件中定义的不相符(buffer的首字节是报告ID)

- 传入的buffer长度少于固件定义的报告长度(报告正文+1byte, 1byte为报告ID)

- 据相关资料反映(非官方文档),只要是驱动程序不接受此请求(对请求无反应),都会产生此错误

6. 报告描述符及数据通信程序示例

报告描述符(由于是汇编代码,所以不必留意其语法,仅需注意表中的每个数据都占1个字节):

_ReportDescriptor: //报告描述符

.dw 0x06, 0x00, 0xff //用法页

.dw 0x09, 0x01 //用法(供应商用法1)

.dw 0xa1, 0x01 //集合开始

.dw 0x85, 0x01 //报告ID(1)

.dw 0x09, 0x01 //用法(供应商用法1)

.dw 0x15, 0x00 //逻辑最小值(0)

.dw 0x26, 0xff, 0x0 //逻辑最大值(255)

.dw 0x75, 0x08 //报告大小(8)

.dw 0x95, 0x07  //报告计数(7)

.dw 0x81, 0x06 //输入(数据,变量,相对值)

.dw 0x09, 0x01 //用法(供应商用法1)

.dw 0x85, 0x03 //报告ID(3

.dw 0xb1, 0x06 //特征(数据,变量,相对值)

.dw 0x09, 0x01 //用法(供应商用法1)

.dw 0x85, 0x02 //报告ID(2

.dw 0xb1, 0x06 //特征(数据,变量,相对值)

.dw 0x09, 0x01 //用法(供应商用法1)

.dw 0x85, 0x04 //报告ID(4

.dw 0x91, 0x06 //输出(数据,变量,相对值)

.dw 0xc0 //结合结束

_ReportDescriptor_End:

这个报告描述符,定义了4个不同的报告:输入报告1,特征报告2,特征报告3,输出报告4(数字代表其报告ID)。为了简化,每个报告都是7个字节(加上报告ID就是8个字节)。下面用一个简单的示例来描述PC端与USB HID设备进行通信的一般方法。

#define USB_VID 0xFC0
#define USB_PID 0x420
HANDLE OpenMyHIDDevice(int overlapped);

void HIDSampleFunc()
{
    HANDLE        hDev;
    BYTE        recvDataBuf[8];
    BYTE        reportBuf[8];
    DWORD        bytes;
     
    hDev = OpenMyHIDDevice(0); //打开设备,不使用重叠(异步)方式;

    
    if (hDev == INVALID_HANDLE_VALUE)
        return;
    
    reportBuf[0] = 4; //输出报告的报告ID是4

    memset(reportBuf, 0, 8);
    reportBuf[1] = 1;
    if (!WriteFile(hDev, reportBuf, 8, &bytes, NULL)) //写入数据到设备

        return;
    
    ReadFile(hDev, recvDatatBuf, 8, &bytes, NULL); //读取设备发给主机的数据

}

HANDLE OpenMyHIDDevice(int overlapped)
{
    HANDLE     hidHandle;
    GUID     hidGuid;
    
    HidD_GetHidGuid(&hidGuid);
    
    HDEVINFO hDevInfo = SetupDiGetClassDevs(
                    &hidGuid,
                    NULL,
                    NULL,
                    (DIGCF_PRESENT | DIGCF_DEVICEINTERFACE)); 
    if (hDevInfo == INVALID_HANDLE_VALUE)
    {
     return INVALID_HANDLE_VALUE;
    }
    
    SP_DEVICE_INTERFACE_DATA devInfoData;
    devInfoData.cbSize = sizeof (SP_DEVICE_INTERFACE_DATA);
    int deviceNo = 0;
    
    SetLastError(NO_ERROR);
    
    while (GetLastError() != ERROR_NO_MORE_ITEMS)
    {
        if (SetupDiEnumInterfaceDevice (hDevInfo,
                    0, 
                    &hidGuid,
                    deviceNo,
                    &devInfoData))
        {
            ULONG requiredLength = 0;
            SetupDiGetInterfaceDeviceDetail(hDevInfo,
                                            &devInfoData,
                                            NULL, 
                                            0,
                                            &requiredLength,
                                            NULL);

            PSP_INTERFACE_DEVICE_DETAIL_DATA devDetail = 
                (SP_INTERFACE_DEVICE_DETAIL_DATA*) malloc (requiredLength);
            devDetail->cbSize = sizeof(SP_INTERFACE_DEVICE_DETAIL_DATA);

            if(!SetupDiGetInterfaceDeviceDetail(hDevInfo,
                        &devInfoData,
                        devDetail,
                        requiredLength,
                        NULL,
                        NULL)) 
            {
                free(devDetail);
                           SetupDiDestroyDeviceInfoList(hDevInfo);
                return INVALID_HANDLE_VALUE;
            }

                  if (overlapped)
                  {
                         hidHandle = CreateFile(devDetail->DevicePath,
                        GENERIC_READ | GENERIC_WRITE,
                        FILE_SHARE_READ | FILE_SHARE_WRITE,
                        NULL, 
                        OPEN_EXISTING, 
                        FILE_FLAG_OVERLAPPED,
                        NULL);
                  }
                  else
                  {
                         hidHandle = CreateFile(devDetail->DevicePath,
                        GENERIC_READ | GENERIC_WRITE,
                        FILE_SHARE_READ | FILE_SHARE_WRITE,
                        NULL, 
                        OPEN_EXISTING, 
                        0,
                        NULL);
                  }

            free(devDetail);

            if (hidHandle==INVALID_HANDLE_VALUE)
            {
                SetupDiDestroyDeviceInfoList(hDevInfo);
                free(devDetail);
                return INVALID_HANDLE_VALUE;
            }

            _HIDD_ATTRIBUTES hidAttributes;
            if(!HidD_GetAttributes(hidHandle, &hidAttributes))
            {
                CloseHandle(hidHandle);
                           SetupDiDestroyDeviceInfoList(hDevInfo);
                return INVALID_HANDLE_VALUE;
            }

            if (USB_VID == hidAttributes.VendorID 
                && USB_PID == hidAttributes.ProductID)
            {
                break;
            }
            else
            {
                CloseHandle(hidHandle);
                ++deviceNo;
            }
        }
    }

    SetupDiDestroyDeviceInfoList(hDevInfo);
    return hidHandle;
}

一位ALS患者在生命走到尽头前用脚贡献了最后一个代码补丁zt

转自:http://software.intel.com/zh-cn/blogs/2011/05/24/alszt/?cid=sw:prccsdn1701

作者: 阿汤 (39 篇文章) 日期: 五月 24, 2011 在 4:50 下午

一个把自己的生命和代码和为一体的人,看了报道后自己又找了一些相关消息跟大家分享一下。:

ALS是肌肉萎縮性側索硬化症的略稱。又稱漸凍人症。

文中所提到的bug,2002年就报出来了,9年没有被解决掉,最后是这样的一个人解决的。这个bug是:https://bugzilla.gnome.org/show_bug.cgi?id=78514

再贴一张这个程序员的最后照片。一位ALS患者在生命走到尽头前用脚贡献了最后一个代码补丁

Adrian Hands就是一位ALS病人,他在已经失去了运动能力、双手残废无法使用键盘的情况下,用脚在一个莫尔斯码键盘模拟器上编写代码,为GNOME提交了生 命中最后一个patch。

以下是他的儿子Ian Hands在GNOME的邮件列表里的一段话
I would like to extend my thanks to the gnome team/community for a great last moment with my dad. Adrian H

Visual DSP++调试程序时SDRAM初始化的处理方式

在Visual DSP++的安装目录下“..\Analog Devices\VisualDSP 5.0\System\ArchDef”包含了针对各种类型处理器的的调试加载信息设置文件(.xml),文件主要完成在利用仿真器加载调试代码前,初始化处理器相关寄存器和准备好程序运行的环境等工作,为调试程序的运行准备好必要的环境。

比如,以一个“ADSP-BF561-proc.xml”文件为例,文件的最后几行就是初始化DSP中SDRAM控制器的寄存器的代码(均以“EBIU_”字样开头,其含义详见处理器参考手册),便于在调试程序运行前,按照SDRAM特性初始化SDRAM控制器的控制方式。

那么,第一个问题是:Visual DSP++默认的文件中的SDRAM控制器的设置是按照哪种类型的SDRAM进行的设置呢?

答案是:按照ADI自己的参考板上的SDARM性能进行设置的,所以如果我们要设计自己的电路板采用不同的SDRAM的话,就必须修改对应处理器文件中的寄存器设置内容。

第二个问题是:调试的时候我们使用这个文件初始化SDRAM或其他初始化工作,那么,当程序下载到板载Flash的时候,谁来初始化SDRAM和其他资源的呢?

答案是:ADI为每一种处理器都提供了一个“ADSP-xxx-ROM-Vxx.dxe”的文件(在对应的处理器类型目录下的LDR子目录中),在你生成ldr文件准备烧写的时候,编译器就会提示你要加载这个文件的。他干的就是类似前面提到的“ADSP-BF561-proc.xml”文件的活,只不过“ADSP-BF561-proc.xml”文件还要多干一样活是将易失性存储器的空间初始化,以模拟处理器刚上电的状态。要不然调试时不掉电,反复加载程序后可能程序会乱掉,以至于无法正确模拟处理器刚上电后的运行状态了。 既然这个也是ADI随着Visual DSP++预装好的(自然也是针对ADI的参考板设置的),那么也必然会遇到前面的问题,如果使用我自己的SDRAM怎么办的问题,还好ADI提供了源代码和工程(也在LDR子目录下,自己找找看吧~),代码仅仅是很简单的一个汇编文件,里面就设置了几个寄存器,改一下重编译即可。

总结:其实ADI的Visual DSP++的安装目录下有很多“资源”,只要用心从这些资源里是可以学到很多东西的!

深入浅出硬盘分区表

转自:http://www.vckbase.com/document/viewdoc/?id=443
作者:武汉市中国地质大学 印涛,秦剑

    人们在使用电脑时,有时由于异常操作,有时由于病毒侵袭,会导致某个分区消失或硬盘无法启动。究其原因,就是硬盘分区表受损。硬盘分区表可以说是支持硬盘正常工作的骨架.操作系统正是通过它把硬盘划分为若干个分区,然后再在每个分区里面创建文件系统,写入数据文件.本文主要讲述的是分区表的位置,结构以及各个分区表是如何链接起来的.当掌握了这些知识后,即使分区表受到破坏,一样也可以根据残存的数据手工修复分区表,从而修复分区。
一.分区表的位置及识别标志
    分区表一般位于硬盘某柱面的0磁头 1扇区.而第1个分区表(也即主分区表)总是位于 
(0柱面,1磁头,1扇区),剩余的分区表位置可以由主分区表依次推导出来.分区表有64个字节,占据其所在扇区的[441-509]字节.要判定是不是分区表,就看其后紧邻的两个字节(也即[510-511])是不是 "55AA",若是,则为分区表.
二.分区表的结构
分区表由4项组成,每项16个字节.共4×16 = 64个字节.每项描述一个分区的基本信息.每个字节的含义如下:
分区表项含义

字节 含义
0 Activeflag.活动标志.若为0x80H,则表示该分区为活动分区.若为0x00H,则表示该分区为非活动分区
1,2,3 该分区的起始磁头号,扇区号,柱面号磁头号 -- 1字节, 扇区号 -- 2字节低6位,柱面号 -- 2字节高2位 + 3字节
4 分区文件系统标志:
分区未用: 0x00H.
扩展分区: 0x05H, 0x0FH.
FAT16分区: 0x06H.
FAT32分区: 0x0BH, 0x1BH, 0x0CH, 0x1CH.
NTFS分区: 0x07H.
5,6,7 该分区的结束磁头号,扇区号,柱面号,含义同上
8,9,10,11 逻辑起始扇区号。表示分区起点之前已用了的扇区数
12,13,14,15 该分区所占用的扇区数.

分区表项有几个字节比较重要,下面分别阐述之:

1、(1,2,3)字节
    磁头号由(1)字节8位表示,其范围为(0 -- 28 - 1),也即(0 磁头-- 254磁头)。   
扇区号由(2)字节低6位表示,其范围为(0 -- 26 - 1),由于扇区号从1开始,所以其范围是(1扇区-- 63扇区)。   
柱面号由(2)字节高2位 + (3)字节,共10位表示,其范围为(0 --2 10 - 1),也即(0 柱面-- 1023柱面)。
当柱面号超过1023时,这10位依然表示成1023,需要注意。   
(5,6,7)字节含义同上。
2、(8, 9, 10, 11)字节  
    如果是主分区表,则这4 个字节表示该分区起始逻辑扇区号与逻辑0扇区(0柱面,0磁头,1扇区)之差。如果非主分区表,
    则这4 个字节要么表示该分区起始逻辑扇区号与扩展分区起始逻辑扇区号之差,要么为63。详细情况在后面有所阐述。  
  
注意:
1、扇区上的字节是按左边低位,右边高位的顺序排列的。所以在取值时,需要把字节再反一下,让高位字节在左边,低位字节在右边,
这一点在读取逻辑起始扇区号和分区大小时需要注意。举个例子:第一项的逻辑起始扇区为(3F 00 00 00),转换为十进制前要先反一下字
节顺序,为(00 00 00 3F)然后在转换为十进制,即63 .同理分区大小为(3F 04 7D 00),先反为(00 7D 04 3F)再转换为十进制,
即8193087。
  
2、逻辑扇区号与(柱面,磁头,扇区)的相互转换:
令L = 逻辑扇区号,C = 柱面号,H = 磁头号,S = 扇区号。
每道扇区数 =  63
每柱面磁头数 = 255
每柱面扇区数 = 每道扇区数* 每柱面磁头数
                 = 63 × 255
       			 = 16065
柱面号下标从0开始。磁头号[0 -- 254],扇区号[1 -- 63]。
逻辑扇区号下标也从0开始。
(柱面,磁头,扇区)转换成逻辑扇区号的公式为:
L = C×16065 + H ×63 + S - 1 ;
比如(1柱面,1磁头,1扇区),其逻辑扇区号为:
L = 1×16065 + 1×63 + 1 - 1
= 16128
逻辑扇区号转换成(柱面,磁头,扇区) 公式为:
C = L / 16065
H = (L % 16065) / 63
S = (L % 16065) % 63 + 1
比如逻辑扇区号 16127:
C = 16127 / 16065 = 1
H = (16127 % 16065) / 63 = 0
S = (16127 % 16065) % 63 + 1 = 63
即(1柱面,0磁头,63扇区)
  
3、分区表上有四项,每一项表示一个分区,所以一个分区表最多只能表示4个分区。主分 
区表上的4项用来表示主分区和扩展分区的信息。因为扩展分区最多只能有一个,所以硬盘 
最多可以有四个主分区或者三个主分区,一个扩展分区。余下的分区表是表示逻辑分区的。 
这里有必要阐述一点:逻辑区都是位于扩展分区里面的,并且逻辑分区的个数没有限制。
 
4、分区表所在扇区通常在(0磁头,1扇区),而该分区的开始扇区通常位于(1磁头,1扇区),中间隔了63 个隐藏扇区。
  
三.分区表链的查找
  分区表链实际上相当于一个单向链表结构。第一个分区表,也即主分区表,可以有一项 描述扩展分区。而这一项就相当于指针,指向扩展分区。然后我们根据该指针来到扩展分 区起始柱面的0头1扇区,找到第二个分区表。对于该分区表,通常情况下:第一项描述了 扩展分区中第一个分区的信息,第二项描述下一个分区,而这第二项就相当于指向第二个分 区的指针,第三项,第四项一般均为0。我们可以根据该指针来到扩展分区中第二个分区起 始柱面的0头1扇区,找到第三个分区表。以此类推,只到最后一个分区表。而最后一个分 区表只有第一项有信息,余下三项均为0.相当于其指针为空.所以只要找到了一个分区表就可 以推导找出其后面所有分区表。不过该分区表前面的分区表就不好推导出来了。但令人高兴 的是这个链表的头节点,也即主分区表的位置是固定的位于(0柱面, 0磁头, 1扇区)处, 我们可以很轻易的找到它,然后把剩下的所有分区表一一找到。
以笔者的硬盘为例:一个主分区(C盘), 一个扩展分区.扩展分区中有两个逻辑分区(D盘,E盘)其分区表链示意图如下:

图一 分区表链示意图
(一).读取(0柱面,0磁头,1扇区)处C盘的主分区表:
 [80 01 01 00 0B FE 7F FD 3F 00 00 00 3F 04 7D 00 ]	                                  	  
 [00 00 41 FE 0F FE FF FF 7E 04 7D 00 1F 2C B4 00 ]
 
[00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ]

    [00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ]
第一项:
(80)(01 01 00)(0B)(FE 7F FD )(3F 00 00 00 )(3F 04 7D 00)
描述的是C盘的情况。
1.(80):表示C盘为活动分区。即系统会从C盘启动。
2.(01 01 00):表示C盘的起始扇区为(0柱面,0磁头,1扇区)。
3.(0B):表示C盘的文件系统为FAT32。
4.(FE 7F FD):
(FE) 16  =  (254) 10  (7F) 16  =  (0111 1111) 2  (FD) 16  =  (1111 1101) 2
磁头号:(254) 10;
扇区号:(11 1111) 2  =  (63) 10.
柱面号:(01 1111 1101) 2  =  (509) 10
故C盘结束扇区为(509柱面,254磁头,63扇区)。
5.(3F 00 00 00):
反向,(00 00 00 3F) 16  =  (63) 10,为C盘起始逻辑扇区号与逻辑0扇区号之差。表示C盘前面已有63个扇区,这63个扇区为系统隐藏扇区。
6. (3F 04 7D 00):
反向,(00 7D 04 3F) 16  =  (8193087) 10。表明C盘有8193087个扇区。即(0柱面,1磁头,1扇区)至(509柱面,254磁头,63扇区)
共有8193087个扇区。
第二项:
(00)(00 41 FE)(0F)(FE FF FF)(7E 04 7D 00)(1F 2C B4 00)
描述的是扩展分区的情况。
1. (00): 表示该分区不是活动分区。
2. (00 41 FE):
(00) 16  =  (0) 10  (41) 16  =  (0100 0001) 2  (FE) 16  =  (1111 1110) 2
磁头号:(0) 10;
扇区号:(00 0001) 2  =  (1) 10.
柱面号:(01 1111 1110) 2  =  (510) 10
所以扩展分区的起始扇区为(510柱面,0磁头,1扇区)。
3. (0F): 表示该分区为扩展分区。
4. (FE FF FF):
(FE) 16  =  (254) 10  (FF) 16  =  (1111 1111) 2  (FF) 16  =  (1111 1111) 2;
磁头号:(254) 10;
扇区号:(11 1111) 2  =  (63) 10.
柱面号:(11 1111 1111) 2  =  (1023) 10
但这是不准确的,因为当柱面号的真实值超过1023时,表示柱面号的10位也依然是1023。

5. (7E 04 7D 00):
反向,(00 7D 04 7E) 16  =  (8193150) 10. 表示扩展分区的起始扇区号为8193150,即(510 柱面,0磁头,1扇区)。这是真实准确的,
我一般都用这一项来定位分区起点。
6. (1F 2C B4 00):
反向, (00 B4 2C 1F) 16  =  (11807775) 10. 表示扩展分区共有11807775个扇区。通过上面得到的起点和分区的大小,
可以推导出扩展分区的结束位置:8193150 + 11807775 = 20000925号扇区,即(1244 柱面,254磁头,63扇区)。
二.查找D盘分区表 根据上面的信息,第二个分区表,也即D盘分区表在(510柱面,0磁头,1扇区)处。读取该扇区,得到分区表如下:
[00 01 41 FE 0B FE FF 7B 3F 00 00 00 BF A3 5D 00 ]
                                    
 [00 00 C1 7C 05 FE FF FF FE A3 5D 00 21 88 56 00 ]

 [00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ]

 [00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ]
第一项:
(00)(01 41 FE)(0B)(FE FF 7B)(3F 00 00 00 )(BF A3 5D 00)
  描述的是D盘的情况。
1.(00):表示D盘不是活动分区。
2.(01 41 FE):
  (01) 16  =  (1) 10  (41) 16  =  (0100 0001) 2  (FE) 16  =  (1111 1110) 2.
磁头号:(1) 10;
扇区号:(00 0001) 2  =  (1) 10.
柱面号:(01 1111 1110) 2  =  (510) 10;
故D盘开始扇区为(510柱面,1磁头,1扇区)。
3.(0B):表示D盘的文件系统为FAT32。
4.(FE FF 7B):
(FE) 16  =  (254) 10 。 (FF) 16  =  (1111 1111) 2  (7B) 16  =  (0111 1011) 2.
磁头号:(254) 10;
扇区号:(11 1111) 2  =  (63) 10.
柱面号:(11 0111 1011) 2  =  (891) 10
故D盘结束扇区为(891柱面,254磁头,63扇区)。
5.(3F 00 00 00):
反向,(00 00 00 3F)16  =  (63)10,为D盘起始逻辑扇区号(510柱面,1磁头,1扇区)与扩展分区起始逻辑扇区号
(510柱面,0磁头,1扇区)之差。表示D盘前面已有63个扇区,这63个扇区为系统隐藏扇区。
6. (BF A3 5D 00):
反向,(00 5D A3 BF) 16  =  (6136767) 10。表明D盘有6136767个扇区。
通过上面得到的起点和分区的大小,可以推导出D盘的结束位置:8193150 + 63 + 6136767 = 14329980号扇区。
即(891柱面,254磁头,63扇区)。与上面的正好吻合。
第二项:
(00)(00 C1 7C)(05)(FE FF FF)(FE A3 5D 00)(21 88 56 00)
描述的是E盘的情况。
1. (00): 表示E盘不是活动分区。
2. (00 C1 7C):
(00) 16  =  (0) 10  (C1) 16  =  (1100 0001) 2  (7C) 16  =  (0111 1100) 2
磁头号:(0) 10
扇区号:(00 0001) 2  =  (1) 10
柱面号:(11 0111 1100) 2  =  (892) 10
所以E盘的起始扇区为(892柱面,0磁头,1扇区)。
3. (05): 表示E盘的在扩展分区里面。
4.(FE FF FF):
(FE) 16  =  (254) 10  (FF) 16  =  (1111 1111) 2  (FF) 16  =  (1111 1111) 2
磁头号:(254) 10
扇区号:(11 1111) 2  =  (63) 10
柱面号:(11 1111 1111) 2  =  (1023) 10
但这是不准确的,原因同上。

5.(FE A3 5D 00):
 反向,(00 5D A3 FE) 16  =  (6136830) 10. 这一项非常重要,它定位了E盘分区表所在扇区。其值为E盘分区表所在扇区号
 与扩展分区起始扇区号之差。所以,E盘分区表所在扇区号为:
8193150 + 6136830 = 14329980。即(892柱面,0磁头,1扇区)。

6.(21 88 56 00):
反向,(00 56 88 21) 16  =  (5670945) 10.表示E盘共有11807775个扇区。通过上面得到的起点和分区的大小,可以推导出E
盘的结束位置:14329980 + 5670945 = 20000925号扇区,即(1244 柱面,254磁头,63扇区)。
三.查找E盘分区表 根据上面的信息,第三个分区表,也即E盘分区表在(892柱面,0磁头,1扇区)处。读取该扇区,得到分区表如下:
[00 01 C1 7C 0B FE FF FF 3F 00 00 00 E2 87 56 00]

[ 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ]

[00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ]

[00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ]

该分区表第二项全为0,说明没有下一个分区表了。该分区表就是分区表链的最后一个节点。
第一项:
(00)(01 C1 7C)(0B)(FE FF FF)(3F 00 00 00 )(E2 87 56 00)
该项与D盘分区表的第二项描述的都是E盘的情况,但它们在某些细节上又有所区别。
1.(00):表示E盘不是活动分区。
2.(01 C1 7C):
  (01) 16  =  (1) 10  (C1) 16  =  (1100 0001) 2  (7C) 16  =  (0111 1100) 2.
磁头号:(1) 10
扇区号:(00 0001) 2  =  (1) 10
柱面号:(11 0111 1100) 2  =  (892) 10
故E盘起始扇区为(892柱面,1磁头,1扇区)。
3.(0B):表示E盘的文件系统为FAT32。
4.(FE FF FF):
(FE) 16  =  (254) 10 。 (FF) 16  =  (1111 1111) 2  (FF) 16  =  (1111 1111) 2.
磁头号:(254) 10;
扇区号:(11 1111) 2  =  (63) 10.
柱面号:(11 1111 1111) 2  =  (1023) 10
但这是不准确的,原因同上。
5.(3F 00 00 00):
反向,(00 00 00 3F) 16  =  (63) 10.这一项与D盘分区表相应项有所不同.为E盘起始逻辑
扇区号(892柱面,1磁头,1扇区)与(892柱面,0磁头,1扇区)之差。表示E盘前面已有63个扇区, 这63个扇区为系统隐藏扇区。
操作系统无法对这些扇区进行读写,所以可以把自己的秘密信息写在这里.
6. (E2 87 56 00): 
反向,(00 56 87 E2) 16  =  (5670882) 10。表明E盘有5670882个扇区。而D盘分区表相应项为5670945. 5670945 - 5670882 = 63.
正好等于63个隐藏扇区.这是因为D盘分区表描述的是(892柱面,0磁头,1扇区) 到 (1244 柱面,254磁头,63扇区) 之间的扇区数。
而E盘分区表描述的是(892柱面, 1磁头,1扇区) 到 (1244 柱面,254磁头,63扇区) 之间的扇区数。
四.结束语
    至此,我们已经打通了整个分区表链.以后在某个链节点数据受损时,也可以根据上下节点的信息而手工定位并修复之。
修复工具可采用可读写磁盘的Winhex.
通信地址:
E-mail: yt_5000@sohu.com
邮政编码: 430074
湖北省武汉市中国地质大学硕2000-11班 印涛,秦剑

程序员最应该读的图书(中译版)

转自:http://my.oschina.net/cfanlds/blog/14486

来自StackOverflow上的投票,stackoverflow 是著名的计算机专业相关的问答社区。调查原文地址

http://stackoverflow.com/questions/1711/what-is-the-single-most-influential-book-every-programmer-should-read
取前20名。找了下中译本,
自己只有其中的两本,要多看书了。

1. 代码大全(第2版)
作者 : [美] 史蒂夫·迈克康奈尔
出版社 : 电子工业出版社
code.jpg
2. 程序员修炼之道
作者 : Andrew Hunt/David Thomas
出版社 : 电子工业出版社
2.jpg
3. 计算机程序的构造和解释(原书第2版)
作者 : Harold Abelson/Gerald Jay Sussman/Julie Sussman
出版社 : 机械工业出版社
3.jpg
4. C程序设计语言(第2版・新版)
作者 : 克尼汉
出版社 : 机械工业出版社
4.jpg
5. 算法导论
作者 : [美] Thomas H.Cormen/Charles E.Leiserson/Ronald L.Rivest/Clifford Stein
出版社 : 机械工业出版社

5.jpg
6. 重构:改善既有代码的设计/图灵程序设计丛书
作者 : Martin Fowler
出版社 : 人民邮电出版社

6.jpg
7. 人月神话
作者 : (美)布鲁克斯 著,汪颖 译
出版社 : 清华大学出版社
7.jpg
8. 设计模式
作者 : [美] Erich Gamma/Richard Helm/Ralph Johnson/John Vlissides
出版社 : 机械工业出版社
8.jpg
9. 计算机程序设计艺术(第1卷)
作者 : [美] Donald E. Knuth
出版社 : 清华大学出版社
9.jpg
10. 编译原理
作者 : Alfred V. Aho/Monica S.Lam/Ravi Sethi/Jeffrey D. Ullman
出版社 : 机械工业出版社
10.jpg
11. Head First 设计模式(中文版)
作者 : (美)弗里曼(Freeman,E.) 等著,Oreily Taiwan公司 译,UML China 改编
出版社 : 中国电力出版社
11.jpg
12. 哥德尔 艾舍尔 巴赫
作者 : [美]侯世达/Douglas Hofstadter
出版社 : 商务印书馆
12.jpg
13. Effective C++改善程序与设计的55个具体做法(中文第三版)
作者 : Scott Meyers
出版社 : 电子工业出版社
13.jpg
14. More Effective C++中文版
作者 : (美)迈耶斯 著,侯捷 译
出版社 : 中国电力出版社
14.jpg
15. 编程珠玑(第2版)
作者 : Jon Bentley
出版社 : 人民邮电出版社
15.jpg
16. 万里任禅游
作者 : (美)罗伯特·M·波西格
出版社 : 重庆出版社
16.jpg
17. 编码
作者 : [美] 佩措尔德 (Charles Petzold)
出版社 : 电子工业出版社
17.jpg
18. 修改代码的艺术
作者 : Michael Feathers
出版社 : 人民邮电出版社
18.jpg
19. 人件(第2版)
作者 : Tom DeMarco/Timothy Lister
出版社 : 清华大学出版社
19.jpg
20. 代码整洁之道
作者 : (美)马丁 著,韩磊 译
出版社 : 人民邮电出版社
20.jpg
21. 编程人生
作者 : Peter Seibel
出版社 : 人民邮电出版社

21.jpg