flat assembler
Message board for the users of flat assembler.

Index > Main > Search files current directory

Goto page Previous  1, 2
Author
Thread Post new topic Reply to topic
unknown334



Joined: 08 Oct 2021
Posts: 14
unknown334
macomics wrote:
This is all the points when typing in the browser. There is not enough of a bracket closing at the end.
Quote:
b = a shr (( % - 1 ) * 4 )


still doesn't work, let's have a look at it in our spare time, because it has to be debugged at every turn
Post 08 Oct 2021, 15:41
View user's profile Send private message Reply with quote
macomics



Joined: 26 Jan 2021
Posts: 164
Location: Russia
macomics
try it
Code:
; for /F "usebackq" %%I in (`dir /b *.txt`) do ( echo FileName fix "%%~dpnI.tmp" > temp.inc
;  ren %%~fI %%~nI.tmp
;  fasm "%~f0" "%%~fI"
; )
; del temp.inc
; exit /b 0

  format BINARY
  include "temp.inc"
  virtual
    hexdigit::
    db '0123456789ABCDEF'
  end virtual
  virtual at 0
    source::
       file FileName
    txtfile.Length = $
  end virtual
  db '00000000  '
  repeat txtfile.Length
    load a byte from source:(%-1)
    load b byte from hexdigit:a shr 4
    load a byte from hexdigit:a and 15
    db b,a,' '
    if (% and -16 > 0) & (% - 1) and 15 = 15
      a = % - 1 - 15 - 1
      repeat 16
        load b byte from source:a + %
        if b < 32
          db '.'
        else
          db b
        end if
      end repeat
      db 13, 10
      a = %
      repeat 8
        b = a shr ( 32 - % * 4 )
        load b byte from hexdigit:b and 15
        db b
      end repeat
      db '  '
    end if
  end repeat    
