flat assembler
Message board for the users of flat assembler.
 Home   FAQ   Search   Register 
 Profile   Log in to check your private messages   Log in 
flat assembler > DOS > Chances to debug a .com file with source (labels/comments/)?

Goto page 1, 2  Next
Author
Thread Post new topic Reply to topic
marste



Joined: 05 May 2015
Posts: 42
Chances to debug a .com file with source (labels/comments/)?
There are the options to debug a .com file viewing not the compiled code but the source file with labels and comments in it?
PS: very nice FASM, I like it, compliments! Smile
Thank you!
Post 12 Sep 2015, 00:55
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 15233
Location: 1I/╩╗Oumuamua
The old Turbo Assembler had a source code level debugger included. I don't know of any thing for DOS that would work with fasm's debug format.
Post 12 Sep 2015, 10:45
View user's profile Send private message Visit poster's website Reply with quote
nop



Joined: 01 Sep 2008
Posts: 165
Location: right here left there
if u have assembled the .com file from fasm source you can generate the .fas file and tomasz has provided a utility to create a symbol list from the .fas file i did it some time ago and i can't check right now but it was in the docs with the download for the dos version
Post 12 Sep 2015, 11:21
View user's profile Send private message Reply with quote
marste



Joined: 05 May 2015
Posts: 42
I used all the tools to produce symbols, listing and "prepsrc" (produce just a listing of the instructions).

Tried Turbo Debugger, but it says that symbols have an invalid format and do not load it. It shows just disassembled instructions and dump of memory for data.

I tried also to compile an example with Turbo Assembler but it says that for .com the symbolic information are not produced.
Post 12 Sep 2015, 20:47
View user's profile Send private message Reply with quote
ACP



Joined: 23 Sep 2006
Posts: 197
Most DOS debuggers predates FASM hence there is no support for symbols. However if you like to use TASM & TD there is a way to have symbolic debugging in TD for COM files. Here is the trick:

TASM /zi yourfile.asm
TLINK /v yourfile.obj
TDSTRIP -s -c yourfile.exe yourfile.com

This will produce symbol file for com. You may try to generate symbols from obj files if I remember correctly. BTW: I hope you have a good reason for using COM format instead of EXE.
Post 13 Sep 2015, 08:41
View user's profile Send private message Reply with quote
marste



Joined: 05 May 2015
Posts: 42

ACP wrote:
Most DOS debuggers predates FASM hence there is no support for symbols. However if you like to use TASM & TD there is a way to have symbolic debugging in TD for COM files. Here is the trick:

TASM /zi yourfile.asm
TLINK /v yourfile.obj
TDSTRIP -s -c yourfile.exe yourfile.com

This will produce symbol file for com. You may try to generate symbols from obj files if I remember correctly. BTW: I hope you have a good reason for using COM format instead of EXE.



Great ACP, it works!!

Just now I should convert all my program syntax to TASM or there is a way to keep FASM one? (that I like very much and I have already used a bit!)

PS: the reason to have .com is the final executable size where even few bytes count!
Post 16 Sep 2015, 21:52
View user's profile Send private message Reply with quote
ACP



Joined: 23 Sep 2006
Posts: 197
If you plan to use TASM package than you need to convert source code to TASM or older MASM syntax. If you are converting from FASM syntax this document may provide a bit of help in such task: http://flatassembler.net/docs.php?article=design

Don't know how much sources you have in FASM format but if the number is substantial than maybe it would be worth to write symbols converter instead? Secondly I never liked Turbo Debugger personally. During DOS time there were few debuggers superior to TD, especially when you weren't using TASM.

The big question is do you really need symbol debugging? FASM does pretty good job at assembling code according to your source. Unless you are using complex macros and HLL features I would suggest to stick with FASM since it is actively developed contrary to TASM and choose a better debugger.

As for COM file format if you can live with its limitation than good for you.
Post 17 Sep 2015, 07:10
View user's profile Send private message Reply with quote
marste



Joined: 05 May 2015
Posts: 42
My code is pretty complex but not long at all. Just FASM syntax is for me more direct and clear (even if when I was programming assembler around 1987 I was using MASM one).

For this I'm surely open to change debugger, but should show source lines as TD does (i.e. with names and comments).

Then, which debugger to use?

If it's useful I should even be able to debug using .exe format and then convert to .com at the end!
Post 17 Sep 2015, 17:18
View user's profile Send private message Reply with quote
ACP



