flat assembler
Message board for the users of flat assembler.

Index > Macroinstructions > macro problem if numbers.

Author
Thread Post new topic Reply to topic
Roman



Joined: 21 Apr 2012
Posts: 1822
Roman 11 Jul 2022, 17:10
fasmw 1.73
Code:
macro xmover chA,chB,[args,args2] { local .up
      common
      if `chA eq 1
         efff equ al
      else if `chA eq 2
         efff equ ax
      else if `chA eq 4
         efff equ eax
      else if `chA eq 8
         efff equ rax
      end if
      xor ecx,ecx
      forward
.up:  mov efff,[args+rcx]
      mov [args2+rcx],efff
      add ecx,chA
      cmp ecx,chA*chB
      jb  .up
      }            
    

xmover 1,10,rsi,rdi ;get me efff always rax ! But must al
And not work this:
Code:
xmover  1,10,rsi,rdi,r10,r11  ;r10 & r11 ignored    
Post 11 Jul 2022, 17:10
View user's profile Send private message Reply with quote
macomics



Joined: 26 Jan 2021
Posts: 1013
Location: Russia
macomics 11 Jul 2022, 17:49
Code:
macro xmover chA,chB,[src,dst] { common
      if `chA eq "1"
         efff equ al
      else if `chA eq "2"
         efff equ ax
      else if `chA eq "4"
         efff equ eax
      else if `chA eq "8"
         efff equ rax
      end if
      xor ecx,ecx
      forward local .up
.up:  mov efff,[src+rcx]
      mov [dst+rcx],efff
      add ecx,chA
      cmp ecx,chA*chB
      jb  .up
      }    
Post 11 Jul 2022, 17:49
View user's profile Send private message Reply with quote
ProMiNick



Joined: 24 Mar 2012
Posts: 802
Location: Russian Federation, Sochi
ProMiNick 11 Jul 2022, 17:51
assembly if block will never affect on preprocessor equ (reason - stage mixing)
solution? for ex left all assignments & checks to preprocessor stage:
Code:
macro xmover chA,chB,[args,args2] { local .up
      common
        a@1 equ al
        a@2 equ ax
        a@4 equ eax
        a@8 equ rax
         efff equ a@#chA

      xor ecx,ecx
      forward
.up:  mov efff,[args+rcx]
      mov [args2+rcx],efff
      add ecx,chA
      cmp ecx,chA*chB
      jb  .up
      }

xmover 1,10,rsi,rdi
xmover 2,10,rsi,rdi
xmover 4,10,rsi,rdi
xmover 8,10,rsi,rdi    
Post 11 Jul 2022, 17:51
View user's profile Send private message Send e-mail Reply with quote
Roman



Joined: 21 Apr 2012
Posts: 1822
Roman 11 Jul 2022, 19:41
Thanks.
Good solution.
Post 11 Jul 2022, 19:41
View user's profile Send private message Reply with quote
Roman



Joined: 21 Apr 2012
Posts: 1822
Roman 12 Jul 2022, 08:16
Another problem with label .up. Label alredy defined .up.
Code:
macro xmover chA,chB,[args,args2] { ;local .up
      common    
        a@1 equ al
        a@2 equ ax
        a@4 equ eax
        a@8 equ rax
        a@16 equ xmm0

        cmm@1 equ mov
        cmm@2 equ mov
        cmm@4 equ mov
        cmm@8 equ mov
        cmm@16 equ movups

         efff equ a@#chA
         cmm@ equ cmm@#chA
      xor ecx,ecx
.up:
      forward
      cmm@ efff,[args+rcx]
      cmm@ [args2+rcx],efff
      common
      add ecx,chA
      cmp ecx,chA*chB
      jb  .up
      }                
    

;in code
xmover 16,10,rsi,rdi,r10,r11 ;ok
xmover 16,10,rsi,rdi,r12,r13 ;fasm get error .up alredy defined
Post 12 Jul 2022, 08:16
View user's profile Send private message Reply with quote
macomics



Joined: 26 Jan 2021
Posts: 1013
Location: Russia
macomics 12 Jul 2022, 08:38
Code:
format binary
use64
xmover_a@1 equ al
xmover_a@2 equ ax
xmover_a@4 equ eax
xmover_a@8 equ rax
xmover_a@16 equ xmm0
xmover_cmm@1 equ mov
xmover_cmm@2 equ mov
xmover_cmm@4 equ mov
xmover_cmm@8 equ mov
xmover_cmm@16 equ movups

macro xmover chA,chB,[src,dst] { common local .up
        xor ecx,ecx
    .up:
  forward
        xmover_cmm@#chA xmover_a@#chA, [src + rcx]
        xmover_cmm@#chA [dst + rcx], xmover_a@#chA
  common
        add ecx, chA
        cmp ecx, chA * chB
        jb  .up
    }