Test:
Code:
00000000  20 20 66 6F 72 6D 61 74 20 42 49 4E 41 52 59 0D   format BINARY.
00000010  0A 20 20 46 69 6C 65 4E 61 6D 65 20 66 69 78 20 .  FileName fix 
00000020  22 74 65 73 74 2E 74 78 74 22 0D 0A 20 20 76 69 "test.txt"..  vi
00000030  72 74 75 61 6C 0D 0A 20 20 20 20 68 65 78 64 69 rtual..    hexdi
00000040  67 69 74 3A 3A 0D 0A 20 20 20 20 64 62 20 27 30 git::..    db '0
00000050  31 32 33 34 35 36 37 38 39 41 42 43 44 45 46 27 123456789ABCDEF'
00000060  0D 0A 20 20 65 6E 64 20 76 69 72 74 75 61 6C 0D ..  end virtual.
00000070  0A 20 20 76 69 72 74 75 61 6C 20 61 74 20 30 0D .  virtual at 0.
00000080  0A 20 20 20 20 73 6F 75 72 63 65 3A 3A 0D 0A 20 .    source::.. 
00000090  20 20 20 20 20 20 66 69 6C 65 20 46 69 6C 65 4E       file FileN
000000A0  61 6D 65 0D 0A 20 20 20 20 74 78 74 66 69 6C 65 ame..    txtfile
000000B0  2E 4C 65 6E 67 74 68 20 3D 20 24 0D 0A 20 20 65 .Length = $..  e
000000C0  6E 64 20 76 69 72 74 75 61 6C 0D 0A 20 20 64 62 nd virtual..  db
000000D0  20 27 30 30 30 30 30 30 30 30 20 20 27 0D 0A 20  '00000000  '.. 
000000E0  20 72 65 70 65 61 74 20 74 78 74 66 69 6C 65 2E  repeat txtfile.
000000F0  4C 65 6E 67 74 68 0D 0A 20 20 20 20 6C 6F 61 64 Length..    load
00000100  20 61 20 62 79 74 65 20 66 72 6F 6D 20 73 6F 75  a byte from sou
00000110  72 63 65 3A 28 25 2D 31 29 0D 0A 20 20 20 20 6C rce:(%-1)..    l
00000120  6F 61 64 20 62 20 62 79 74 65 20 66 72 6F 6D 20 oad b byte from 
00000130  68 65 78 64 69 67 69 74 3A 61 20 73 68 72 20 34 hexdigit:a shr 4
00000140  0D 0A 20 20 20 20 6C 6F 61 64 20 61 20 62 79 74 ..    load a byt
00000150  65 20 66 72 6F 6D 20 68 65 78 64 69 67 69 74 3A e from hexdigit:
00000160  61 20 61 6E 64 20 31 35 0D 0A 20 20 20 20 64 62 a and 15..    db
00000170  20 62 2C 61 2C 27 20 27 0D 0A 20 20 20 20 69 66  b,a,' '..    if
00000180  20 28 25 20 61 6E 64 20 2D 31 36 20 3E 20 30 29  (% and -16 > 0)
00000190  20 26 20 28 25 20 61 6E 64 20 31 35 20 3D 20 31  & (% and 15 = 1
000001A0  29 0D 0A 20 20 20 20 20 20 61 20 3D 20 25 20 2D )..      a = % -
000001B0  20 31 20 2D 20 31 36 20 2D 20 31 0D 0A 20 20 20  1 - 16 - 1..   
000001C0  20 20 20 72 65 70 65 61 74 20 31 36 0D 0A 20 20    repeat 16..  
000001D0  20 20 20 20 20 20 6C 6F 61 64 20 62 20 62 79 74       load b byt
000001E0  65 20 66 72 6F 6D 20 73 6F 75 72 63 65 3A 61 20 e from source:a 
000001F0  2B 20 25 0D 0A 20 20 20 20 20 20 20 20 69 66 20 + %..        if 
00000200  62 20 3C 20 33 32 0D 0A 20 20 20 20 20 20 20 20 b < 32..        
00000210  20 20 64 62 20 27 2E 27 0D 0A 20 20 20 20 20 20   db '.'..      
00000220  20 20 65 6C 73 65 0D 0A 20 20 20 20 20 20 20 20   else..        
00000230  20 20 64 62 20 62 0D 0A 20 20 20 20 20 20 20 20   db b..        
00000240  65 6E 64 20 69 66 0D 0A 20 20 20 20 20 20 65 6E end if..      en
00000250  64 20 72 65 70 65 61 74 0D 0A 20 20 20 20 20 20 d repeat..      
00000260  64 62 20 31 33 2C 20 31 30 0D 0A 20 20 20 20 20 db 13, 10..     
00000270  20 61 20 3D 20 25 20 2D 20 31 0D 0A 20 20 20 20  a = % - 1..    
00000280  20 20 72 65 70 65 61 74 20 38 0D 0A 20 20 20 20   repeat 8..    
00000290  20 20 20 20 62 20 3D 20 61 20 73 68 72 20 28 20     b = a shr ( 
000002A0  33 32 20 2D 20 25 20 2A 20 34 20 29 0D 0A 20 20 32 - % * 4 )..  
000002B0  20 20 20 20 20 20 6C 6F 61 64 20 62 20 62 79 74       load b byt
000002C0  65 20 66 72 6F 6D 20 68 65 78 64 69 67 69 74 3A e from hexdigit:
000002D0  62 20 61 6E 64 20 31 35 0D 0A 20 20 20 20 20 20 b and 15..      
000002E0  20 20 64 62 20 62 0D 0A 20 20 20 20 20 20 65 6E   db b..      en
000002F0  64 20 72 65 70 65 61 74 0D 0A 20 20 20 20 20 20 d repeat..      
00000300  64 62 20 27 20 20 27 0D 0A 20 20 20 20 65 6E 64 db '  '..    end
00000310  20 69 66 0D 0A 20 20 65 6E 64 20 72 65 70 65 61  if..  end repea
00000320  74 0D 0A     
Post 08 Oct 2021, 16:04
View user's profile Send private message Reply with quote
unknown334



Joined: 08 Oct 2021
Posts: 14
unknown334
macomics wrote:
try it
Code:
; for /F "usebackq" %%I in (`dir /b *.txt`) do ( echo FileName fix "%%~dpnI.tmp" > temp.inc
;  ren %%~fI %%~nI.tmp
;  fasm "%~f0" "%%~fI"
; )
; del temp.inc
; exit /b 0

  format BINARY
  include "temp.inc"
  virtual
    hexdigit::
    db '0123456789ABCDEF'
  end virtual
  virtual at 0
    source::
       file FileName
    txtfile.Length = $
  end virtual
  db '00000000  '
  repeat txtfile.Length
    load a byte from sourceSad%-1)
    load b byte from hexdigit:a shr 4
    load a byte from hexdigit:a and 15
    db b,a,' '
    if (% and -16 > 0) & (% - 1) and 15 = 15
      a = % - 1 - 15 - 1
      repeat 16
        load b byte from source:a + %
        if b < 32
          db '.'
        else
          db b
        end if
      end repeat
      db 13, 10
      a = %
      repeat 8
        b = a shr ( 32 - % * 4 )
        load b byte from hexdigit:b and 15
        db b
      end repeat
      db '  '
    end if
  end repeat    
