Author Topic: 64-bit Assemblers  (Read 25448 times)

sinsi

  • Guest
Re: 64-bit Assemblers
« Reply #15 on: September 14, 2012, 05:48:13 PM »
japheth, you can use the macros to basically create a sort of .rc section, it doesn't have to be a precompiled .res file.
With the sort of things fasm's macro language can do, it's more of a macro assembler than masm is.

And it kills ml64  :biggrin:

japheth

  • Guest
Re: 64-bit Assemblers
« Reply #16 on: September 14, 2012, 06:03:01 PM »
japheth, you can use the macros to basically create a sort of .rc section, it doesn't have to be a precompiled .res file.
With the sort of things fasm's macro language can do, it's more of a macro assembler than masm is.

Ok, but isn't this also possible with Masm? Masm won't create a PE binary, but writing data into a .rsrc section should be no problem.

sinsi

  • Guest
Re: 64-bit Assemblers
« Reply #17 on: September 14, 2012, 06:15:35 PM »
Ok, but isn't this also possible with Masm? Masm won't create a PE binary, but writing data into a .rsrc section should be no problem.
Not sure. Does masm or the linker associate a .rsrc section with the resource entry in the PE header?

farrier

  • Member
  • **
  • Posts: 58
Re: 64-bit Assemblers
« Reply #18 on: September 14, 2012, 07:17:32 PM »
The fasm can take one source file--see attached Windows dialog example from fasm package, with .exe--assembles the asm source creates the resource section and builds the executable with no need for a linker.  Can also create a Version section and Manifest section.  With any of the fasm packages: Windows IDE; Windows command line; DOS with extender; Linux and variants; you can create .exe, .dll, .obj, .bin, .so? .bin for Windows, DOS, Linux & with the version--fasmarm--maintained by revolution, for ARM chips.

The only time I've needed a linker was to combine my fasm .obj file with a MASM .obj file.

I started with MASM but use the fasm exclusively now.  Just starting in the 64 bit world now.

hth,

farrier
For the code is dark, and full of errors!
It's a good day to code!
Don't Bogart that code, my friend!

CodeDog

  • Guest
Re: 64-bit Assemblers
« Reply #19 on: September 14, 2012, 10:46:50 PM »
In fasm you normally write your libraries in plain source files and then include them. Or use dll's. You can build object files too but you need an external linker. When building your source library you can use conditional assembly like this:

Code: [Select]
if used myvar1
   myvar1 db 100000 dup 0
end if

If you don't refer to the data, it will not be included in the final executable.


 
« Last Edit: September 15, 2012, 11:32:03 AM by CodeDog »

CodeDog

  • Guest
Re: 64-bit Assemblers
« Reply #20 on: September 15, 2012, 11:31:44 AM »
The times directive is cool, here is an example how to create a rot13 lookup table, 256 items in the array using the times directive in fasm:

Code: [Select]
        times 65 db %-1
        times 26 db (((%-1)+13) MOD 26) + 65
        times 6 db %+90
        times 26 db (((%-1)+13) MOD 26) + 97
        times 133 db %+122

and here is the equivalent in masm. I may have been doing things too complex in masm, but this is what i've got:

Code: [Select]
Rot13Buf4                 DB 0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26
DB 27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50
DB 51,52,53,54,55,56,57,58,59,60,61,62,63,64
DB "NOPQRSTUVWXYZABCDEFGHIJKLM"
DB 91,92,93,94,95,96
DB "nopqrstuvwxyzabcdefghijklm"
DB 123,124,125,126,127,128,129,130,131,132,133,134,135,136,137,138,139,140,141,142
DB 143,144,145,146,147,148,149,150,151,152,153,154,155,156,157,158,159,160,161,162
DB 163,164,165,166,167,168,169,170,171,172,173,174,175,176,177,178,179,180,181,182
DB 183,184,185,186,187,188,189,190,191,192,193,194,195,196,197,198,199,200,201,202
DB 203,204,205,206,207,208,209,210,211,212,213,214,215,216,217,218,219,220,221,222
DB 223,224,225,226,227,228,229,230,231,232,233,234,235,236,237,238,239,240,241,242
DB 243,244,245,246,247,248,249,250,251,252,253,254,255

Both of these do the exact same thing.  :eusa_snooty:

MichaelW

  • Global Moderator
  • Member
  • *****
  • Posts: 1209
