Use of Turbo Assembler

坚强是说给别人听的谎言 提交于 2020-12-30 03:37:42

问题


I use an IBM processor, and I have barely begun to delve into x86 assembly. Now that I have thoroughly read through an assembly book, I decided to put a simple program to the test (one that prints an exclamation mark on the screen):

.MODEL SMALL
.CODE
     MOV AH,2h
     MOV DL,21h
     INT 21h
     INT 20h
END

Now, there was a similar example in the book titled Peter Norton's Assembly Language Book for the IBM PC that went along these lines:

.MODEL SMALL
.CODE
     MOV AH,2h
     MOV DL,2Ah
     INT 21h
     INT 20h
END

I assume that this program would print an asterisk according to the ASCII table, but I cannot test that because of the fact that I know not how to handle TASM since I barely installed it on my Dell Inspiron which contains an Intel processor (which should imply an IBM system). In the command prompt of the TASM, I typed the following lines of code ultimately in order to assemble the program that I called EXCLAMAT.asm and run it:

C:\TASM>TASM EXCLAMAT.asm;
C:\TASM>TLINK EXCLAMAT;
C:\TASM>TD EXCLAMAT.exe

When I ran this program, a dialog told me that: "Program has no symbol table"

What did I do incorrectly? Thank you very much!


回答1:


TD (Turbo Debugger) is the wrong tool to run the program. You need only to type in the program name on the prompt:

C:\TASM>EXCLAMAT.exe

The message of TD "Program has no symbol table" is just a warning that you see the pure code and no labels or names. To avoid it: TLINK /v EXCLAMAT;




回答2:


Don't you get some warnings when linking your assembled code? There are several issues when I test it:

  • you need to define the program entry point by setting a label at begining of code, then using the directive end label_defined, else you get this link error

    Fatal: No program entry point

  • when producing a .exe you need also to allocate a stack with the .stack directive else you will have this warning:

    Warning: No stack

  • the int 20h was commonly used to terminate a .com program but it is not adapted to .exe. The prefered method is to call the int 21h with AH = 4c to terminate and specify a return code. See this MSDN entry for a detailed explanation.

Thus to compile an behave correctly your program becomes:

;produce a .exe file
; tasm exclamat.asm;
; tlink /v exclamat  (/v for including debug info for td)

.model small
.stack          ;if no value given, defaults to 1024

.code
entrypoint:

    mov ah,2h
    mov dl,21h
    int 21h
    
    ; terminate with int 21h / ah=4c instead of int 20h
    ; see http://support.microsoft.com/kb/72848/en-us
    mov ax,4c00h
    int 21h

end entrypoint  ;define the entry point to the specified label

In the case you would produce a .com file, there is some other needs:

  • assembly must start at the 100h address
  • do not specify a stack
  • you can terminate with int 20h
  • link with the /t parameter

Here is the same program modified:

;produce a .com file
; tasm exclamat.asm;
; tlink /t exclamat.obj

.model small

.code
    org 100h

entrypoint:
    mov ah,2h
    mov dl,21h
    int 21h
    int 20h
end entrypoint

BTW, this codes were tested on a WXP host and the old tasm.exe seems to have problems with underlying ntvdm process that supports the 16bit legacy code. If your console becomes weird (e.g completion do not work anymore), you might have to kill ntvdm to unlock it. I guess you would get a better behavior inside a dos emulator like DOSBox...



来源:https://stackoverflow.com/questions/24049946/use-of-turbo-assembler

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!