Test:
Code:
00000000  20 20 66 6F 72 6D 61 74 20 42 49 4E 41 52 59 0D   format BINARY.
00000010  0A 20 20 46 69 6C 65 4E 61 6D 65 20 66 69 78 20 .  FileName fix 
00000020  22 74 65 73 74 2E 74 78 74 22 0D 0A 20 20 76 69 "test.txt"..  vi
00000030  72 74 75 61 6C 0D 0A 20 20 20 20 68 65 78 64 69 rtual..    hexdi
00000040  67 69 74 3A 3A 0D 0A 20 20 20 20 64 62 20 27 30 git::..    db '0
00000050  31 32 33 34 35 36 37 38 39 41 42 43 44 45 46 27 123456789ABCDEF'
00000060  0D 0A 20 20 65 6E 64 20 76 69 72 74 75 61 6C 0D ..  end virtual.
00000070  0A 20 20 76 69 72 74 75 61 6C 20 61 74 20 30 0D .  virtual at 0.
00000080  0A 20 20 20 20 73 6F 75 72 63 65 3A 3A 0D 0A 20 .    source::.. 
00000090  20 20 20 20 20 20 66 69 6C 65 20 46 69 6C 65 4E       file FileN
000000A0  61 6D 65 0D 0A 20 20 20 20 74 78 74 66 69 6C 65 ame..    txtfile
000000B0  2E 4C 65 6E 67 74 68 20 3D 20 24 0D 0A 20 20 65 .Length = $..  e
000000C0  6E 64 20 76 69 72 74 75 61 6C 0D 0A 20 20 64 62 nd virtual..  db
000000D0  20 27 30 30 30 30 30 30 30 30 20 20 27 0D 0A 20  '00000000  '.. 
000000E0  20 72 65 70 65 61 74 20 74 78 74 66 69 6C 65 2E  repeat txtfile.
000000F0  4C 65 6E 67 74 68 0D 0A 20 20 20 20 6C 6F 61 64 Length..    load
00000100  20 61 20 62 79 74 65 20 66 72 6F 6D 20 73 6F 75  a byte from sou
00000110  72 63 65 3A 28 25 2D 31 29 0D 0A 20 20 20 20 6C rceSad%-1)..    l
00000120  6F 61 64 20 62 20 62 79 74 65 20 66 72 6F 6D 20 oad b byte from 
00000130  68 65 78 64 69 67 69 74 3A 61 20 73 68 72 20 34 hexdigit:a shr 4
00000140  0D 0A 20 20 20 20 6C 6F 61 64 20 61 20 62 79 74 ..    load a byt
00000150  65 20 66 72 6F 6D 20 68 65 78 64 69 67 69 74 3A e from hexdigit:
00000160  61 20 61 6E 64 20 31 35 0D 0A 20 20 20 20 64 62 a and 15..    db
00000170  20 62 2C 61 2C 27 20 27 0D 0A 20 20 20 20 69 66  b,a,' '..    if
00000180  20 28 25 20 61 6E 64 20 2D 31 36 20 3E 20 30 29  (% and -16 > 0)
00000190  20 26 20 28 25 20 61 6E 64 20 31 35 20 3D 20 31  & (% and 15 = 1
000001A0  29 0D 0A 20 20 20 20 20 20 61 20 3D 20 25 20 2D )..      a = % -
000001B0  20 31 20 2D 20 31 36 20 2D 20 31 0D 0A 20 20 20  1 - 16 - 1..   
000001C0  20 20 20 72 65 70 65 61 74 20 31 36 0D 0A 20 20    repeat 16..  
000001D0  20 20 20 20 20 20 6C 6F 61 64 20 62 20 62 79 74       load b byt
000001E0  65 20 66 72 6F 6D 20 73 6F 75 72 63 65 3A 61 20 e from source:a 
000001F0  2B 20 25 0D 0A 20 20 20 20 20 20 20 20 69 66 20 + %..        if 
00000200  62 20 3C 20 33 32 0D 0A 20 20 20 20 20 20 20 20 b < 32..        
00000210  20 20 64 62 20 27 2E 27 0D 0A 20 20 20 20 20 20   db '.'..      
00000220  20 20 65 6C 73 65 0D 0A 20 20 20 20 20 20 20 20   else..        
00000230  20 20 64 62 20 62 0D 0A 20 20 20 20 20 20 20 20   db b..        
00000240  65 6E 64 20 69 66 0D 0A 20 20 20 20 20 20 65 6E end if..      en
00000250  64 20 72 65 70 65 61 74 0D 0A 20 20 20 20 20 20 d repeat..      
00000260  64 62 20 31 33 2C 20 31 30 0D 0A 20 20 20 20 20 db 13, 10..     
00000270  20 61 20 3D 20 25 20 2D 20 31 0D 0A 20 20 20 20  a = % - 1..    
00000280  20 20 72 65 70 65 61 74 20 38 0D 0A 20 20 20 20   repeat 8..    
00000290  20 20 20 20 62 20 3D 20 61 20 73 68 72 20 28 20     b = a shr ( 
000002A0  33 32 20 2D 20 25 20 2A 20 34 20 29 0D 0A 20 20 32 - % * 4 )..  
000002B0  20 20 20 20 20 20 6C 6F 61 64 20 62 20 62 79 74       load b byt
000002C0  65 20 66 72 6F 6D 20 68 65 78 64 69 67 69 74 3A e from hexdigit:
000002D0  62 20 61 6E 64 20 31 35 0D 0A 20 20 20 20 20 20 b and 15..      
000002E0  20 20 64 62 20 62 0D 0A 20 20 20 20 20 20 65 6E   db b..      en
000002F0  64 20 72 65 70 65 61 74 0D 0A 20 20 20 20 20 20 d repeat..      
00000300  64 62 20 27 20 20 27 0D 0A 20 20 20 20 65 6E 64 db '  '..    end
00000310  20 69 66 0D 0A 20 20 65 6E 64 20 72 65 70 65 61  if..  end repea
00000320  74 0D 0A     