Re: 64-bit Assemblers
« Reply #21 on: September 15, 2012, 03:23:01 PM »
Using MASM I can’t see any way to define the table as compactly as FASM can, but I can see a simpler way to define it.
Code: [Select]
;===================================================================================
include \masm32\include\masm32rt.inc
;===================================================================================
.data

Rot13Buf4 LABEL BYTE
DB 0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26
DB 27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50
DB 51,52,53,54,55,56,57,58,59,60,61,62,63,64
DB "NOPQRSTUVWXYZABCDEFGHIJKLM"
DB 91,92,93,94,95,96
DB "nopqrstuvwxyzabcdefghijklm"
DB 123,124,125,126,127,128,129,130,131,132,133,134,135,136,137,138,139,140,141,142
DB 143,144,145,146,147,148,149,150,151,152,153,154,155,156,157,158,159,160,161,162
DB 163,164,165,166,167,168,169,170,171,172,173,174,175,176,177,178,179,180,181,182
DB 183,184,185,186,187,188,189,190,191,192,193,194,195,196,197,198,199,200,201,202
DB 203,204,205,206,207,208,209,210,211,212,213,214,215,216,217,218,219,220,221,222
DB 223,224,225,226,227,228,229,230,231,232,233,234,235,236,237,238,239,240,241,242
DB 243,244,245,246,247,248,249,250,251,252,253,254,255

ROT13BUF LABEL BYTE
N=0
REPEAT 65
    DB N
    N=N+1
ENDM
DB "NOPQRSTUVWXYZABCDEFGHIJKLM",91,92,93,94,95,96,"nopqrstuvwxyzabcdefghijklm"
N=123
REPEAT 133
    DB N
    N=N+1
ENDM

.code
;===================================================================================
start:
;===================================================================================

    mov esi, OFFSET Rot13Buf4
    mov edi, OFFSET ROT13BUF
    xor ebx, ebx
    REPEAT 256
        movzx edx, BYTE PTR [esi+ebx]
        printf("%d\t%d\t",ebx,edx)
        movzx edx, BYTE PTR [edi+ebx]
        printf("%d\n",edx)
        inc ebx
    ENDM

    inkey
    exit
;===================================================================================
end start

Well Microsoft, here’s another nice mess you’ve gotten us into.

CodeDog

  • Guest
Re: 64-bit Assemblers
« Reply #22 on: September 15, 2012, 04:27:40 PM »
I had a suspicion it could be simplified a bit.

The file directive is also cool if you need to load data directly into the executable from a file

Code: [Select]
Buf    file '1.asm':100,200
       file '1.asm':350,800
This loads 200 bytes from offset 100 and 800 bytes from offset 350 in 1.asm directly into the executable. Nice for creating standalone patchers.  :eusa_boohoo:

jj2007

  • Member
  • *****
  • Posts: 10657
  • Assembler is fun ;-)
    • MasmBasic
Re: 64-bit Assemblers
« Reply #23 on: September 15, 2012, 04:33:02 PM »
DB 0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26
DB 27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50
DB 51,52,53,54,55,56,57,58,59,60,61,62,63,64


To do that in Masm, either use the REPEAT directive with CATSTR etc, or (saving executable size) use a combo of lodsb/xchg eax, ecx/lodsb/stosb instructions.

japheth

  • Guest
Re: 64-bit Assemblers
« Reply #24 on: September 15, 2012, 04:48:11 PM »
The times directive is cool

The times directive is just a short form of the repeat directive. It may spare you some key presses, that's all.

The automatic loop counter is elegant, but IMO this concept isn't really assembly-like. The counter incrementation happens "under the hood", which I don't like that much.

Masm already has a preprocessor directive with a "loop variable", it's the FOR directive. It could be very easily extended to format:

Code: [Select]
     for i=0, i < 10, i = i+1
     endm

which is superior to FASM's ability, because a) everything is transparent and b) if the loops are nested, you have full access to all loop variables "on higher levels".

   

CodeDog

  • Guest
Re: 64-bit Assemblers
« Reply #25 on: September 16, 2012, 02:12:15 AM »
Fasm is influenced by pascal syntax maybe that is why. The reason I like fasm is because that guy who wrote it share the same background as myself. He came from Turbo Assembler and Turbo Pascal, and I understand his design philosophies because I had the same view as him. A simplistic approach. I understand him perfectly well that is why I kind of like Fasm so far. But Masm has its place for sure. Even IF I will move to using Fasm, I would not want Masm to disappear.