xmover 16,10,rsi,rdi,r10,r11
xmover 16,10,rsi,rdi,r12,r13
; fasm -m 1024 ./test.asm
; flat assembler  version 1.73.30  (1024 kilobytes memory)
; 1 passes, 63 bytes.
; hexdump -C test.bin
; 00000000  31 c9 0f 10 04 0e 0f 11  04 0f 41 0f 10 04 0a 41  |1.........A....A|
; 00000010  0f 11 04 0b 83 c1 10 81  f9 a0 00 00 00 72 e3 31  |.............r.1|
; 00000020  c9 0f 10 04 0e 0f 11 04  0f 41 0f 10 04 0c 41 0f  |.........A....A.|
; 00000030  11 44 0d 00 83 c1 10 81  f9 a0 00 00 00 72 e2     |.D...........r.|    


Khm. Why cmp ecx, chA * chB = 81 F9 0A 00 00 00, but cmp ecx, 10 = 83 F9 0A?
Post 12 Jul 2022, 08:38
View user's profile Send private message Reply with quote
Roman



Joined: 21 Apr 2012
Posts: 1822
Roman 12 Jul 2022, 11:31
Quote:

Why cmp ecx, chA * chB = 81 F9 0A 00 00 00, but cmp ecx, 10 = 83 F9 0A?

Because xmover forbidden macro Smile
Post 12 Jul 2022, 11:31
View user's profile Send private message Reply with quote
FlierMate1



Joined: 31 May 2022
Posts: 118
FlierMate1 12 Jul 2022, 12:35
macomics wrote:
Why cmp ecx, chA * chB = 81 F9 0A 00 00 00, but cmp ecx, 10 = 83 F9 0A?


Because of the length of the operand?

I too encounter similar instruction encoding:

Code:
5:  05 d2 04 00 00          add    eax,0x4d2
a:  83 c0 02                add    eax,0x2
    


Shorter code for single byte value?
Post 12 Jul 2022, 12:35
View user's profile Send private message Reply with quote
macomics



Joined: 26 Jan 2021
Posts: 1013
Location: Russia
macomics 12 Jul 2022, 12:43
FlierMate1 wrote:
macomics wrote:
Why cmp ecx, chA * chB = 81 F9 0A 00 00 00, but cmp ecx, 10 = 83 F9 0A?


Because of the length of the operand?

I too encounter similar instruction encoding:

Code:
5:  05 d2 04 00 00          add    eax,0x4d2
a:  83 c0 02                add    eax,0x2
    


Shorter code for single byte value?
Both instructions have the same values. The differences are only in the fasm code. When using any constant (defined via = or equ) fasm generates a long instruction instead of a short one.
Post 12 Jul 2022, 12:43
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 20421
Location: In your JS exploiting you and your system
revolution 12 Jul 2022, 18:01
macomics wrote:
Both instructions have the same values.
One is 0xa0, the other is 0x0a.
Post 12 Jul 2022, 18:01
View user's profile Send private message Visit poster's website Reply with quote
macomics



Joined: 26 Jan 2021
Posts: 1013
Location: Russia
macomics 12 Jul 2022, 18:53
revolution wrote:
One is 0xa0, the other is 0x0a.
I was poking around for half an hour, but I didn't notice such a simple reason. Thanks.
Post 12 Jul 2022, 18:53
View user's profile Send private message Reply with quote
FlierMate1



Joined: 31 May 2022
Posts: 118
FlierMate1 12 Jul 2022, 20:50
revolution wrote:
macomics wrote:
Both instructions have the same values.
One is 0xa0, the other is 0x0a.


I paste the two lines of machine code given by @macomics, and both resolved to 0x0a. Maybe I am missing something obvious here?


Description: Machine code & mnemonic code
Filesize: 56.33 KB
Viewed: 5012 Time(s)

Screenshot_20220713-044655_Chrome.jpg


Post 12 Jul 2022, 20:50
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 20421
Location: In your JS exploiting you and your system
revolution 12 Jul 2022, 20:53
macomics wrote:
; 00000010 0f 11 04 0b 83 c1 10 81 f9 a0 00 00 00 72 e3 31 |.............r.1|
https://board.flatassembler.net/topic.php?p=223883#223883
Post 12 Jul 2022, 20:53
View user's profile Send private message Visit poster's website Reply with quote
FlierMate1



Joined: 31 May 2022
Posts: 118
FlierMate1 12 Jul 2022, 20:59
revolution wrote:
macomics wrote:
; 00000010 0f 11 04 0b 83 c1 10 81 f9 a0 00 00 00 72 e3 31 |.............r.1|
https://board.flatassembler.net/topic.php?p=223883#223883


Ahh, I found it, so this is it.

(Thanks for pointing it out)
Post 12 Jul 2022, 20:59
View user's profile Send private message Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  


< 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


Copyright © 1999-2024, Tomasz Grysztar. Also on GitHub, YouTube.

Website powered by rwasa.