# [x86 ASM] .com to PE transition a bit rocky.

This topic is 4059 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

Hey guys. I'm using FASM (http://www.flatassembler.net/), making some x86 programs. Until just recently, I've only ever made .com files (raw executables). However, due to various limitations, I would like to begin assembling Portable Executables. However, things seem to instantly fail to work when doing this. I figure I've included everything necessary for a PE to work. At the beginning of the file, I've got format PE, I've got an entry Start (Start being a label), I've got a section '.code' code readable executable before all my code, and a section '.data' data readable writeable before all my dbs and dws, and I think all the other PE parameters are optional (like stack and heap). My code assembles fine, but hits a 'rand.exe has encountered a problem and blah blah blah' when I run it. So, is there a line I'm forgetting? Would you like my code posted? Thanks in advance.

##### Share on other sites
I've a couple of ideas as to what could be causing the problem. To narrow it down, it would help if you posted some code.

##### Share on other sites
Alrighty. Streamlined for all our sakes.
format PE consoleentry Startsection '.code' code readable executable; Bunch of labels with instructions that act as functions.; General stuff, like printing characters, strings, integers,; and generating random numbers (hence rand.exe).section '.data' data readable writeableseed dd        00000000000000000000000000000000b     db 0011101b                        ; Used for random number generation.n dw 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0    ; Used with integer printingnewline db 0Dh,0Ah,'\$'                  ; To make line breaks faster.

And that's it. As for the functions, I've got ScanChar (takes a keyboard input), PrintChar (shortcut for int 21h, ah=02), PrintString (same for int 21h, ah=09), PrintInt (big ole sucker that prints an integer in any base), SRand (takes an input for a random seed), TSRand (uses system time for seed), Rand (actually makes a number), Start (beginning of program), and Close (int 21h, ax=4C00h).

If you'd like to see their code (120 lines in total), ask again.

##### Share on other sites
Well, I don't really know about FASM, but a quick scan seems to indicate that you're trying to run DOS assembler (i.e. calling DOS interrupts) in Windows mode. The 'console' option probably makes a Windows console program not a DOS one. A COM file on the other hand, is always run as a DOS program. In Windows you need to call the Win32 API functions for the same purpose, or find a way to get FASM to produce DOS-format PE programs.

##### Share on other sites
format PE console
produces a 32-bit Windows executable. Given that you are calling DOS interrupts and (I assume) using 16-bit code, I think what you really want is to transition from a COM file to a 16-bit DOS EXE. For that, you need
format MZ

##### Share on other sites
Well, all those are valid points, and probably correct, but it seems my code has decided to asplode (http://www.uncyclopedia.org/wiki/A_Splode) in general; it no longer even works as a COM (even after removing the PE jargon). Ah well, I'll get back to you.

1. 1
2. 2
Rutin
25
3. 3
4. 4
JoeJ
18
5. 5

• 14
• 22
• 11
• 11
• 9
• ### Forum Statistics

• Total Topics
631764
• Total Posts
3002210
×