我用汇编语言制作了一个项目,需要使用 .lib 文件。我使用 TASM 汇编器,但我没有成功运行我的程序。
我搜索了有关使用 TASM 链接 .lib 文件的信息,但所有来源都向我展示了如何使用 MASM 链接 .lib 文件。我找到了一个简短的教程,我一直在尝试从http://grail.cba.csuohio.edu/~jackie/cis335/tasmInfo.htm使用它,但我仍然无法运行我的程序。
我用汇编语言制作了一个项目,需要使用 .lib 文件。我使用 TASM 汇编器,但我没有成功运行我的程序。
我搜索了有关使用 TASM 链接 .lib 文件的信息,但所有来源都向我展示了如何使用 MASM 链接 .lib 文件。我找到了一个简短的教程,我一直在尝试从http://grail.cba.csuohio.edu/~jackie/cis335/tasmInfo.htm使用它,但我仍然无法运行我的程序。
IRVINE16.INC
使用 TASM 不理解的指令(例如 PROTO)。IRVINE16.LIB
导出修饰名称(例如_WriteString@0
)。
首先,您需要使IRVINE16.INC
可读性:
.NOLIST
为%NOLIST
PROTO
。STRUCT
为STRUC
(CursorPosStruc, TimeRecord, FPU_ENVIRON)DWORD
为DD
. 不要改变ALIGN DWORD
WORD
为DW
BYTE
为DB
现在创建一个带有 .inc 扩展名的8.3文本文件。让我们命名它beeftasm.inc
:
EXTRN _Clrscr@0:PROC
EXTRN _Crlf@0:PROC
EXTRN _Delay@0:PROC
EXTRN _DumpMem@0:PROC
EXTRN _DumpRegs@0:PROC
EXTRN _GetCommandtail@0:PROC
EXTRN _GetMaxXY@0:PROC
EXTRN _GetMseconds@0:PROC
EXTRN _Gotoxy@0:PROC
EXTRN _IsDigit@0:PROC
EXTRN _Randomize@0:PROC
EXTRN _RandomRange@0:PROC
EXTRN _Random32@0:PROC
EXTRN _ReadHex@0:PROC
EXTRN _ReadInt@0:PROC
EXTRN _ReadChar@0:PROC
EXTRN _ReadFloat@0:PROC
EXTRN _ReadString@0:PROC
EXTRN _SetTextColor@0:PROC
EXTRN _ShowFPUStack@0:PROC
EXTRN _WaitMsg@0:PROC
EXTRN _WriteBin@0:PROC
EXTRN _WriteBinB@0:PROC
EXTRN _WriteChar@0:PROC
EXTRN _WriteDec@0:PROC
EXTRN _WriteHex@0:PROC
EXTRN _WriteHexB@0:PROC
EXTRN _WriteInt@0:PROC
EXTRN _WriteString@0:PROC
EXTRN _WriteFloat@0:PROC
EXTRN _Str_copy@4:PROC
EXTRN _Str_length@2:PROC
EXTRN _Str_compare@4:PROC
EXTRN _Str_trim@4:PROC
EXTRN _Str_ucase@2:PROC
Str_copy = cs:_Str_copy@4
Str_length = cs:_Str_length@2
Str_compare = cs:_Str_compare@4
Str_trim = cs:_Str_trim@4
Str_ucase = cs:_Str_ucase@2
Clrscr = cs:_Clrscr@0
Crlf = cs:_Crlf@0
Delay = cs:_Delay@0
DumpMem = cs:_DumpMem@0
DumpRegs = cs:_DumpRegs@0
GetCommandtail = cs:_GetCommandtail@0
GetMaxXY = cs:_GetMaxXY@0
GetMseconds = cs:_GetMseconds@0
Gotoxy = cs:_Gotoxy@0
IsDigit = cs:_IsDigit@0
Randomize = cs:_Randomize@0
RandomRange = cs:_RandomRange@0
Random32 = cs:_Random32@0
ReadHex = cs:_ReadHex@0
ReadInt = cs:_ReadInt@0
ReadChar = cs:_ReadChar@0
ReadFloat = cs:_ReadFloat@0
ReadString = cs:_ReadString@0
SetTextColor = cs:_SetTextColor@0
ShowFPUStack = cs:_ShowFPUStack@0
WaitMsg = cs:_WaitMsg@0
WriteBin = cs:_WriteBin@0
WriteBinB = cs:_WriteBinB@0
WriteChar = cs:_WriteChar@0
WriteDec = cs:_WriteDec@0
WriteHex = cs:_WriteHex@0
WriteHexB = cs:_WriteHexB@0
WriteInt = cs:_WriteInt@0
WriteString = cs:_WriteString@0
WriteFloat = cs:_WriteFloat@0
下面是一个小测试程序,它调用所有导出的函数IRVINE16.LIB
:
; Name: testirv.asm
; Assemble: tasm testirv
; Link: tlink /3 testirv
; Run: testirv Take whatever you need
INCLUDE IRVINE16.inc
INCLUDELIB Irvine16.lib
INCLUDE beeftasm.inc
.CODE
main PROC
mov ax, @data
mov ds, ax
call WhereXY
mov WORD PTR [buf], dx
call Clrscr
call WhereXY
mov WORD PTR [buf+2], dx
lea dx, tClrscr
call WriteString
movzx eax, WORD PTR [buf+2]
call WriteDec
mov al, ' '
call WriteChar
movzx eax, WORD PTR [buf]
call WriteDec
call Crlf
lea dx, tDumpMem
call WriteString
lea si, hello
mov cx, 16
mov bx, 1
mov dx, OFFSET hello
call DumpMem
lea dx, tGetCommandtail
call WriteString
lea dx, buf
call GetCommandtail
call WriteString
call Crlf
lea dx, tWriteString
call WriteString
mov dx, OFFSET hello
call WriteString
call Crlf
lea dx, tWriteChar
call WriteString
mov al, [hello]
call WriteChar
mov al, [hello+6]
call WriteChar
call Crlf
lea dx, tWriteInt
call WriteString
mov eax, 1234567890
call WriteInt
mov al, ' '
call WriteChar
call WriteChar
call WriteChar
lea dx, tWriteDec
call WriteString
mov eax, 1234567890
call WriteDec
mov al, ' '
call WriteChar
call WriteChar
call WriteChar
lea dx, tWriteHex
call WriteString
mov eax, 1234567890
call WriteHex
call Crlf
lea dx, tWriteHexB
call WriteString
mov eax, 1234567890
mov ebx, 1
call WriteHexB
call Crlf
lea dx, tWriteBin
call WriteString
mov eax, 1234567890
call WriteBin
call Crlf
lea dx, tWriteBinB
call WriteString
mov eax, 1234567890
mov ebx, 1
call WriteBinB
call Crlf
lea dx, tGetMaxXY
call WriteString
call GetMaxXY
movzx eax, dl
call WriteDec
mov al, ' '
call WriteChar
movzx eax, dh
call WriteDec
call Crlf
lea dx, tGetMseconds
call WriteString
call GetMseconds
mov DWORD PTR [buf], eax
call WriteDec
call Crlf
call WhereXY
push dx
mov dh, 6
mov dl, 40
call Gotoxy
lea dx, tGotoxy
call WriteString
mov bl, lightBlue
lea si, hello2
call WriteColoredString
pop dx
call Gotoxy
lea dx, tIsDigit
call WriteString
lea si, tDecStr
J1:
lodsb
test al, al
jz J2
call IsDigit
setz al
or al, 30h
call WriteChar
jmp J1
J2:
call Crlf
lea dx, tRandom32
call WriteString
call Random32
call WriteDec
call Crlf
lea dx, tRandomRange
call WriteString
mov ecx, 10
J3:
mov eax, 1000
call RandomRange
call WriteDec
mov al, ' '
call WriteChar
loop J3
call Crlf
lea dx, tRandomize
call WriteString
call Randomize
mov ecx, 10
J4:
mov eax, 1000
call RandomRange
call WriteDec
mov al, ' '
call WriteChar
loop J4
call Crlf
lea dx, tStr_compare
call WriteString
push OFFSET tString2
push OFFSET tString1
call Str_compare
setz al
movzx eax, al
call WriteDec
mov al, ' '
call WriteChar
push OFFSET tString1
push OFFSET tString1
call Str_compare
setz al
movzx eax, al
call WriteDec
call Crlf
lea dx, tStr_copy
call WriteString
mov ax, SEG buf
mov es, ax
push OFFSET buf
push OFFSET tString1
call Str_copy
xor al, al
mov cx, 0FFFFh
lea di, buf
repne scasb
mov BYTE PTR [di-1], ' '
push di
push OFFSET tString2
call Str_copy
lea dx, buf
call WriteString
call Crlf
lea dx, tStr_length
call WriteString
push OFFSET tString1
call Str_length
call WriteDec
call Crlf
lea dx, tStr_trim
call WriteString
mov eax, 'sss'
mov DWORD PTR [tString2 + 3], 'sss'
mov ax, ds
mov es, ax
push 's'
push OFFSET tString2
call Str_trim
cld ; Restore the default direction (up)
lea dx, tString2
call WriteString
call Crlf
lea dx, tStr_ucase
call WriteString
push OFFSET tString1
call Str_ucase
lea dx, tString1
call WriteString
call Crlf
lea dx, tWaitMsg
call WriteString
call WaitMsg
lea dx, tDumpRegs
call WriteString
call DumpRegs
lea dx, tShowFPUStack
call WriteString
finit
fld1
fldPI
fldz
fld fDouble
fld fSingle
call ShowFPUStack
call Crlf
lea dx, tWriteFloat
call WriteString
call WriteFloat
call Crlf
lea dx, tReadFloat
call WriteString
finit
call ReadFloat
call GotoPrevChar
mov al, ' '
call WriteChar
call WriteFloat
call Crlf
lea dx, tReadString
call WriteString
lea dx, buf
call ReadString
push ax
call GotoPrevChar
mov al, ' '
call WriteChar
pop ax
movzx eax, ax
call WriteDec
mov al, ' '
call WriteChar
lea dx, buf
call WriteString
call Crlf
lea dx, tReadInt
call WriteString
call ReadInt
push eax
call GotoPrevChar
mov al, ' '
call WriteChar
pop eax
call WriteDec
call Crlf
lea dx, tReadChar
call WriteString
call ReadChar
push ax
mov al, ' '
call WriteChar
pop ax
call WriteChar
call Crlf
lea dx, tReadHex
call WriteString
call ReadHex
mov esi, eax
call GotoPrevChar
mov al, ' '
call WriteChar
mov eax, esi
call WriteBin
mov al, ' '
call WriteChar
mov eax, esi
call WriteInt
mov al, ' '
call WriteChar
mov eax, esi
call WriteDec
call Crlf
call Crlf
call WaitMsg
mov ax, red
call SetTextColor
lea dx, tSetTextColor
call WriteString
lea dx, hello1
call WriteString
call Crlf
lea dx, tDelay
call WriteString
call GetMseconds
mov ebx, eax
mov eax, 100000
call Delay
call GetMseconds
sub eax, ebx
call WriteDec
call Crlf
mov ax, 4c00h
int 21h
main ENDP
;---------------------------------------------------
WhereXY PROC
;
; Gets the cursor position on video page 0.
; Receives: nothing
; Returns: DH, DL = row, column
;---------------------------------------------------
push ax
push bx
push cx
mov ah, 3
xor bh, bh
int 10h
pop cx
pop bx
pop ax
ret
WhereXY ENDP
;---------------------------------------------------
WhatXY PROC
;
; Gets the character at cursor position on video page 0.
; Receives: nothing
; Returns: AH, AL = attribute, character
;---------------------------------------------------
push bx
mov ah, 8
xor bh, bh
int 10h
pop bx
ret
WhatXY ENDP
;---------------------------------------------------
GotoPrevChar PROC
;
; Gets the previous character from cursor position on video page 0.
; Receives: nothing
; Returns: Cursor on the video position right after the previous character
;---------------------------------------------------
pusha
call WhereXY
xor dl, dl
@@J1:
call Gotoxy
dec dh
call WhatXY
cmp al, 20h
je @@J1
inc dh
mov bx, dx
call GetMaxXY
mov dh, bh
@@J2:
dec dl
call Gotoxy
call WhatXY
cmp al, 20h
je @@J2
inc dl
call Gotoxy
popa
ret
GotoPrevChar ENDP
;------------------------------------------------------
WriteColoredString PROC
;
; Writes a colored string
; Receives: DS:SI = Pointer to a zero terminated string
; BL = Color attribute (see Irvine16.inc)
; Returns: nothing
;-------------------------------------------------------
pusha
xor bh, bh
@@nextchar:
lodsb
test al, al
jz @@return
mov cx, 1
mov ah, 09h
int 10h
push bx
mov ah, 3
int 10h
inc dl
mov ah, 2
int 10h
pop bx
jmp @@nextchar
@@return:
popa
ret
WriteColoredString ENDP
.DATA
hello db "Hello world",0
hello1 db "Hello red world",0
hello2 db "Hello blue planet",0
tDecStr db " 2790000000 owns Donald Trump at least, but I only want a thank you",0
fDouble dq 1.23456789
fSingle dd 9.87654321
tString1 db 'first',0
tString2 db 'second',0
buf db 80h DUP(0)
tClrscr db "Clrscr: ",0
tDelay db "Delay (10 seconds): ",0
tDumpMem db "DumpMem: ",0
tDumpRegs db "DumpRegs: ",0
tGetCommandtail db "GetCommandtail: ",0
tGetMaxXY db "GetMaxXY: ",0
tGetMseconds db "GetMseconds: ",0
tGotoxy db "Gotoxy: ",0
tIsDigit db "IsDigit: ",0
tRandom32 db "Random32: ",0
tRandomize db "Randomize: ",0
tRandomRange db "RandomRange: ",0
tReadChar db "ReadChar: ",0
tReadFloat db "ReadFloat: ",0
tReadHex db "ReadHex: ",0
tReadInt db "ReadInt: ",0
tReadString db "ReadString: ",0
tSetTextColor db "SetTextColor: ",0
tShowFPUStack db "ShowFPUStack: ",0
tStr_compare db "Str_compare: ",0
tStr_copy db "Str_copy: ",0
tStr_length db "Str_length: ",0
tStr_trim db "Str_trim: ",0
tStr_ucase db "Str_ucase: ",0
tWaitMsg db "WaitMsg: ",0
tWriteBin db "WriteBin: ",0
tWriteBinB db "WriteBinB: ",0
tWriteChar db "WriteChar: ",0
tWriteDec db "WriteDec: ",0
tWriteFloat db "WriteFloat: ",0
tWriteHex db "WriteHex: ",0
tWriteHexB db "WriteHexB: ",0
tWriteInt db "WriteInt: ",0
tWriteString db "WriteString: ",0
END main