Joined: 23 Sep 2006
Posts: 197
Don't switch debugger because of my personal opinion. If you are fine with TD than use it. My favor debuggers supporting source code debugging are: Periscope 5.x and Soft-ICE 2.x (later versions are targeting Windows). The drawback is that none of them is working under DosBox and while there could a chance to make Periscope working SI is out of question since it is loaded as device driver. However they should work under DOS VM in VMware and VirtualBox.

Debugging EXE and later converting it to COM file format sound to me like a bad idea unless you can watch out for bugs being a result from executable formats differences. If you are dependent on Int 21h DOS services than this may bite you at one point. For example memory allocation works differently for COM and EXE programs.

TASM ideal mode and FASM syntax are superior to MASM different quirks.
Post 17 Sep 2015, 19:10
View user's profile Send private message Reply with quote
marste



Joined: 05 May 2015
Posts: 42
Seems Periscope and Soft-ICE are available only "cracked", so I stayed on tasm that on phatcode seems available to be used and for my needs seems ok.

It took me more than expected but at the end I compiled the source without apparent errors. The problem seems that tdstrip remove more than needed.

I need ds:0 to point at data section and so I wrote a simple program that show the problem I have:

ideal
model tiny
segment code
assume cs:code, ds:code, ss:code
org 0
zero equ $
org 100h ; .com
start:
xor ax,ax ; mov ah,00 ; Select the video mode 0
int 10h ; Call video interrupt
mov ax,ds
add ax, (post_dataoffset - zero) / 16
mov ds,ax
xor dx,dx
mov ah,9 ; print string at ds:dx
int 21h
mov ax,4c00h
int 21h
dataoffset:
align 16
post_dataoffset:
org 0
db "simple string to print$"
ends code
end start

After tdstrip the .com file is 32 bytes long and do not contain the "simple string to print$"...
Post 19 Sep 2015, 09:41
View user's profile Send private message Reply with quote
marste



Joined: 05 May 2015
Posts: 42
PS: the FASM "equivalent" version is infact 55 bytes long (i.e. include the string to print!)

use16
org 100h
start:
xor ax,ax ; mov ah,00 ; Select the video mode 0
int 10h ; Call video interrupt
mov ax,ds
add ax, post_dataoffset / 16
mov ds,ax
xor dx,dx
mov ah,9 ; print string at ds:dx
int 21h
mov ax,4c00h
int 21h
dataoffset:
align 16
post_dataoffset:
org 0
db "simple string to print$"
Post 19 Sep 2015, 10:10
View user's profile Send private message Reply with quote
ACP



Joined: 23 Sep 2006
Posts: 197
I think that the problem is org 0 statement after post_dataoffset label. Why are you putting you string at that location? COM files starts at 100h, the memory below is used by DOS structures and in COM files you can't have more than one segment containing code, data and stack.

BTW: I can't compile you example code using TASM 5 package.
Post 19 Sep 2015, 10:17
View user's profile Send private message Reply with quote
marste



Joined: 05 May 2015
Posts: 42

ACP wrote:
I think that the problem is org 0 statement after post_dataoffset label. Why are you putting you string at that location? COM files starts at 100h, the memory below is used by DOS structures and in COM files you can't have more than one segment containing code, data and stack.


I need to reset assembler location since to compact my code I need to reference the location at DS with zero offset. Infact in FASM this part works fine.


ACP wrote:
BTW: I can't compile you example code using TASM 5 package.


Sorry, tryed with v5 (before was v4) and it works (to work properly need "zero = $" and not "zero equ $"!).
Just the .com is 64 bytes and not 55 as the working FASM version.
Post 19 Sep 2015, 13:19
View user's profile Send private message Reply with quote
ACP



Joined: 23 Sep 2006
Posts: 197
When you try to assemble you example code with TASM and link it with TLINK directly to COM file you get the following error due to org 0 directive:

Cannot generate COM file: data below initial CS:IP defined.

That is why TDSTRIP truncates your file when you convert from EXE to COM. This is exactly type of issue I've been warning you about.

Just because the assembler/linker was able to produce output file doesn't mean it will run correctly. In case of FASM the resulting COM is not working properly due to the fact that COM file has single segment. You need to manually relocate data using rep movs and you can use EQUs definition for correct offsets when accessing your data. Additionally overwriting DOS structures like PSP isn't a good idea if you are using DOS INT 21h handler: some functions will not work correctly.

