汇编链接后的.exe文件 无法执行

阳明阳明 2010-01-27 11:59:59

;********************************************************************************************************
; uC/OS-II
; The Real-Time Kernel
;
; (c) Copyright 1992-2002, Jean J. Labrosse, Weston, FL
; All Rights Reserved
;
;
; 80x86/80x88 Specific code
; LARGE MEMORY MODEL
;
; Borland C/C++ V4.51
; (IBM/PC Compatible Target)
;
; File : OS_CPU_A.ASM
; By : Jean J. Labrosse
;********************************************************************************************************

;********************************************************************************************************
; PUBLIC and EXTERNAL REFERENCES
;********************************************************************************************************

PUBLIC _OSTickISR
PUBLIC _OSStartHighRdy
PUBLIC _OSCtxSw
PUBLIC _OSIntCtxSw

EXTRN _OSIntExit:NEAR
EXTRN _OSTimeTick:NEAR
EXTRN _OSTaskSwHook:NEAR

EXTRN _OSIntNesting:BYTE
EXTRN _OSTickDOSCtr:BYTE
EXTRN _OSPrioHighRdy:BYTE
EXTRN _OSPrioCur:BYTE
EXTRN _OSRunning:BYTE
EXTRN _OSTCBCur:DWORD
EXTRN _OSTCBHighRdy:DWORD

.MODEL SMALL
.CODE
.186
PAGE ; /*$PAGE*/
;*********************************************************************************************************
; START MULTITASKING
; void OSStartHighRdy(void)
;
; The stack frame is assumed to look as follows:
;
; OSTCBHighRdy->OSTCBStkPtr --> DS (Low memory)
; ES
; DI
; SI
; BP
; SP
; BX
; DX
; CX
; AX
; OFFSET of task code address
; SEGMENT of task code address
; Flags to load in PSW
; OFFSET of task code address
; SEGMENT of task code address
; OFFSET of 'pdata'
; SEGMENT of 'pdata' (High memory)
;
; Note : OSStartHighRdy() MUST:
; a) Call OSTaskSwHook() then,
; b) Set OSRunning to TRUE,
; c) Switch to the highest priority task.
;*********************************************************************************************************

_OSStartHighRdy PROC

MOV AX, SEG _OSTCBHighRdy ; Reload DS
MOV DS, AX ;
;
CALL FAR PTR _OSTaskSwHook ; Call user defined task switch hook
;
MOV AL, 1 ; OSRunning = TRUE;
MOV BYTE PTR DS:_OSRunning, AL ; (Indicates that multitasking has started)
;
LES BX, DWORD PTR DS:_OSTCBHighRdy ; SS:SP = OSTCBHighRdy->OSTCBStkPtr
MOV SS, ES:[BX+2] ;
MOV SP, ES:[BX+0] ;
;
POP DS ; Load task's context
POP ES ;
POPA ;
;
IRET ; Run task

_OSStartHighRdy ENDP

PAGE ; /*$PAGE*/
;*********************************************************************************************************
; PERFORM A CONTEXT SWITCH (From task level)
; void OSCtxSw(void)
;
; Note(s): 1) Upon entry,
; OSTCBCur points to the OS_TCB of the task to suspend
; OSTCBHighRdy points to the OS_TCB of the task to resume
;
; 2) The stack frame of the task to suspend looks as follows:
;
; SP -> OFFSET of task to suspend (Low memory)
; SEGMENT of task to suspend
; PSW of task to suspend (High memory)
;
; 3) The stack frame of the task to resume looks as follows:
;
; OSTCBHighRdy->OSTCBStkPtr --> DS (Low memory)
; ES
; DI
; SI
; BP
; SP
; BX
; DX
; CX
; AX
; OFFSET of task code address
; SEGMENT of task code address
; Flags to load in PSW (High memory)
;*********************************************************************************************************

_OSCtxSw PROC
;
PUSHA ; Save current task's context
PUSH ES ;
PUSH DS ;
;
MOV AX, SEG _OSTCBCur ; Reload DS in case it was altered
MOV DS, AX ;
;
LES BX, DWORD PTR DS:_OSTCBCur ; OSTCBCur->OSTCBStkPtr = SS:SP
MOV ES:[BX+2], SS ;
MOV ES:[BX+0], SP ;
;
CALL FAR PTR _OSTaskSwHook ; Call user defined task switch hook
;
MOV AX, WORD PTR DS:_OSTCBHighRdy+2 ; OSTCBCur = OSTCBHighRdy
MOV DX, WORD PTR DS:_OSTCBHighRdy ;
MOV WORD PTR DS:_OSTCBCur+2, AX ;
MOV WORD PTR DS:_OSTCBCur, DX ;
;
MOV AL, BYTE PTR DS:_OSPrioHighRdy ; OSPrioCur = OSPrioHighRdy
MOV BYTE PTR DS:_OSPrioCur, AL ;
;
LES BX, DWORD PTR DS:_OSTCBHighRdy ; SS:SP = OSTCBHighRdy->OSTCBStkPtr
MOV SS, ES:[BX+2] ;
MOV SP, ES:[BX] ;
;
POP DS ; Load new task's context
POP ES ;
POPA ;
;
IRET ; Return to new task
;
_OSCtxSw ENDP