When I read the fasm docs, I just understand it immediately. Normally if you are trying to learn something new, you go like "Damnit, I just have to take this one step at the time". But with the fasm docs, I'm already adapted to it and understand it, because I agree with it as I read it.

A good designer doesn't try to communicate a complex protocol to random people, a good designer will appeal to his audience and they already understand his protocol.

Abraham Lincoln - 2012

CodeDog

  • Guest
Re: 64-bit Assemblers
« Reply #26 on: September 19, 2012, 10:10:33 PM »
japhet, this does more or less the same as your for loop. And you do have access to the loop variable on "higher level". I just weren't aware of it when you wrote it. You can define as many variables you want in your code, put it anywhere you like and access them, redefine them in the loop, do whatever you want with them.

Code: [Select]
i=0
while i<10
    i=i+1
end while

Here is an example of nested loop:

Code: [Select]
y=0
while y<480
  repeat 640
    stdcall PlotPixel,%-1,y,0FFh
  end repeat
  y=y+1
end while

example using two repeats:

Code: [Select]
y=0
x=0
repeat 480
  repeat 640
    stdcall PlotPixel,x,y,0FFh
    x=x+1
  end repeat
  x=0
  y=y+1
end repeat

I used variables in both repeat just for demonstration purposes. x and y can not only be accessed inside the repeats but also anywhere else in your program. You can define x and y anywhere in your program, then redefine them and put different values into them later. You can even restore it to a previous value, like this:

Code: [Select]
x = 10
mov eax, x
x = 20
mov ecx, x
restore x  <- this restores x back to 10 again

Break when half screen is plotted:

Code: [Select]
y=0
x=0
repeat 480
  repeat 640
    stdcall PlotPixel,x,y,0FFh
    x=x+1
  end repeat
  x=0
  y=y+1
  if y>(480/2)-1
    break
  end if
end repeat

If you want to you can also create your own conditional directives like IF THEN or even a FOR loop. It can be done very easily if you absolutely want the for loop you can design it in a macro.  :P

CodeDog

  • Guest
Re: 64-bit Assemblers
« Reply #27 on: September 20, 2012, 02:07:39 AM »
Another thing I like is the virtual directive. It can be used for many things but one of the things I can think of is producing buffers of opcodes in a buffer that you can put into another process later if you need to

 
Code: [Select]
       virtual at 0
            nop
            nop
            nop
            n2=$
            repeat n2
                   load k% from %-1
            end repeat
        end virtual

        Buf rb 0
        times n2 db k%
        BufSize dd n2
« Last Edit: September 20, 2012, 03:12:50 AM by CodeDog »

japheth

  • Guest
Re: 64-bit Assemblers
« Reply #28 on: September 20, 2012, 02:30:35 AM »
japhet, this does more or less the same as your for loop. And you do have access to the loop variable on "higher level". I just weren't aware of [snip]

You misunderstood my posting ( or didn't read carefully ); I was talking about the automatically generated loop variable which is named %.

CodeDog

  • Guest
Re: 64-bit Assemblers
« Reply #29 on: September 20, 2012, 03:14:26 AM »
japhet, this does more or less the same as your for loop. And you do have access to the loop variable on "higher level". I just weren't aware of [snip]

You misunderstood my posting ( or didn't read carefully ); I was talking about the automatically generated loop variable which is named %.

That automatically generated variable is just a bonus to the flexible constant system fasm offer. There is no rule that says you should use % primarily.  ;)
Constants in fasm offer unlimited flexibility, beyond that of masm. The only thing that piss me off with fasm is that the compiler does not allow floating point calculation during compile-time.  :( If it only supports fpu calculations during compile-time I could create very flexible graphics macros.

Btw, check my previous post, virtual is useful for generating opcodes and later copying it to other parts of your code or into another process. What do you think of it?  :P The virtual directive creates a list of virtually constructed instructions (magical instructions that wont be part of the output) and then load it into constants, then finally put the opcodes into a real buffer defined in the data section. Later you can copy the opcodes to another process.

You can do the same thing in masm too, but normally you would do it by copying opcodes directly from the code section, but in fasm you copy virtual instructions that don't exist in the code section.