Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

creating a 32-bit binary file with nonzero org with TASM+TLINK

Tags:

x86

assembly

tasm

I'm looking for the equivalent of the following assembly program with TASM, i.e. creating a 32-bit binary file with nonzero org. Here is how it works with NASM:

; $ nasm -O0 -f bin -o id.bin id.nasm
bits 32
cpu 386
org 432100h
mov eax, foo
push eax
foo:
; $ ndisasm -b 32 id.bin
; 00000000  B806214300        mov eax,0x432106
; 00000005  50                push eax

Is it possible to do the same with a combination of TASM and TLINK? How would the .asm file look like? What are the compilation command lines?

Please note:

  • The output file must be 6 bytes long (see hex dump above), without any headers.

  • It's really TASM+TLINK. In this question I'm not looking for alternatives. (NASM can obviously do it, see above.)

  • The org must be 432100h. It's not OK to use org 0 and mov eax, foo+432100h.

Some context: I have a moderately complex x86 32-bit assembly program with binary file output, and I'm curious if it would be possible to port it to TASM.

like image 830
pts Avatar asked Oct 16 '25 00:10

pts


1 Answers

I managed to make it work with TASM+WLINK (rather than TASM+TLINK), using TASM 4.1 and the WLINK from OpenWatcom v2.

Here is my id.asm file:

.386   
.model flat
.stack 100h  ; Dummy, to pacify TASM.
mov eax, offset foo  
push eax
foo:
end foo  ; Dummy reference to foo, to pacify TASM.

Here is how I compile it:

tasm /t id.asm
wlink format raw bin option offset=0x432100 option quiet name idw.bin file id.obj
ndisasm -b 32 idw.bin

Output:

00000000  B806214300        mov eax,0x432106
00000005  50                push eax

Here is an alternative id.asm file, using TASM ideal mode:

p386n
model flat
stack 100h  ; Dummy, to pacify TASM.
codeseg
mov eax, offset foo
push eax
foo:   
end foo  ; Dummy, to pacify TASM.

Unfortunately most early versions of WLINK (such as in Watcom C/C++ 11.0B, the last release before OpenWatcom) don't support format raw.

like image 97
pts Avatar answered Oct 17 '25 14:10

pts