PAGE ; /*$PAGE*/




...全文
505 13 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
13 条回复
切换为时间正序
请发表友善的回复…
发表回复
亲休息吧 2012-01-03
  • 打赏
  • 举报
回复
只编译这个汇编可以运行?还有其他的函数文件吧!
阳明阳明 2010-01-30
  • 打赏
  • 举报
回复
[Quote=引用 7 楼 gogdizzy 的回复:]
引用 6 楼 xinxintai 的回复:
dosbox是干什么用的?


dos模拟器,可以在winxp以后的版本中使用(winxp以后的OS就不支持16位的程序了。),能够执行16位程序。
[/Quote]



上面的程序能在dosbox上跑吗
  • 打赏
  • 举报
回复
[Quote=引用 8 楼 xinxintai 的回复:]
上面的程序能在dosbox上跑吗
[/Quote]

我也不清楚,事实上,我不知道你的程序都会调用什么。不过普通的汇编16位程序都可以跑,我还用dosbox玩主题医院了。
xusir98 2010-01-30
  • 打赏
  • 举报
回复
进来学习一下,呵呵!
lz3771 2010-01-30
  • 打赏
  • 举报
回复
mark
  • 打赏
  • 举报
回复
应该可以,windows 3.1、95、98都可以在dosbox上安装运行,玩老系统,dosbox绝对是最好的虚拟机,比vmware、virtual pc、virtual box都强。
  • 打赏
  • 举报
回复
[Quote=引用 6 楼 xinxintai 的回复:]
dosbox是干什么用的?
[/Quote]

dos模拟器,可以在winxp以后的版本中使用(winxp以后的OS就不支持16位的程序了。),能够执行16位程序。
阳明阳明 2010-01-29
  • 打赏
  • 举报
回复
dosbox是干什么用的?
阳明阳明 2010-01-28
  • 打赏
  • 举报
回复

;*********************************************************************************************************
; PERFORM A CONTEXT SWITCH (From an ISR)
; void OSIntCtxSw(void)
;
; Note(s): 1) Upon entry,
; OSTCBCur points to the OS_TCB of the task to suspend
; OSTCBHighRdy points to the OS_TCB of the task to resume
;
; 2) The stack frame of the task to suspend looks as follows:
;
; OSTCBCur->OSTCBStkPtr ------> DS (Low memory)
; ES
; DI
; SI
; BP
; SP
; BX
; DX
; CX
; AX
; OFFSET of task code address
; SEGMENT of task code address
; Flags to load in PSW (High memory)
;
;
; 3) The stack frame of the task to resume looks as follows:
;
; OSTCBHighRdy->OSTCBStkPtr --> DS (Low memory)
; ES
; DI
; SI
; BP
; SP
; BX
; DX
; CX
; AX
; OFFSET of task code address
; SEGMENT of task code address
; Flags to load in PSW (High memory)
;*********************************************************************************************************

_OSIntCtxSw PROC
;
CALL FAR PTR _OSTaskSwHook ; Call user defined task switch hook
;
MOV AX, SEG _OSTCBCur ; Reload DS in case it was altered
MOV DS, AX ;
;
MOV AX, WORD PTR DS:_OSTCBHighRdy+2 ; OSTCBCur = OSTCBHighRdy
MOV DX, WORD PTR DS:_OSTCBHighRdy ;
MOV WORD PTR DS:_OSTCBCur+2, AX ;
MOV WORD PTR DS:_OSTCBCur, DX ;
;
MOV AL, BYTE PTR DS:_OSPrioHighRdy ; OSPrioCur = OSPrioHighRdy
MOV BYTE PTR DS:_OSPrioCur, AL
;
LES BX, DWORD PTR DS:_OSTCBHighRdy ; SS:SP = OSTCBHighRdy->OSTCBStkPtr
MOV SS, ES:[BX+2] ;
MOV SP, ES:[BX] ;
;
POP DS ; Load new task's context
POP ES ;
POPA ;
;
IRET ; Return to new task
;
_OSIntCtxSw ENDP