BTW: the 16bit TASM.EXE and TASMX from TASM 5 package are in fact v4.1. Only the TASM32.EXE is v5.0.
Post 19 Sep 2015, 14:06
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 15233
Location: 1I/╩╗Oumuamua

ACP wrote:
In case of FASM the resulting COM is not working properly due to the fact that COM file has single segment. You need to manually relocate data using rep movs and you can use EQUs definition for correct offsets when accessing your data. Additionally overwriting DOS structures like PSP isn't a good idea if you are using DOS INT 21h handler: some functions will not work correctly.

No, fasm doesn't move the data down. It just appends it to the end as the OP intended. Indeed the fasm generated file will work fine.
Post 19 Sep 2015, 14:17
View user's profile Send private message Visit poster's website Reply with quote
ACP



Joined: 23 Sep 2006
Posts: 197
Did you actually run the resulting file under DOS/DosBOX? Even looking at the disassembly you can tell it will not run properly. Unless you are referring to the fact that DOS will happily execute resulting file. In such case you are right - FASM will generate output that DOS will execute.
Post 19 Sep 2015, 14:23
View user's profile Send private message Reply with quote
marste



Joined: 05 May 2015
Posts: 42
Yes, I run both resulting files (55 and 64 bytes) and they worked!

Just... now I tryed to replicate the compilation to show it and ... I'm not able to obtain back the 64 bytes!!! Sad

Anyway org directive should just telling assembler to think that everything following that instruction has a different address but is not actually moving bytes around (as 100h is infact starting at the first byte). Assembler should just add up bytes than then dos with .com management load at 100h and start to execute.

Anyway I confirm: the problem is in the org 0 directive. To use TASM I should offset everithing. Probably I will.

In the meantime thank you!!
Post 19 Sep 2015, 16:18
View user's profile Send private message Reply with quote
ACP



Joined: 23 Sep 2006
Posts: 197
As for TASM there should be a way of creating TDS file for Turbo Debugger using TDMAP utility but I can't find a combination of tools that will work together. Basically after linking to COM file with TLINK you should create TDS file using TDMAP and later load COM file into TD.
Post 19 Sep 2015, 23:03
View user's profile Send private message Reply with quote
marste



Joined: 05 May 2015
Posts: 42

ACP wrote:
As for TASM there should be a way of creating TDS file for Turbo Debugger using TDMAP utility but I can't find a combination of tools that will work together. Basically after linking to COM file with TLINK you should create TDS file using TDMAP and later load COM file into TD.



I have TDS file (and is loading in TD), my compilation is:


Code:

tasm /c /x /la /zi /m9 /dtasm=1 test.asm
tlink /n /Tde /O /v test.obj
tdstrip -s -c smext.exe test.com 




I was even able to make the source compatible with tasm and fasm together. The trick is in the option /dtasm=1 above and the instructions (if someone will find useful):


Code:
if tasm eq 1
  ; tasm
else
  ; fasm
  endif equ end if
endif

if tasm eq 1
    ideal
    model tiny
    segment code
    assume cs:codeds:codess:code
else
    use16
endif

org 0
zero = $
org 100h ; .com 



And then offsetting all the instructions and data definition with the "zero" offset when referring to offset, as for example:


Code:
    les bx,[memory_location -zero]
    dw memory_location -zero
memory_location db ...


(sometimes not required but better more then less! Wink)

The program should end with:


Code:
if tasm eq 1
    ends code
    end start
endif


(it's giving a warning in tasm because didn't reach endif but just that)

And now... let's debug!
Post 20 Sep 2015, 08:24
View user's profile Send private message Reply with quote
ACP



Joined: 23 Sep 2006
Posts: 197
TDMAP allows creating TDS files which means you could skip conversion from EXE to COM. In such case you can directly link to COM (TLINK /t or /Tdc option). Anyway I could not find in my collection a set of Borland tools that would work together and apparently TDMAP is missing from TASM v5 package. Oh well, it has been so long ago when I used all those tools.

Good luck with debugging.

BTW: An interesting detail: I did not remember that TASM is using xchg bx,bx as padding (fasm is using nop).
Post 20 Sep 2015, 10:16
View user's profile Send private message Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  
Goto page 1, 2  Next

< Last Thread | Next Thread >

Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Powered by phpBB © 2001-2005 phpBB Group.

Main index   Download   Documentation   Examples   Message board
Copyright © 2004-2016, Tomasz Grysztar.