It works Smile Thank you very much.
Post 08 Oct 2021, 16:19
View user's profile Send private message Reply with quote
macomics



Joined: 26 Jan 2021
Posts: 164
Location: Russia
macomics
For the sake of understanding, I clarify. This is not a fasm program. The macrolanguage of the compiler is engaged in the translation of the text and it is fasm that writes the result in the form of a hexadecimal representation to the file. Thus, the above text is a script, not a program!
To write a program for Windows OS, you need to decide whether you need a 32-bit version or a 64-bit version of the program.
Although in general, I gave the sequence of calls to the operating system functions in the post above.
Post 08 Oct 2021, 16:28
View user's profile Send private message Reply with quote
unknown334



Joined: 08 Oct 2021
Posts: 14
unknown334
macomics wrote:
For the sake of understanding, I clarify. This is not a fasm program. The macrolanguage of the compiler is engaged in the translation of the text and it is fasm that writes the result in the form of a hexadecimal representation to the file. Thus, the above text is a script, not a program!
To write a program for Windows OS, you need to decide whether you need a 32-bit version or a 64-bit version of the program.
Although in general, I gave the sequence of calls to the operating system functions in the post above.


Ideally I need both 32-bit and 64-bit Windows
at the very best on linux

If anyone can help, I would be very grateful.
Post 08 Oct 2021, 16:42
View user's profile Send private message Reply with quote
macomics



Joined: 26 Jan 2021
Posts: 164
Location: Russia
macomics
Now I'm going home on the train and writing this (and checking) on a tablet with Linux Ubuntu installed. Running a Windows VM on it without a Bluetooth mouse is a insult to the brain. That's why I didn't check the batch script. But running fasm for testing is quite acceptable. So this script also works on Linux.
Post 08 Oct 2021, 16:52
View user's profile Send private message Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  
Goto page Previous  1, 2

< 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-2020, Tomasz Grysztar. Also on GitHub, YouTube, Twitter.

Website powered by rwasa.