PAGE ; /*$PAGE*/
;*********************************************************************************************************
; HANDLE TICK ISR
;
; Description: This function is called 199.99 times per second or, 11 times faster than the normal DOS
; tick rate of 18.20648 Hz. Thus every 11th time, the normal DOS tick handler is called.
; This is called chaining. 10 times out of 11, however, the interrupt controller on the PC
; must be cleared to allow for the next interrupt.
;
; Arguments : none
;
; Returns : none
;
; Note(s) : The following C-like pseudo-code describe the operation being performed in the code below.
;
; Save all registers on the current task's stack;
; OSIntNesting++;
; if (OSIntNesting == 1) {
; OSTCBCur->OSTCBStkPtr = SS:SP
; }
; OSTickDOSCtr--;
; if (OSTickDOSCtr == 0) {
; OSTickDOSCtr = 11;
; INT 81H; Chain into DOS every 54.925 mS
; (Interrupt will be cleared by DOS)
; } else {
; Send EOI to PIC; Clear tick interrupt by sending an End-Of-Interrupt to the 8259
; PIC (Priority Interrupt Controller)
; }
; OSTimeTick(); Notify uC/OS-II that a tick has occured
; OSIntExit(); Notify uC/OS-II about end of ISR
; Restore all registers that were save on the current task's stack;
; Return from Interrupt;
;*********************************************************************************************************
;
_OSTickISR PROC
;
PUSHA ; Save interrupted task's context
PUSH ES
PUSH DS
;
MOV AX, SEG(_OSIntNesting) ; Reload DS
MOV DS, AX
INC BYTE PTR DS:_OSIntNesting ; Notify uC/OS-II of ISR
;
CMP BYTE PTR DS:_OSIntNesting, 1 ; if (OSIntNesting == 1)
JNE SHORT _OSTickISR1
MOV AX, SEG(_OSTCBCur) ; Reload DS
MOV DS, AX
LES BX, DWORD PTR DS:_OSTCBCur ; OSTCBCur->OSTCBStkPtr = SS:SP
MOV ES:[BX+2], SS ;
MOV ES:[BX+0], SP ;
;
_OSTickISR1:
MOV AX, SEG(_OSTickDOSCtr) ; Reload DS
MOV DS, AX
DEC BYTE PTR DS:_OSTickDOSCtr
CMP BYTE PTR DS:_OSTickDOSCtr, 0
JNE SHORT _OSTickISR2 ; Every 11 ticks (~199.99 Hz), chain into DOS
;
MOV BYTE PTR DS:_OSTickDOSCtr, 11
INT 081H ; Chain into DOS's tick ISR
JMP SHORT _OSTickISR3

_OSTickISR2:
MOV AL, 20H ; Move EOI code into AL.
MOV DX, 20H ; Address of 8259 PIC in DX.
OUT DX, AL ; Send EOI to PIC if not processing DOS timer.
;
_OSTickISR3:
CALL FAR PTR _OSTimeTick ; Process system tick
;
CALL FAR PTR _OSIntExit ; Notify uC/OS-II of end of ISR
;
POP DS ; Restore interrupted task's context
POP ES
POPA
;
IRET ; Return to interrupted task
;
_OSTickISR ENDP
;
END


以上.asm文件,我用masm 软件编译生成.obj之后,用tc创建了一个工程,链接之后生成test.exe文件,运行test.exe文件后,出现对话框:ntvcm.exe已停止工作,Windows 可以联机检查该问题的解决方案。打开问题详细信息,如下:
问题签名:
问题事件名称: APPCRASH
应用程序名: ntvdm.exe
应用程序版本: 6.0.6001.18000
应用程序时间戳: 47918baf
故障模块名称: StackHash_1703
故障模块版本: 0.0.0.0
故障模块时间戳: 00000000
异常代码: c0000005
异常偏移量: 00000075
OS 版本: 6.0.6001.2.1.0.768.3
区域设置 ID: 2052
其他信息 1: 1703
其他信息 2: 2264db07e74365624c50317d7b856ae9
其他信息 3: 1344
其他信息 4: 875fa2ef9d2bdca96466e8af55d1ae6e
我用的是vista系统
紫郢剑侠 2010-01-28
  • 打赏
  • 举报
回复
有些底层操作在Windows中是不能直接进行的,除非你改写成驱动程序
  • 打赏
  • 举报
回复
你用虚拟机安装一个纯dos才能运行。比如
MOV AL, 20H ; Move EOI code into AL.
MOV DX, 20H ; Address of 8259 PIC in DX.
OUT DX, AL ; Send EOI to PIC if not processing DOS timer.
直接操作时钟芯片的端口读写。不能在虚拟dos下用
  • 打赏
  • 举报
回复
下载dosbox:www.dosbox.com
  • 打赏
  • 举报
回复
不愧是大师级的代码啊!!!

21,497

社区成员

发帖
与我相关
我的任务
社区描述
汇编语言(Assembly Language)是任何一种用于电子计算机、微处理器、微控制器或其他可编程器件的低级语言,亦称为符号语言。
社区管理员
  • 汇编语言
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