Re: Macro2D




"Rosario" <x@xxx> ha scritto nel messaggio
news:48ce2116$0$1092$4fafbaef@xxxxxxxxxxxxxxxxxxxxxx
Whith this post there is the directory Macro2D.zip
that has the file Macro2D.exe that it seems the zip
form has the "CRC32" == 63367343
it is my macro language traslater to assembly nasm
finished just now.
It will be full of bug, I hope that not cause too many
damages...
I hope someone use it good.

How many bug or errors you can see?
Have you some suggestion?
Buon Giorno a tutti
Rosario

because someone want see if there is some virus
this is the nasm traslation

[hope it is not much long]

----------------------------------
section _DATA use32 public class=DATA

; d4 -obj a
; alink -oPE -subsys con a.obj win32.lib
; per oPE linkato come console

global _main


global Isreg, Riscrivi, Hash, SeeTab, InstallGenerali, FreeTab
global InstallNasm, FreeMem, DCmp, DCopy, FindMacroWord
global FindMacro, AtoI, Installl, Install, FreeNodo
global AllocNodo, Undef
global CopyString, CopyPseudoString
global IsComment, IsLabel, combine, Next_ch, First_ch
global ScriviParola, ScriviB2, ToNasm
global CopyUntil10Or0_jki, LineToNasm, ProvaToNasm
global Next_ch1, First_ch1, AsmMain
global PrendiNomeDa_i, LevaSpaziDa_i, PrendiNomeTraVirgoletteDa_i
global PrendiNomeTraSpaziDa_i, Free_sys, Malloc_sys, MacroNasm
global HashWord, Lookup, CatStr, FaiObj, FaiPe, FaiConsole
global ConvertiNumeriTavola, sposta, GetStdIo, AppendPointName
global PrendiArgomenti, PrintError, FindLastPoint_i
global SPuts, LenStr_i, SGetLine
global PrendiWord_jki, PrendiWordTraSpazi_jki
global FindEndNextWordTraSpazi_i, WordLen_i, LenStr_i
global WordLenTraSpazi_i, FindNextWord_i, FindNextWordTraSPazi_i
global InstalMacro, PushMacro, FreeIfFindAddressInString
global UndefMacro, PopMacro, ProvaFunzioni, Copy_jki
global CopyLine_jki, FlushCloseHandle, Find, VaiUntil10Or0_i
global FindData_i, FindCode_i, FindCarattereFromEnd
global AssegnaVettori, GetData_jki, InterattivoNasm
global LineToRosAsm, InstallRos
global HaLaLineaQualcheParola_i, IsNextWordLabel_i
global FromNasmToRos, AssegnaVettoriIstruzione
global MacroRosAsm, ScriviChi

extern VirtualAlloc
extern VirtualFree
extern CreateFileA
extern CloseHandle
extern ReadFile
extern WriteFile
extern GetCommandLineA
extern GetFileSize
extern GetStdHandle
extern AllocConsole
extern FreeConsole
extern GetConsoleScreenBufferInfo
extern GetExitCodeProcess
extern GetStartupInfoA
extern CreateProcessA
extern WaitForSingleObject
extern FormatMessageA
extern GetLastError
extern FlushFileBuffers
extern GetTickCount

;*
; %define VirtualAlloc 'kernel32.VirtualAlloc'
; %define VirtualFree 'kernel32.VirtualFree'
; %define CreateFileA 'kernel32.CreateFileA'
; %define CloseHandle 'kernel32.CloseHandle'
; %define ReadFile 'kernel32.ReadFile'
; %define WriteFile 'kernel32.WriteFile'
; %define GetCommandLineA 'kernel32.GetCommandLineA'
; %define GetFileSize 'kernel32.GetFileSize'
; %define GetStdHandle 'kernel32.GetStdHandle'
; %define AllocConsole 'kernel32.AllocConsole'
; %define FreeConsole 'kernel32.FreeConsole'
; %define GetConsoleScreenBufferInfo 'kernel32.GetConsoleScreenBufferInfo'
; %define GetExitCodeProcess 'kernel32.GetExitCodeProcess'
; %define GetStartupInfoA 'kernel32.GetStartupInfoA'
; %define CreateProcessA 'kernel32.CreateProcessA'
; %define WaitForSingleObject 'kernel32.WaitForSingleObject'
; %define FormatMessageA 'kernel32.FormatMessageA'

; %define GetLastError 'kernel32.GetLastError'
; %define FlushFileBuffers 'kernel32.FlushFileBuffers'
; %define GetTickCount 'kernel32.GetTickCount'
;*

%define MEM_COMMIT 01000h
%define MEM_RESERVE 02000h
%define MEM_RELEASE 08000h
%define PAGE_READWRITE 00004h

%define GENERIC_READ 080000000h
%define GENERIC_WRITE 040000000h
%define FILE_ATTRIBUTE_NORMAL 000000080h
%define OPEN_EXISTING 000000003h
%define CREATE_ALWAYS 000000002h
%define INVALID_HANDLE_VALUE 0FFFFFFFFh
%define IVA_ 0FFFFFFFFh


%define STD_ERROR_HANDLE 0FFFFFFF4h
%define STD_INPUT_HANDLE 0FFFFFFF6h
%define STD_OUTPUT_HANDLE 0FFFFFFF5h



%define Space 6
%define Punti 9
%define EOI 5


%define HASHSIZE 4019

hashtab dd 0

TheNext dd 0
NodeMem dd 0

MacroDefinizioniGeneraliLed dd 0
NasmDefLed dd 0
RosAsmDefLed dd 0

PointerSize dd 0
TheNextPointer dd 0
StringPointers dd 0

stdin dd -1
stdout dd -1
stderr dd -1

consoley dd 1024
consolex dd 80

BufInfo: times 20 dd 0
; dwSize.x: dw 0
; dwSize.y: dw 0
; dwCursorPosition.x: dw 0
; dwCursorPosition.y: dw 0
; wAttributes: dw 0
; srWindow.Left: dw 0
; srWindow.Top: dw 0
; srWindow.Right: dw 0
; srWindow.Bottom: dw 0
; dwMaximumWindowSize.x: dw 0
; dwMaximumWindowSize.y: dw 0
; 2*11=22 24/4=6

StartInfo: times 20 dd 0

; typedef struct _STARTUPINFO { // si
; 4 DWORD cb;
; 4 LPTSTR lpReserved;
; 4 LPTSTR lpDesktop;
; 4 LPTSTR lpTitle;
; 4 DWORD dwX;
; 4 DWORD dwY;
; 4 DWORD dwXSize;
; 4 DWORD dwYSize;
; 4 DWORD dwXCountChars;
; 4 DWORD dwYCountChars;
; 4 DWORD dwFillAttribute;
; 4 DWORD dwFlags;
; 2 WORD wShowWindow;
; 2 WORD cbReserved2;
; 4 LPBYTE lpReserved2;
; 4 HANDLE hStdInput;
; 4 HANDLE hStdOutput;
; 4 HANDLE hStdError;
;} STARTUPINFO, *LPSTARTUPINFO;



ProcInfo: dd 0, 0, 0, 0, 0, 0
;typedef struct _PROCESS_INFORMATION { // pi
; HANDLE hProcess;
; HANDLE hThread;
; DWORD dwProcessId;
; DWORD dwThreadId;
;} PROCESS_INFORMATION;


; numeri decimali 0x0
; numeri hex non decimali 0x1
; altre lettere dell'alfabeto + "_" 0x2
; "@" "$" "%" 0x3 [alfanumerico <=3]
; EOI 0x5
; spazi 0x6
; punti 0x9

TempoA dd 0, 0

%define Space 6
%define Punti 9
%define EOI 5

; 0, 1, 2, 3, 4, 5, 6, 7, 8, 9
MyTable:
db 5, 16, 16, 16, 16, 16, 16, 16, 16, 6 ; 0
db 5, 16, 16, 16, 16, 16, 16, 16, 16, 16 ; 1 10 e' fine input non spazio
db 16, 16, 16, 16, 16, 16, 16, 16, 16, 16 ; 2
db 16, 16, 6, 9, 16, 9, 3, 3, 9, 16 ; 3
db 9, 9, 9, 9, 9, 9, 2, 16, 0, 0 ; 4 "." e' lettera
db 0, 0, 0, 0, 0, 0, 0, 0, 16, 16 ; 5
db 9, 9, 9, 9, 3, 1, 1, 1, 1, 1 ; 6
db 1, 2, 2, 2, 2, 2, 2, 2, 2, 2 ; 7
db 2, 2, 2, 2, 2, 2, 2, 2, 2, 2 ; 8
db 2, 16, 16, 16, 9, 2, 16, 1, 1, 1 ; 9
db 1, 1, 1, 2, 2, 2, 2, 2, 2, 2 ; 10
db 2, 2, 2, 2, 2, 2, 2, 2, 2, 2 ; 11
db 2, 2, 2, 16, 9, 16, 16, 16, 16, 16 ; 12
db 16, 16, 16, 16, 16, 16, 16, 16, 16, 16 ; 13
db 16, 16, 16, 16, 16, 16, 16, 16, 16, 16 ; 14
db 16, 16, 16, 16, 16, 16, 16, 16, 16, 16 ; 15
db 16, 16, 16, 16, 16, 16, 16, 16, 16, 16 ; 16
db 16, 16, 16, 16, 16, 16, 16, 16, 16, 16 ; 17
db 16, 16, 16, 16, 16, 16, 16, 16, 16, 16 ; 18
db 16, 16, 16, 16, 16, 16, 16, 16, 16, 16 ; 19
db 16, 16, 16, 16, 16, 16, 16, 16, 16, 16 ; 20
db 16, 16, 16, 16, 16, 16, 16, 16, 16, 16 ; 21
db 16, 16, 16, 16, 16, 16, 16, 16, 16, 16 ; 22
db 16, 16, 16, 16, 16, 16, 16, 16, 16, 16 ; 23
db 16, 16, 16, 16, 16, 16, 16, 16, 16, 16 ; 24
db 16, 16, 16, 16, 16, 16, 0, 0, 0, 0 ; 25

; 0, 1, 2, 3, 4, 5, 6, 7, 8, 9
MyTableR:
db 5, 16, 16, 16, 16, 16, 16, 16, 16, 6 ; 0
db 12, 16, 16, 12, 16, 16, 16, 16, 16, 16 ; 1 10 e' fine input non spazio
db 16, 16, 16, 16, 16, 16, 16, 16, 16, 16 ; 2
db 16, 16, 6, 9, 10, 9, 0, 0, 9, 10 ; 3
db 9, 9, 9, 9, 9, 9, 0, 16, 0, 0 ; 4 "." e' lettera
db 0, 0, 0, 0, 0, 0, 0, 0, 10, 10 ; 5
db 9, 9, 9, 9, 0, 0, 0, 0, 0, 0 ; 6
db 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ; 7
db 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ; 8
db 0, 11, 10, 11, 9, 0, 10, 0, 0, 0 ; 9
db 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ; 10
db 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ; 11
db 0, 0, 0, 11, 9, 11, 10, 16, 16, 16 ; 12
db 16, 16, 16, 16, 16, 16, 16, 16, 16, 16 ; 13
db 16, 16, 16, 16, 16, 16, 16, 16, 16, 16 ; 14
db 16, 16, 16, 16, 16, 16, 16, 16, 16, 16 ; 15
db 16, 16, 16, 16, 16, 16, 16, 16, 16, 16 ; 16
db 16, 16, 16, 16, 16, 16, 16, 16, 16, 16 ; 17
db 16, 16, 16, 16, 16, 16, 16, 16, 16, 16 ; 18
db 16, 16, 16, 16, 16, 16, 16, 16, 16, 16 ; 19
db 16, 16, 16, 16, 16, 16, 16, 16, 16, 16 ; 20
db 16, 16, 16, 16, 16, 16, 16, 16, 16, 16 ; 21
db 16, 16, 16, 16, 16, 16, 16, 16, 16, 16 ; 22
db 16, 16, 16, 16, 16, 16, 16, 16, 16, 16 ; 23
db 16, 16, 16, 16, 16, 16, 16, 16, 16, 16 ; 24
db 16, 16, 16, 16, 16, 16, 0, 0, 0, 0 ; 25

IIIsIIuI db "[%s]%u|" , 0
IQuestaIeIIlaIhelp db "Questa e' la help" , 0

IIPremiIInII db "<Premi \n> " , 0, 0

; PiccoloBuffer times 64 db 0


; point to next:nx puntatore
; name:nm nome
; defn:df definizione
; defnlen:dfl lenDefinizione
; << nx=0, nm=4, df=8, dfl=12

MacroDefinizioniGenerali:
db "a" , 0, "eax" , 0
db "b" , 0, "ebx" , 0
db "c" , 0, "ecx" , 0
db "jx" , 0, "di" , 0
db "i" , 0, "esi" , 0
db "j" , 0, "edi" , 0
db "ix" , 0, "si" , 0
db "r" , 0, "edx" , 0
db "rx" , 0, "dx" , 0
db "rl" , 0, "dl" , 0
db "rh" , 0, "dh" , 0
db "s" , 0, "esp" , 0
db "sx" , 0, "sp" , 0
db "k" , 0, "ebp" , 0
db "kx" , 0, "bp" , 0
; 15

db "##õ1" , 0, "jmp õ1" , 0
db "õ1=õ2" , 0, "mov õ1, õ2" , 0
db "õ1+=õ2" , 0, "add õ1, õ2" , 0
db "õ1-=õ2" , 0, "sub õ1, õ2" , 0
db "õ1++=õ2" , 0, "adc õ1, õ2" , 0
db "õ1--=õ2" , 0, "sbb õ1, õ2" , 0
db "õ1<->õ2" , 0, "xchg õ1, õ2" , 0

db "õ1<<=õ2" , 0, "shl õ1, õ2" , 0
db "õ1>>=õ2" , 0, "shr õ1, õ2" , 0
db "õ1<<<=õ2" , 0, "rcl õ1, õ2" , 0
db "õ1>>>=õ2" , 0, "rcr õ1, õ2" , 0
db "õ1&õ2" , 0, "test õ1, õ2" , 0
db "õ1=&õ2" , 0, "lea õ1, õ2" , 0
db "õ1&=õ2" , 0, "and õ1, õ2" , 0
db "õ1|=õ2" , 0, "or õ1, õ2" , 0
db "õ1^=õ2" , 0, "xor õ1, õ2" , 0

;----------- db "õ1=*õ2" ,0, "mov õ1, [õ2]", 0

db "<õ1" , 0, "push õ1" , 0
; 35
db ">õ1" , 0, "pop õ1" , 0
db "õ1()" , 0, "call õ1" , 0
; 37
db "<õ1,õ2" , 0, "push õ1 |push õ2" , 0
db ">õ1,õ2" , 0, "pop õ2 |pop õ1" , 0

db "<õ1,õ2,õ3" , 0, "push õ1 |push õ2 |push õ3" , 0
db ">õ1,õ2,õ3" , 0, "pop õ3 |pop õ2 |pop õ1" , 0

db "<õ1,õ2,õ3,õ4" , 0, "push õ1 |push õ2 |push õ3 |push õ4" , 0
db ">õ1,õ2,õ3,õ4" , 0, "pop õ4 |pop õ3 |pop õ2 |pop õ1" , 0

db "<õ1,õ2,õ3,õ4,õ5" , 0, "push õ1 |push õ2 |push õ3 |push õ4 |push õ5"
, 0
db ">õ1,õ2,õ3,õ4,õ5" , 0, "pop õ5 |pop õ4 |pop õ3 |pop õ2 |pop õ1"
, 0

db "<õ1,õ2,õ3,õ4,õ5,õ6" , 0
db "push õ1 |push õ2 |push õ3 |push õ4 |push õ5 |push õ6" , 0

db ">õ1,õ2,õ3,õ4,õ5,õ6" , 0
db "pop õ6 |pop õ5 |pop õ4 |pop õ3 |pop õ2 |pop õ1" , 0

db "<õ1,õ2,õ3,õ4,õ5,õ6,õ7" , 0
db "push õ1 |push õ2 |push õ3 |push õ4 |push õ5 |push õ6 |push õ7" ,
0

db ">õ1,õ2,õ3,õ4,õ5,õ6,õ7" , 0
db "pop õ7 |pop õ6 |pop õ5 |pop õ4 |pop õ3 |pop õ2 |pop õ1" ,
0

db "<õ1,õ2,õ3,õ4,õ5,õ6,õ7,õ8" , 0
db "push õ1 |push õ2 |push õ3 |push õ4 |push õ5 |push õ6 |push õ7
|push õ8" , 0

db ">õ1,õ2,õ3,õ4,õ5,õ6,õ7,õ8" , 0
db "pop õ8 |pop õ7 |pop õ6 |pop õ5 |pop õ4 |pop õ3 |pop õ2
|pop õ1" , 0
; 51

;------------------------------------------*/
db "õ1=õ2()" , 0, "call õ2 |mov õ1, eax" , 0
db "õ1(õ2)" , 0, "push õ2 |call õ1" , 0

db "õ1=õ2(õ3)" , 0, "push õ3 |call õ2 |mov õ1, eax" , 0
db "õ1<(õ2)" , 0, "push õ2 |call õ1 |add esp, 4" , 0

db "õ1=õ2<(õ3)" , 0
db "push õ3 |call õ2 |add esp, 4 |mov õ1, eax" , 0
; 56
db "õ1(õ2,õ3)" , 0
db "push õ3 |push õ2 |call õ1" , 0

db "õ1=õ2(õ3,õ4)" , 0
db "push õ4 |push õ3 |call õ2 |mov õ1, eax" , 0

db "õ1<(õ2,õ3)" , 0
db "push õ3 |push õ2 |call õ1 |add esp, 8" , 0

db "õ1=õ2<(õ3,õ4)" , 0
db "push õ4 |push õ3 |call õ2 |add esp, 8 |mov õ1, eax" , 0

db "õ1(õ2,õ3,õ4)" , 0
db "push õ4 |push õ3 |push õ2 |call õ1" , 0

db "õ1=õ2(õ3,õ4,õ5)" , 0
db "push õ5 |push õ4 |push õ3 |call õ2 |mov õ1, eax" , 0

db "õ1<(õ2,õ3,õ4)" , 0
db "push õ4 |push õ3 |push õ2 |call õ1 |add esp, 12" , 0

db "õ1=õ2<(õ3,õ4,õ5)" , 0
db "push õ5 |push õ4 |push õ3 |call õ2 |add esp, 12 |mov õ1, eax"
, 0

db "õ1(õ2,õ3,õ4,õ5)" , 0
db "push õ5 |push õ4 |push õ3 |push õ2 |call õ1" , 0

db "õ1=õ2(õ3,õ4,õ5,õ6)" , 0
db "push õ6 |push õ5 |push õ4 |push õ3 |call õ2 |mov õ1, eax" , 0
; 66
db "õ1<(õ2,õ3,õ4,õ5)" , 0
db "push õ5 |push õ4 |push õ3 |push õ2 |call õ1 |add esp, 16" , 0

db "õ1=õ2<(õ3,õ4,õ5,õ6)" , 0
db "push õ6 |push õ5 |push õ4 |push õ3 |call õ2 |add esp, 16 |mov
õ1, eax" , 0

db "õ1(õ2,õ3,õ4,õ5,õ6)" , 0
db "push õ6 |push õ5 |push õ4 |push õ3 |push õ2 |call õ1" , 0

db "õ1=õ2(õ3,õ4,õ5,õ6,õ7)" , 0
db "push õ7 |push õ6 |push õ5 |push õ4 |push õ3 |call õ2 |mov õ1,
eax" , 0

db "õ1<(õ2,õ3,õ4,õ5,õ6)" , 0
db "push õ6 |push õ5 |push õ4 |push õ3 |push õ2 |call õ1 |add esp,
20" , 0

db "õ1=õ2<(õ3,õ4,õ5,õ6,õ7)" , 0
db "push õ7 |push õ6 |push õ5 |push õ4 |push õ3 |call õ2 |add esp,
20 |mov õ1, eax" , 0

db "õ1(õ2,õ3,õ4,õ5,õ6,õ7)" , 0
db "push õ7 |push õ6 |push õ5 |push õ4 |push õ3 |push õ2 |call õ1" ,
0

db "õ1=õ2(õ3,õ4,õ5,õ6,õ7,õ8)" , 0
db "push õ8 |push õ7 |push õ6 |push õ5 |push õ4 |push õ3 |call õ2
|mov õ1, eax" , 0

db "õ1<(õ2,õ3,õ4,õ5,õ6,õ7)" , 0
db "push õ7 |push õ6 |push õ5 |push õ4 |push õ3 |push õ2 |call õ1
|add esp, 24" , 0

db "õ1=õ2<(õ3,õ4,õ5,õ6,õ7,õ8)" , 0
db "push õ8 |push õ7 |push õ6 |push õ5 |push õ4 |push õ3 |call õ2
|add esp, 24 |mov õ1, eax" , 0
; 76
db "õ1(õ2,õ3,õ4,õ5,õ6,õ7,õ8)" , 0
db "push õ8 |push õ7 |push õ6 |push õ5 |push õ4 |push õ3 |push õ2
|call õ1" , 0

db "õ1=õ2(õ3,õ4,õ5,õ6,õ7,õ8,õ9)" , 0
db "push õ9 |push õ8 |push õ7 |push õ6 |push õ5 |push õ4 |push õ3
|call õ2 |mov õ1, eax" , 0

db "õ1<(õ2,õ3,õ4,õ5,õ6,õ7,õ8)" , 0
db "push õ8 |push õ7 |push õ6 |push õ5 |push õ4 |push õ3 |push õ2
|call õ1 |add esp, 28" , 0

db "õ1=õ2<(õ3,õ4,õ5,õ6,õ7,õ8,õ9)" , 0
db "push õ9 |push õ8 |push õ7 |push õ6 |push õ5 |push õ4 |push õ3
|call õ2 |add esp, 28 |mov õ1, eax" , 0

db "õ1(õ2,õ3,õ4,õ5,õ6,õ7,õ8,õ9)" , 0
db "push õ9 |push õ8 |push õ7 |push õ6 |push õ5 |push õ4 |push õ3
|push õ2 |call õ1" , 0

db "õ1=õ2(õ3,õ4,õ5,õ6,õ7,õ8,õ9,õ10)" , 0
db "push õ10 |push õ9 |push õ8 |push õ7 |push õ6 |push õ5 |push õ4
|push õ3 |call õ2 |mov õ1, eax" , 0

db "õ1<(õ2,õ3,õ4,õ5,õ6,õ7,õ8,õ9)" , 0
db "push õ9 |push õ8 |push õ7 |push õ6 |push õ5 |push õ4 |push õ3
|push õ2 |call õ1 |add esp, 32" , 0

db "õ1=õ2<(õ3,õ4,õ5,õ6,õ7,õ8,õ9,õ10)" , 0
db "push õ10 |push õ9 |push õ8 |push õ7 |push õ6 |push õ5 |push õ4
|push õ3 |call õ2 |add esp, 32 |mov õ1, eax" , 0

db "õ1(õ2,õ3,õ4,õ5,õ6,õ7,õ8,õ9,õ10)" , 0
db "push õ10 |push õ9 |push õ8 |push õ7 |push õ6 |push õ5 |push õ4
|push õ3 |push õ2 |call õ1" , 0

db "õ1=õ2(õ3,õ4,õ5,õ6,õ7,õ8,õ9,õ10,õ11)" , 0
db "push õ11 |push õ10 |push õ9 |push õ8 |push õ7 |push õ6 |push õ5
|push õ4 |push õ3 |call õ2 |mov õ1, eax" , 0
; 86
db "õ1<(õ2,õ3,õ4,õ5,õ6,õ7,õ8,õ9,õ10)" , 0
db "push õ10 |push õ9 |push õ8 |push õ7 |push õ6 |push õ5 |push õ4
|push õ3 |push õ2 |call õ1 |add esp, 36" , 0

db "õ1=õ2<(õ3,õ4,õ5,õ6,õ7,õ8,õ9,õ10,õ11)" , 0
db "push õ11 |push õ10 |push õ9 |push õ8 |push õ7 |push õ6 |push õ5
|push õ4 |push õ3 |call õ2 |add esp, 36 |mov õ1, eax" , 0
;--------------taglio

db "õ1(õ2,õ3,õ4,õ5,õ6,õ7,õ8,õ9,õ10,õ11)" , 0
db "push õ11 |push õ10 |push õ9 |push õ8 |push õ7 |push õ6 |push õ5
|push õ4 |push õ3 |push õ2 |call õ1" , 0

; ------------taglio

db "õ1=õ2(õ3,õ4,õ5,õ6,õ7,õ8,õ9,õ10,õ11,õ12)" , 0
db "push õ12 |push õ11 |push õ10 |push õ9 |push õ8 |push õ7 |push õ6
|push õ5 |push õ4 |push õ3 |call õ2 |mov õ1, eax" , 0

db "õ1<(õ2,õ3,õ4,õ5,õ6,õ7,õ8,õ9,õ10,õ11)" , 0
db "push õ11 |push õ10 |push õ9 |push õ8 |push õ7 |push õ6 |push õ5
|push õ4 |push õ3 |push õ2 |call õ1 |add esp, 40" , 0

db "õ1=õ2<(õ3,õ4,õ5,õ6,õ7,õ8,õ9,õ10,õ11,õ12)" , 0
db "push õ12 |push õ11 |push õ10 |push õ9 |push õ8 |push õ7 |push õ6
|push õ5 |push õ4 |push õ3 |call õ2 |add esp, 40 |mov õ1, eax" , 0

db "õ1(õ2,õ3,õ4,õ5,õ6,õ7,õ8,õ9,õ10,õ11,õ12)" , 0
db "push õ12 |push õ11 |push õ10 |push õ9 |push õ8 |push õ7 |push õ6
|push õ5 |push õ4 |push õ3 |push õ2 |call õ1" , 0

db "õ1=õ2(õ3,õ4,õ5,õ6,õ7,õ8,õ9,õ10,õ11,õ12,õ13)" , 0
db "push õ13 |push õ12 |push õ11 |push õ10 |push õ9 |push õ8 |push õ7
|push õ6 |push õ5 |push õ4 |push õ3 |call õ2 |mov õ1, eax" , 0

db "õ1<(õ2,õ3,õ4,õ5,õ6,õ7,õ8,õ9,õ10,õ11,õ12)" , 0
db "push õ12 |push õ11 |push õ10 |push õ9 |push õ8 |push õ7 |push õ6
|push õ5 |push õ4 |push õ3 |push õ2 |call õ1 |add esp, 44" , 0

db "õ1=õ2<(õ3,õ4,õ5,õ6,õ7,õ8,õ9,õ10,õ11,õ12,õ13)" , 0
db "push õ13 |push õ12 |push õ11 |push õ10 |push õ9 |push õ8 |push õ7
|push õ6 |push õ5 |push õ4 |push õ3 |call õ2 |add esp, 44 |mov õ1,
eax" , 0
; 96

db "õ1(õ2,õ3,õ4,õ5,õ6,õ7,õ8,õ9,õ10,õ11,õ12,õ13)" , 0
db "push õ13 |push õ12 |push õ11 |push õ10 |push õ9 |push õ8 |push õ7
|push õ6 |push õ5 |push õ4 |push õ3 |push õ2 |call õ1" , 0

db "õ1=õ2(õ3,õ4,õ5,õ6,õ7,õ8,õ9,õ10,õ11,õ12,õ13,õ14)" , 0
db "push õ14 |push õ13 |push õ12 |push õ11 |push õ10 |push õ9 |push
õ8 |push õ7 |push õ6 |push õ5 |push õ4 |push õ3 |call õ2 |mov õ1,
eax" , 0

db "õ1<(õ2,õ3,õ4,õ5,õ6,õ7,õ8,õ9,õ10,õ11,õ12,õ13)" , 0
db "push õ13 |push õ12 |push õ11 |push õ10 |push õ9 |push õ8 |push õ7
|push õ6 |push õ5 |push õ4 |push õ3 |push õ2 |call õ1 |add esp, 48"
, 0

db "õ1=õ2<(õ3,õ4,õ5,õ6,õ7,õ8,õ9,õ10,õ11,õ12,õ13,õ14)" , 0
db "push õ14 |push õ13 |push õ12 |push õ11 |push õ10 |push õ9 |push
õ8 |push õ7 |push õ6 |push õ5 |push õ4 |push õ3 |call õ2 |add esp,
48 |mov õ1, eax" , 0

;100

;------------------------------------------*/

db "++õ1" , 0, "inc õ1" , 0
db "--õ1" , 0, "dec õ1" , 0 ; --[a+si]

db "++õ1,õ2" , 0, "inc õ1 |inc õ2" , 0
db "--õ1,õ2" , 0, "dec õ1 |dec õ2" , 0

db "++õ1,õ2,õ3" , 0
db "inc õ1 |inc õ2 |inc õ3" , 0

db "--õ1,õ2,õ3" , 0
db "dec õ1 |dec õ2 |dec õ3" , 0
; 106
db "++õ1,õ2,õ3,õ4" , 0
db "inc õ1 |inc õ2 |inc õ3 |inc õ4" , 0

db "--õ1,õ2,õ3,õ4" , 0
db "dec õ1 |dec õ2 |dec õ3 |dec õ4" , 0

db "--õ1#õ2" , 0, "dec õ1 |jnz õ2" , 0
db "--õ1!#õ2" , 0, "dec õ1 |jz õ2" , 0
db "++õ1#õ2" , 0, "inc õ1 |jnz õ2" , 0
db "++õ1!#õ2" , 0, "inc õ1 |jz õ2" , 0
db "õ1<>õ2" , 0, "cmp õ1, õ2" , 0
db "õ1#õ2" , 0, "cmp õ1, 0 |jne õ2" , 0
db "õ1!#õ2" , 0, "cmp õ1, 0 |je õ2" , 0
db "õ1<õ2#õ3" , 0, "cmp õ1, õ2 |jb õ3" , 0 ; numeri senza segno
; 116
db "õ1&õ2#õ3" , 0, "test õ1, õ2 |jnz õ3" , 0
db "õ1>õ2#õ3" , 0, "cmp õ1, õ2 |ja õ3" , 0
db "õ1<=õ2#õ3" , 0, "cmp õ1, õ2 |jbe õ3" , 0
db "õ1>=õ2#õ3" , 0, "cmp õ1, õ2 |jae õ3" , 0
db "õ1==õ2#õ3" , 0, "cmp õ1, õ2 |je õ3" , 0
db "õ1!=õ2#õ3" , 0, "cmp õ1, õ2 |jne õ3" , 0
db "õ1>=õ2!#õ3" , 0, "cmp õ1, õ2 |jb õ3" , 0
db "õ1<=õ2!#õ3" , 0, "cmp õ1, õ2 |ja õ3" , 0
db "õ1>õ2!#õ3" , 0, "cmp õ1, õ2 |jbe õ3" , 0
db "õ1&õ2!#õ3" , 0, "test õ1, õ2 |jz õ3" , 0
db "õ1<õ2!#õ3" , 0, "cmp õ1, õ2 |jae õ3" , 0
db "õ1!=õ2!#õ3" , 0, "cmp õ1, õ2 |je õ3" , 0
db "õ1==õ2!#õ3" , 0, "cmp õ1, õ2 |jne õ3" , 0

; nuovi
db "õ1==õ2,õ3#õ4" , 0
db "cmp õ1, õ2 |je õ4 |cmp õ1, õ3 |je õ4" , 0

db "õ1==õ2,õ3,õ4#õ5" , 0
db "cmp õ1, õ2 |je õ5 |cmp õ1, õ3 |je õ5 |cmp õ1, õ4 |je õ5"
, 0

db "õ1==õ2,õ3,õ4,õ5#õ6" , 0
db "cmp õ1, õ2 |je õ6 |cmp õ1, õ3 |je õ6 |cmp õ1, õ4 |je õ6
|cmp õ1, õ5 |je õ6" , 0

db "õ1==õ2,õ3,õ4,õ5,õ6#õ7" , 0
db "cmp õ1, õ2 |je õ7 |cmp õ1, õ3 |je õ7 |cmp õ1, õ4 |je õ7
|cmp õ1, õ5 |je õ7 |cmp õ1, õ6 |je õ7" , 0

; -----------------------------
; 129
; numeri col segno
db "õ1<õ2?#õ3" , 0, "cmp õ1, õ2 |jl õ3" , 0
db "õ1>õ2?#õ3" , 0, "cmp õ1, õ2 |jg õ3" , 0
db "õ1<=õ2?#õ3" , 0, "cmp õ1, õ2 |jle õ3" , 0
db "õ1>=õ2?#õ3" , 0, "cmp õ1, õ2 |jge õ3" , 0
db "õ1==õ2?#õ3" , 0, "cmp õ1, õ2 |je õ3" , 0
db "õ1!=õ2?#õ3" , 0, "cmp õ1, õ2 |jne õ3" , 0
db "õ1>=õ2!?#õ3" , 0, "cmp õ1, õ2 |jl õ3" , 0
db "õ1<=õ2!?#õ3" , 0, "cmp õ1, õ2 |jg õ3" , 0
db "õ1>õ2!?#õ3" , 0, "cmp õ1, õ2 |jle õ3" , 0
db "õ1<õ2!?#õ3" , 0, "cmp õ1, õ2 |jge õ3" , 0
db "õ1!=õ2!?#õ3" , 0, "cmp õ1, õ2 |je õ3" , 0
db "õ1==õ2!?#õ3" , 0, "cmp õ1, õ2 |jne õ3" , 0
; 141
db "õ1=õ2+õ3" , 0, "mov õ1, õ2 |add õ1, õ3" , 0
db "õ1=õ2-õ3" , 0, "mov õ1, õ2 |sub õ1, õ3" , 0
; 143
; label: istruzione = istruzione \0 commento
; numeri senza segno
db "=#õ1" , 0, "jz õ1" , 0
db "<#õ1" , 0, "jb õ1" , 0
db ">#õ1" , 0, "ja õ1" , 0
; 146
; numeri con segno
db "<=#õ1" , 0, "jbe õ1" , 0
db ">=#õ1" , 0, "jae õ1" , 0
db "=?#õ1" , 0, "je õ1" , 0
db "<?#õ1" , 0, "jl õ1" , 0
db ">?#õ1" , 0, "jg õ1" , 0
db "<=?#õ1" , 0, "jle õ1" , 0
db ">=?#õ1" , 0, "jge õ1" , 0
; numeri senza segno
db "!#õ1" , 0, "jnz õ1" , 0
db "!<#õ1" , 0, "jae õ1" , 0
db "!>#õ1" , 0, "jbe õ1" , 0
; 156
db "!<=#õ1" , 0, "ja õ1" , 0
db "!>=#õ1" , 0, "jb õ1" , 0
; numeri con segno
db "!?#õ1" , 0, "jne õ1" , 0
db "!<?#õ1" , 0, "jge õ1" , 0
db "!>?#õ1" , 0, "jle õ1" , 0
db "!<=?#õ1" , 0, "jg õ1" , 0
db "!>=?#õ1" , 0, "jl õ1" , 0

db "(õ1,õ2)<<=õ3" , 0, "shld õ1, õ2, õ3" , 0
db "(õ1,õ2)>>=õ3" , 0, "shrd õ1, õ2, õ3" , 0
; 165

db 0FFh, 0FFh, 0, 0FFh


NasmDef:
db "D" , 0, "dword" , 0
db "W" , 0, "word" , 0
db "B" , 0, "byte" , 0
db "Q" , 0, "qword" , 0
db "T" , 0, "tword" , 0
; 170
db "#õ1" , 0, "jmp short õ1" , 0
db "<<õ1=õ2" , 0, "%define õ1 õ2" , 0
db ">>õ1" , 0, "%undef õ1" , 0

db "<<õ1=õ2,õ3=õ4" , 0
db "%define õ1 õ2 |%define õ3 õ4" , 0
; 174
db ">>õ1,õ2" , 0
db "%undef õ1 |%undef õ2" , 0

db "<<õ1=õ2,õ3=õ4,õ5=õ6" , 0
db "%define õ1 õ2 |%define õ3 õ4 |%define õ5 õ6" , 0

db ">>õ1,õ2,õ3" , 0
db "%undef õ1 |%undef õ2 |%undef õ3" , 0

db "<<õ1=õ2,õ3=õ4,õ5=õ6,õ7=õ8" , 0
db "%define õ1 õ2 |%define õ3 õ4 |%define õ5 õ6 |%define õ7 õ8" , 0

db ">>õ1,õ2,õ3,õ4" , 0
db "%undef õ1 |%undef õ2 |%undef õ3 |%undef õ4 " , 0

db "<<õ1=õ2,õ3=õ4,õ5=õ6,õ7=õ8,õ9=õ10" , 0
db "%define õ1 õ2 |%define õ3 õ4 |%define õ5 õ6 |%define õ7 õ8 |%define
õ9 õ10" , 0

db ">>õ1,õ2,õ3,õ4,õ5" , 0
db "%undef õ1 |%undef õ2 |%undef õ3 |%undef õ4 |%undef õ5 " , 0

db "<<õ1=õ2,õ3=õ4,õ5=õ6,õ7=õ8,õ9=õ10,õ11=õ12" , 0
db "%define õ1 õ2 |%define õ3 õ4 |%define õ5 õ6 |%define õ7 õ8 |%define
õ9 õ10 |%define õ11 õ12 " , 0

db ">>õ1,õ2,õ3,õ4,õ5,õ6" , 0
db "%undef õ1 |%undef õ2 |%undef õ3 |%undef õ4 |%undef õ5 |%undef õ6 "
, 0

db "<<õ1=õ2,õ3=õ4,õ5=õ6,õ7=õ8,õ9=õ10,õ11=õ12,õ13=õ14" , 0
db "%define õ1 õ2 |%define õ3 õ4 |%define õ5 õ6 |%define õ7 õ8 |%define
õ9 õ10 |%define õ11 õ12 |%define õ13 õ14 " , 0
; 184
db ">>õ1,õ2,õ3,õ4,õ5,õ6,õ7" , 0
db "%undef õ1 |%undef õ2 |%undef õ3 |%undef õ4 |%undef õ5 |%undef õ6
|%undef õ7 " , 0

db "==õ1==õ2" , 0
db "extern õ1 |import õ1 õ2 " , 0

db "==õ1,õ2==õ3" , 0
db "extern õ1, õ2 |import õ1 õ3 |import õ2 õ3 " , 0

db "==õ1,õ2,õ3==õ4" , 0
db "extern õ1, õ2, õ3 |import õ1 õ4 |import õ2 õ4 |import õ3 õ4 " , 0

db "==õ1,õ2,õ3,õ4==õ5" , 0
db "extern õ1, õ2, õ3, õ4 |import õ1 õ5 |import õ2 õ5 |import õ3 õ5
|import õ4 õ5 " , 0

db "==õ1,õ2,õ3,õ4,õ5==õ6" , 0
db "extern õ1, õ2, õ3, õ4, õ5 |import õ1 õ6 |import õ2 õ6 |import õ3
õ6 |import õ4 õ6 |import õ5 õ6 " , 0

db "õ1,õ2=õ3" , 0
db "[section .data] |õ2 õ1 õ3 , 0 |__SECT__ " , 0

db "õ1,õ2=õ3,õ4=õ5" , 0
db "[section .data] |õ2 õ1 õ3 , 0 |õ4 õ1 õ5 , 0 |__SECT__ " , 0

db "õ1,õ2=õ3,õ4=õ5,õ6=õ7" , 0
db "[section .data] |õ2 õ1 õ3 , 0 |õ4 õ1 õ5 , 0 |õ6 õ1 õ7 , 0 |__SECT__ "
, 0

db "õ1,õ2=õ3,õ4=õ5,õ6=õ7,õ8=õ9" , 0
db "[section .data] |õ2 õ1 õ3 , 0 |õ4 õ1 õ5 , 0 |õ6 õ1 õ7 , 0 |õ8 õ1 õ9 ,
0 |__SECT__ " , 0
; 194
db "õ1,õ2=õ3,õ4=õ5,õ6=õ7,õ8=õ9,õ10=õ11" , 0
db "[section .data] |õ2 õ1 õ3 , 0 |õ4 õ1 õ5 , 0 |õ6 õ1 õ7 , 0 |õ8 õ1 õ9 ,
0 |õ10 õ1 õ11 , 0 |__SECT__ " , 0

db "õ1,õ2=õ3,õ4=õ5,õ6=õ7,õ8=õ9,õ10=õ11,õ12=õ13" , 0
db "[section .data] |õ2 õ1 õ3 ,0 |õ4 õ1 õ5 ,0 |õ6 õ1 õ7 ,0 |õ8 õ1 õ9 ,0 |õ10
õ1 õ11 ,0 |õ12 õ1 õ13 ,0 |__SECT__ " , 0
; 196

db 0FFh, 0FFh, 0, 0FFh

RosAsmDef:
db "#õ1" , 0
db "jmp õ1" , 0
db "dword" , 0, "D" , 0
db "word" , 0, "W" , 0
db "byte" , 0, "B" , 0
db "qword" , 0, "Q" , 0
db "tword" , 0, "T" , 0
db "short" , 0, " " , 0
db 0FFh, 0FFh, 0, 0FFh, 0

%define NL 13, 10

helpText:
db " ª V ^ " , NL
db " A E e " , NL
db " Processore Macro2D" , 13, 10
db "Questo programma tratta un file di input di istruzioni" , NL
db "che espande (usando alcune macro) e scrive in un file" , NL
db "di output. Tale file di output dovrebbe essere un file" , NL
db "di testo in linguaggio assembly per la cpu 386 Intel" , NL
db "scritto usando la stessa sintassi di Nasm o di RosAsm." , NL
db " " , NL
db "Questo programma e' solo un tentativo o un esperimento" , NL
db "con l'obiettivo di non abolire le micro-istruzioni" , NL
db "dell'assembly pur trovando un modo per evidenziare" , NL
db "i loop e gli if. In pratica si usa l'indentazione ed" , NL
db "le multi istruzioni per linea per ottenere" , NL
db "programmazione strutturata in assembly, che mostra" , NL
db "come i goto o i salti, cosi' comuni in assembly," , NL
db "possono, se correttamente indentati, costituire" , NL
db "programmi molto leggibili [a differenza di quello che" , NL
db "dice la gente sui goto]. In pratica si passa da un" , NL
db "codice in una dimensione [1 istruzione per linea] a" , NL
db "codice in 2 dimensioni [piu' istruzioni per linea +" , NL
db "indentazione]." , NL
db "Spero che qualche programmatore usi questo linguaggio" , NL
db "e non perda la speranza nel considerare il linguaggio" , NL
db "assembly il linguaggio migliore di tutti." , NL
db " " , NL
db " Nota Bene" , NL
db "In poche parole se questo programma si chiama Macro2D" , NL
db '"Macro2D input.m output.asm"' , NL
db "ha come input il file input.m e come output il file" , NL
db "output.asm da trattare con Nasm con per esempio" , NL
db '"nasmw -fobj output.asm"' , NL
db " " , NL
db "Per quanto riguarda l'output con RosAsm" , NL
db '"Macro2D -r input.m rosoutput.asm"' , NL
db "ha come risultato il file rosoutput.asm da elaborare" , NL
db "usando RosAsm." , NL
db '"Macro2D -howuse"' , NL
db "Da' come output le macro in esso contenute e questa" , NL
db "spiegazione, per tutte le altre opzioni utilizzabili" , NL
db "vedere l'opzione -h."
db " " , NL
db " Fine Nota Bene" , NL
db "Il modo di procedere per imparare il linguaggio che" , NL
db "e' sottointeso e' imparare a memoria tutte le macro" , NL
db "istruzioni che seguono (semplicissimo perche' sono" , NL
db "intuitive e poche) e usandole bene per costruire" , NL
db "programmi strutturati." , NL
db " " , NL
db "Alcune particolarita'" , NL
db '* Commenti di linea: "/*" ed ";" sono stringhe di ' , NL
db " inizio per commenti che finisco quando finisce la" , NL
db ' linea ["\n"]' , NL
db " " , NL
db '* Commenti multilinea: "\n;;"'
db " e' la stringa iniziale" , NL
db ' per commenti multilinea che finiscono con "\n;;\n"' , NL
db " " , NL
db '* Commenti multilinea: "\n;*"'
db " e' la stringa iniziale" , NL
db ' per commenti multilinea che finiscono con "\n;;\n"' , NL
db ' oppure con "\n;*\n" tale tipo di commento vale per' , NL
db " la traduzione verso Nasm assembly ma e' commento" , NL
db " semplice per la traduzione verso RosAsm assembly" , NL
db " (opzione -r)" , NL
db " " , NL
db "* Per permettere a piu' istruzioni di condividere la" , NL
db ' stessa linea si usa il separatore "|" che viene' , NL
db ' sostituito da "\n" nella traduzione.' , NL
db " " , NL
db '* ",\n" provoca '
db " l'unione delle della corrente linea" , NL
db " e della linea successiva:" , NL
db ' "lineacorrente,\nLineasuccessiva" ->' , NL
db ' "lineacorrente,Lineasuccessiva"' , NL
db " " , NL
db '* "\\n" provoca '
db " l'unione delle della corrente linea" , NL
db " e della linea successiva:" , NL
db ' "lineacorrente\\n Lineasuccessiva" ->' , NL
db ' "lineacorrente Lineasuccessiva"' , NL
db " " , NL
db '* Alcuni registri hanno nuovi nomi esempio "a" sta' , NL
db " per eax: a->eax, b->ebx, c->ecx, r->edx, i->esi" , NL
db " j->edi, s->esp, k->ebp, rx->dx, jx->di, ix->si" , NL
db " sx->sp, kx->kp, rh->dh, rl->dl." , NL
db " (i nomi degli altri registri o sottoregistri" , NL
db " sono quelli che usa nasmw ). " , NL
db " " , NL
db "* Non sono valide espressioni del tipo a=b+7 o c=a-90" , NL
db " " , NL
db "* E' possibile utilizzare stringhe come nomi di" , NL
db " stringhe a patto che siano di lunghezza >=5 e.g." , NL
db ".data" , NL
db '"stri=%i" db "stri=%i", 0' , NL
db "..." , NL
db ".text" , NL
db "..." , NL
db 'printf<("stri=%i", eax);' , NL
db "che dovrebbe avere traduzione in qualcosa come" , NL
db ".data" , NL
db 'striIIi db "stri=%i", 0' , NL
db "..." , NL
db ".text" , NL
db "..." , NL
db "push eax" , NL
db "push striIIi" , NL
db "call printf" , NL
db "add esp, 8" , NL
db " " , NL
db "* Le istruzioni" , NL
db " mov eax, 4|98, a=4|8, mov eax, 7*9+45" , NL
db " non ottengono le corrette traduzioni; quello che si" , NL
db " potrebbe fare e' mettere le parentesi tonde, anche" , NL
db " se non sono supportate 2 livelli di parentesi, " , NL
db " esempio:"
db " a(&questo|&qwello, 8|4, b)" , NL
db " ha come risultato" , NL
db " push ebx" , NL
db " push 8|4" , NL
db " push &questo|&qwello" , NL
db " call eax" , NL
db " perche' vi e' la parentesi tonda, se si usa" , NL
db " un'altra parentesi tonda il risultato non compila." , NL
db " Altri esempi che dovrebbero essere ok:" , NL
db " mov eax, (4|98) oppure a=(4|98)" , NL
db " mov eax, (7*9+45)" , NL
db " fun(8*9+45, c)" , NL
db " " , NL
db "* ^ ha anche una funzione particolare di accesso allo" , NL
db " stack per esempio:"
db " ^nome|=ebx -> or dword[esp+nome], ebx" , NL
db " ^a-4=99 -> mov dword [esp+a-4], 99" , NL
db " " , NL
db "* * ha una funzione particolare di accesso alla memoria." , NL
db " Esempio: D*a-4=99 viene tradotto in" , NL
db " mov dword [eax-4], 99" , NL
db " " , NL
db "* Non ho fatto molte prove su testi; quindi errori." , NL
db " " , NL
db " Note sull'uso" , NL
db "Declino ogni responsabilita' per qualsiasi danno che" , NL
db "potrebbe arrecare questo programma, o il suo risultato" , NL
db "e declino ogni garanzia implicita o esplicita che" , NL
db "questo programma serva a qualche cosa." , NL
db "Il programma si intende libero (free) per la copia e" , NL
db "per il solo uso descritto sopra quando si parla" , NL
db 'di "Nota Bene"; il suo uso ' , NL
db "quindi e' quello di fornire" , NL
db "macro-espansioni di programmi, anche a uso commerciale" , NL
db "senza io aver niente a pretendere per gli eventuali" , NL
db "programmi tradotti che restano di chi li scrive, come" , NL
db "restano di chi li scrive tutti gli oneri e obblighi" , NL
db "a tali programmi associati." , NL
db "A patto che non venga usato per: " , NL
db "* macro-espansioni di programmi a uso militare o per" , NL
db " distruggere o uccidere qualsiasi essere vivente" , NL
db "* macro-espansioni di programmi per tecnologie per" , NL
db " armi" , NL
db "* macro-espansioni di programmi per tecnologie che" , NL
db " mirino alla modifica del DNA di qualsiasi essere" , NL
db " vivente piante comprese" , NL
db "* macro-espansioni di programmi per tecnologie che" , NL
db " producono rifiuti nucleari, o rifiuti pericolosi" , NL
db " al livello di pericolosita' maggiori o uguali a" , NL
db " quelli dell'uranio." , NL
db " " , NL
db " Alcuni esempi " , NL
db "/* ritorna la lunghezza della stringa presa " , NL
db "/* c==1 significa raggiunto EOF" , NL
db "/* c==0 significa non raggiunto EOF" , NL
db "/* 0k,4j,8i,12b,16ra," , NL
db "/* 20PArr,24PArrSize,28PHandle + 8" , NL
db "/* 28 j |32 k |36 i" , NL
db "SGetLine:" , NL
db "<b,i,j,k" , NL
db "s-=8|j=^28|k=^32|i=^36|b=s" , NL
db " k<=0?#.e0|j#.1" , NL
db ".e0: a^=a" , NL
db ".e: c^=c|stc|#.z" , NL
db ".e1: B*j=0|j-=[s+28]|a=j|#.e" , NL
db ".1: k+=j" , NL
db ".2: j>=k#.e1" , NL
db " ReadFile(i,j,1,b,0)" , NL
db " a==0#.e1|D*s!=1#.3 /*raggiunto EOF" , NL
db " ++j| B[j-1]!=10#.2|c^=c|#.4" , NL
db ".3: c=1" , NL
db ".4: B*j=0|j-=[s+28]|a=j|clc" , NL
db ".z:" , NL
db "s=&[s+8]" , NL
db ">b,i,j,k" , NL
db "ret 12" , NL
db "Tradotto in:" , NL
db "; ritorna la lunghezza della stringa presa" , NL
db "; c==1 significa raggiunto EOF" , NL
db "; c==0 significa non raggiunto EOF" , NL
db "; 0k,4j,8i,12b,16ra," , NL
db "; 20PArr,24PArrSize,28PHandle + 8" , NL
db "; 28 j |32 k |36 i" , NL
db "SGetLine: " , NL
db " push ebx" , NL
db " push esi" , NL
db " push edi" , NL
db " push ebp" , NL
db " sub esp, 8" , NL
db " mov edi, dword[esp+ 28]" , NL
db " mov ebp, dword[esp+ 32]" , NL
db " mov esi, dword[esp+ 36]" , NL
db " mov ebx, esp" , NL
db " cmp ebp, 0" , NL
db " jle .e0" , NL
db " cmp edi, 0" , NL
db " jne .1" , NL
db ".e0: xor eax, eax" , NL
db ".e: xor ecx, ecx" , NL
db " stc" , NL
db " jmp short .z" , NL
db ".e1: mov byte [edi], 0" , NL
db " sub edi, [esp+28]" , NL
db " mov eax, edi" , NL
db " jmp short .e" , NL
db ".1: add ebp, edi" , NL
db ".2: cmp edi, ebp" , NL
db " jae .e1" , NL
db " push 0" , NL
db " push ebx" , NL
db " push 1" , NL
db " push edi" , NL
db " push esi" , NL
db " call ReadFile" , NL
db " cmp eax, 0" , NL
db " je .e1" , NL
db " cmp dword [esp], 1" , NL
db " jne .3 ;raggiunto EOF" , NL
db " inc edi" , NL
db " cmp byte[edi-1], 10" , NL
db " jne .2" , NL
db " xor ecx, ecx" , NL
db " jmp short .4" , NL
db ".3: mov ecx, 1" , NL
db ".4: mov byte [edi], 0" , NL
db " sub edi, [esp+28]" , NL
db " mov eax, edi" , NL
db " clc" , NL
db ".z: " , NL
db " lea esp, [esp+8]" , NL
db " pop ebp" , NL
db " pop edi" , NL
db " pop esi" , NL
db " pop ebx" , NL
db " ret 12" , NL
db "Utilizzo alcune convenzioni per le label." , NL
db "Notare come .z e' la label 'di uscita' e utilizzo" , NL
db "label globali per il nome della funzione, locali" , NL
db "per le label della funzione, l'ultima label e' .z" , NL
db "Le uniche label locali significative sono .e, .e0" , NL
db ".e1 eccetera; se necessario aggiungere label tra" , NL
db "due label esempio .1 ed .2 utilizzo .1a, .1b ecc." , NL
db "/* u32 [size] CatStr(u8* dest,u32 Size,u8* stringCat)" , NL
db "/* 0j,4ra,8P_dest,12P_size,16P_stringCat a,c,r,j" , NL
db "CatStr:" , NL
db "<j" , NL
db " j=[s+8]|c=[s+12]|r=[s+16]" , NL
db " j==0#.e|a^=a|c>1?#.2" , NL
db ".ee: B*j=0" , NL
db ".e: a^=a| stc| #.z" , NL
db ".1: ++j|--c!#.e" , NL
db ".2: B*j#.1" , NL
db ".3: al=*r|*j=al|a==0#.4" , NL
db " --c!#.ee|++r,j|#.3" , NL
db ".4: a=j|B*j=0|a-=[s+8]|clc" , NL
db ".z:" , NL
db ">j" , NL
db "ret 12" , NL
db "Tradotto in:" , NL
db "; u32 [size] CatStr(u8* dest,u32 Size,u8* stringCat)" , NL
db "; 0j,4ra,8P_dest,12P_size,16P_stringCat a,c,r,j" , NL
db "CatStr: " , NL
db " push edi" , NL
db " mov edi, [esp+8]" , NL
db " mov ecx, [esp+12]" , NL
db " mov edx, [esp+16]" , NL
db " cmp edi, 0" , NL
db " je .e" , NL
db " xor eax, eax" , NL
db " cmp ecx, 1" , NL
db " jg .2" , NL
db ".ee: mov byte [edi], 0" , NL
db ".e: xor eax, eax" , NL
db " stc" , NL
db " jmp short .z" , NL
db ".1: inc edi" , NL
db " dec ecx" , NL
db " jz .e" , NL
db ".2: cmp byte [edi], 0" , NL
db " jne .1" , NL
db ".3: mov al, [edx]" , NL
db " mov [edi], al" , NL
db " cmp eax, 0" , NL
db " je .4" , NL
db " dec ecx" , NL
db " jz .ee" , NL
db " inc edx" , NL
db " inc edi" , NL
db " jmp short .3" , NL
db ".4: mov eax, edi" , NL
db " mov byte [edi], 0" , NL
db " sub eax, [esp+8]" , NL
db " clc" , NL
db ".z: " , NL
db " pop edi" , NL
db " ret 12 " , NL
db "Oggi 9 Agosto 2008" , NL
db "Saluti a tutti." , NL
db NL, NL
db " Tutte la macro sostituzioni ammesse per Nasm" , NL
db 0, 0

qui times 1028 db 0

nl db 13, 10, 0

Litlehelp:
db " ª V ^ " , NL
db " A E e " , NL
db "Questo programma tratta un file di input di istruzioni" , NL
db "che espande (usando alcune macro) e scrive in un file" , NL
db "di output. Tale file di output dovrebbe essere un file" , NL
db "di testo in linguaggio assembly per la cpu 386 Intel" , NL
db "scritto usando la stessa sintassi di Nasm o di RosAsm." , NL
db " " , NL
db "Uso: " , NL
db '"ThisFile.exe -h"' , NL
db "per stampare questo file di help" , NL
db "+" , NL
db '"ThisFile.exe -howuse"' , NL
db "per stampare un file di help piu' grande" , NL
db "+" , NL
db '"ThisFile.exe input.m output.asm"' , NL
db "ha come input il file input.m e come output il file" , NL
db "output.asm da trattare con Nasm con per esempio" , NL
db '"nasmw -fobj output.asm"' , NL
db "+" , NL
db '"ThisFile.exe -r input.m rosoutput.asm"' , NL
db "Per quanto riguarda l'output con RosAsm" , NL
db "ha come risultato il file rosoutput.asm da elaborare" , NL
db "usando RosAsm." , NL
db "+" , NL
db '"ThisFile.exe input.asm"' , NL
db "Questo programma serve per formattare meglio" , NL
db "un programma assembly risultato del programma" , NL
db "delle macro." , NL
db "Scrive il file come risultato: prog_Btf.asm" , NL
db "+" , NL
db '"ThisFile.exe -Ob a.m"' , NL
db "Ha come risultato a.asm, a.obj in qusto modo:" , NL
db "ThisFile.exe -Ob a.m -> a.asm" , NL
db "nasmw -fobj a.asm -> a.obj" , NL
db "+" , NL
db '"ThisFile.exe -Pe a.m"' , NL
db "Programma di tipo PE." , NL
db "Ha come risultato a.asm, a.obj, a.exe cosi':" , NL
db "ThisFile.exe -Ob a.m -> a.asm" , NL
db "nasmw -fobj a.asm -> a.obj" , NL
db "alink -oPe a.obj win32.lib -> a.exe" , NL
db "+" , NL
db '"ThisFile.exe -Dl a.m"' , NL
db "Libreria .dll." , NL
db "Ha come risultato a.asm, a.obj, a.dll cosi':" , NL
db "ThisFile.exe -Ob a.m -> a.asm" , NL
db "nasmw -fobj a.asm -> a.obj" , NL
db "alink -oPe -dll a.obj win32.lib -> a.dll" , NL
db "+" , NL
db '"ThisFile.exe -Co a.m"' , NL
db "Programma di tipo console." , NL
db "Ha come risultato a.asm, a.obj, a.exe cosi':" , NL
db "ThisFile.exe -Co a.m -> a.asm" , NL
db "nasmw -fobj a.asm -> a.obj" , NL
db "alink -oPe -subsys con a.obj win32.lib -> a.exe" , NL
db "+" , NL
db '"ThisFile.exe -In"' , NL
db "Espande le macro di Nasm inserite in input." , NL, 0, 0

INasmwIIIfobjII db "Nasmw -fobj " , 0, 0
IalinkIIIoPEIII db "alink -oPE " , 0, 0
IalinkIIoPEIIsubsysIconI db "alink -oPE -subsys con " , 0, 0
IalinkIIoPEIIdllI db "alink -oPE -dll " , 0, 0
IIwin32Ilib db " win32.lib" , 0, 0
IIIIIIIII db " ---> " , 0, 0
IInserisciINasmIMacroIII db "Inserisci Nasm Macro > " , 0, 0
IIIIRisultatoI db " ; Risultato " , 0, 0
IErroreInellIorigineII db "Errore nell'origine; " , 0, 0
IErroreIdiIargomentiII db "Errore di argomenti; " , 0, 0
IInErroreIdiIFreeIn db 13, 10, "Errore di Free" , 13, 10, 0, 0
IIPremiInI db "<Premi\n>" , 0, 0
I0123456789ABCDEF db "0123456789ABCDEF" , 0, 0, 0, 0
IIIOkIDeltaITimeII db ";;Ok Delta Time: " , 0, 0
IMacro2DIn db "Macro2D" , 13, 10, 0, 0
IZBWIDIIIIQIT db "ZBW D Q T" , 0, 0
; Rosario Pulvirenti
; Ilnomenonnelprogra
nome db 032h, 0bh, 04fh, 035h, 01dh, 012h, 0ch, 01fh, 08h, 04fh, 050h, 035h,
07h, 04ch
db 02h, 01bh, 013h, 01h, 01bh, 06h, 01bh, 045h, 012h, 05dh, 051h, 05bh, 0, 0
nome1 db "Programma per tradurre macro " , 0, 0


section _TEXT use32 public class=CODE

Malloc_sys:
mov eax, [esp+4]
cmp eax, 0
jl .e
jz .1
push PAGE_READWRITE
push 03000h
push eax
push 0
call VirtualAlloc
cmp eax, 0
je .f
..1: clc
jmp short .z
..e: xor eax, eax
..f: stc
..z:
ret 4

Free_sys:
mov eax, [esp+4]
cmp eax, 0
je .1
push MEM_RELEASE
push 0
push eax
call VirtualFree
cmp eax, 0
jne .1
..e: mov edx, [stderr]
cmp edx, -1
je .0
push IInErroreIdiIFreeIn
push edx
call SPuts
..0: mov eax, 1
stc
jmp short .z
..1: xor eax, eax ; pone CF==0
..z:
ret 4

; 0ra, 4P_a, 8P_sizeinbytes
Zero:
mov eax, [esp+4]
mov ecx, [esp+8]
cmp eax, 0
je .e
cmp ecx, 0
jg .1
..e: stc
jmp short .z
..1: xor edx, edx
and ecx, 0FFFFFFFCh
jmp short .3
..2: mov dword[eax+edx], 0
add edx, 4
..3: cmp edx, ecx
jb .2
mov ecx, [esp+8]
and ecx, 3
jz .5
add ecx, edx
..4: mov byte[eax+edx], 0
inc edx
cmp edx, ecx
jb .4
..5: clc
..z:
ret 8

; eax, ebx, ecx, edx, esi, edi
; esp, ebp
; 0ra,4P_a
Isreg:
mov edx, [esp+4]
cmp edx, 0
jne .1
..e: xor eax, eax
stc
jmp .z
..1: xor eax, eax
xor ecx, ecx
mov ax, [edx]
mov cx, [edx+2]
and ax, 05f5fh
xor edx, edx
mov dl, ch
xor ch, ch ; ah,al,ch,cl
cmp byte[MyTable+ecx], Space
je .1a
cmp ecx, ','
je .1a
cmp ecx, 13
je .1a
cmp ecx, 10
je .1a
cmp ecx, 0
je .1a ; prima 2chars
cmp al, "E"
jne .e
and cl, 05fh
cmp byte[MyTable+edx], Space
je .2
cmp dl, ','
je .2
cmp dl, 13
je .2
cmp dl, 10
je .2
cmp dl, 0
je .2 ; 3 chars?
jmp short .e
..1a: jmp .5
..2: cmp ecx, "X"
jne .3
cmp eax, "EA"
je .r4

cmp eax, "EB"
je .r4

cmp eax, "EC"
je .r4

cmp eax, "ED"
je .r4

jmp .e
..r4: mov eax, 4
jmp .y
..3: cmp ecx, "I"
jne .4
cmp eax, "ES"
je .r4

cmp eax, "ED"
je .r4

jmp .e
..4: cmp ecx, "P"
jne .e
cmp eax, "ES"
je .r4

cmp eax, "EB"
je .r4

jmp .e
..5: xor ecx, ecx
mov cl, al
cmp ecx, "A"
je .7
cmp ecx, "B"
je .8
cmp ecx, "C"
je .9
cmp ecx, "D"
je .a
cmp ecx, "S"
je .6
jmp .e
..6: jmp .b
..7: cmp eax, "AX"
je .r2
cmp eax, "AL"
je .r1
cmp eax, "AH"
je .r1
jmp .e
..8: cmp eax, "BX"
je .r2
cmp eax, "BL"
je .r1
cmp eax, "BH"
je .r1
cmp eax, "BP"
je .r2
jmp .e
..r2: mov eax, 2
jmp .y
..r1: mov eax, 1
jmp .y
..9: cmp eax, "CX"
je .r2
cmp eax, "CL"
je .r1
cmp eax, "CH"
je .r1
jmp .e
..a: cmp eax, "DX"
je .r2
cmp eax, "DL"
je .r1
cmp eax, "DH"
je .r1
cmp eax, "DI"
je .r2
jmp .e
..b: cmp eax, "SI"
je .r2
cmp eax, "SP"
je .r2
jmp .e
..y: clc
..z:
ret 4

;0r, 4c,8b,12ra,16P_string, 20P_quanti
sposta:
push ebx
push ecx
push edx
mov ebx, dword[esp+ 16]
mov edx, dword[esp+ 20]
inc ebx
xor eax, eax
cmp edx, 0
jle .z
jmp short .1
..0: inc ebx
..1: mov al, [ebx+edx]
mov [ebx], al
cmp eax, 0
jne .0
lea ecx, [ebx+edx]
..2: inc ebx
mov byte[ebx], 0
cmp ebx, ecx
jb .2
..z:
pop edx
pop ecx
pop ebx
ret 8

; 0r,4b,8ra, 12P_tav
; NB: AtoI modifica solo cl
ConvertiNumeriTavola:
push ebx
push edx
mov ebx, [esp+12]
xor ecx, ecx
cmp ebx, 0
jne .1
..e: mov eax, -1
stc
jmp short .z
..1: mov cl, [ebx]
cmp ecx, 0
jne .2
cmp byte[ebx+1], 0FFh
je .9 ; 0,0FFh => finisce
..2: cmp ecx, 'õ'
jne .3
xor eax, eax
mov al, [ebx+1]
cmp byte[MyTable+eax], 0
jne .3
inc ebx
push ebx
call AtoI
cmp eax, 0
je .e
cmp eax, 255
ja .e
mov [ebx], al
mov edx, 0
cmp eax, 9
jbe .2a
inc edx
..2a: cmp eax, 99
jbe .2b
inc edx
..2b: push edx
push ebx
call sposta
; cl=al|B[MyTable+c]==0#.e
; ci sono problemi a
; una eventuale doppia passata della funzione
..3: inc ebx
jmp short .1
..9: clc
..z:
pop edx
pop ebx
ret 4

; 0b,4ra,8P_tav
; NB: AtoI modifica solo cl
SostituisciSbarraCon13_10:
push ebx
mov ebx, [esp+8]
xor ecx, ecx
cmp ebx, 0
jne .1
..e: mov eax, -1
stc
jmp short .z
..1: mov cl, [ebx]
cmp ecx, 0
jne .2
cmp byte[ebx+1], 0FFh
je .9 ; 0,0FFh => finisce
..2: cmp ecx, '|'
jne .3 ; sostituise " |" con \r\n
cmp byte[ebx-1], ' '
jne .3
mov byte[ebx-1], 13
mov byte[ebx], 10
..3: inc ebx
jmp short .1
..9: clc
..z:
pop ebx
ret 4


; scrive tutta la stringa da origine a destinazione
; senza usare nessuna macro
; j=destinazione, i=origine
; B1limit=B1limit+8=76 [2 funzioni chiamate]
CopyString:
%define B1Limit 76
mov eax, ebx ; in b vi è il carattere al=" o '
mov ecx, [esp+B1Limit]
mov byte[edi], ' '
cmp edi, ecx
jae .e
inc edi
mov [edi], bl
cmp edi, ecx
jae .e
inc esi
inc edi
..1: mov bl, [esi]
mov [edi], bl
cmp byte[MyTable+ebx], EOI
je .e ; errore
cmp edi, ecx
jae .e
inc esi
inc edi
cmp ebx, eax
jne .1
mov byte[edi], ' '
cmp edi, ecx
jae .e
inc edi
xor eax, eax
jmp short .z
..e: mov eax, -1
stc
..z:
%undef B1Limit
ret

; scrive tutta la stringa da origine a destinazione
; senza usare nessuna macro, sostituendo gli spazi
; e le lettere non alfanumeriche con I
; r=destinazione, i=origine
; c e' size attuale destinazione, b e' ultimo carattere
CopyPseudoString:
push ebp
%define B1Limit 80
mov ebp, ebx
xor eax, eax
mov ecx, [esp+B1Limit]
inc esi ; salta il " o '
mov byte[edi], ' '
cmp edi, ecx
jae .e
inc edi
mov byte[edi], 'I'
cmp edi, ecx
jae .e
inc edi
..1: mov bl, [esi]
cmp ebx, ebp
je .4
mov al, [MyTable+ebx]
cmp ebx, 0
je .e
cmp ebx, 10
je .e
cmp ebx, 13
je .e
cmp ebx, '.'
je .1a
cmp eax, 2
jbe .2
..1a:
mov byte[edi], 'I'
jmp short .3
..2:
mov [edi], bl
..3: cmp edi, ecx
jae .e
inc esi
inc edi
jmp short .1
..e: mov eax, -1
stc
jmp short .z
..4: inc esi ; salta ultima "
mov byte[edi], ' '
cmp edi, ecx
jae .e
inc edi
xor eax, eax
..z:
%undef B1Limit
pop ebp
ret


; a*31=a*(32-1)=a*32-a
; ritorna il valore di hash della stringa puntata da b
; in ogni caso edx==eax alla fine della funzione
; u32 Hash(u8* b)
; 0i,4b,8ra,12P_s
Hash:
push ebx
push esi
mov ebx, [esp+12]
xor eax, eax
xor ecx, ecx
xor edx, edx
mov esi, 8
cmp ebx, 0
jne .2
..e: stc
jmp short .z
..0: cmp byte[ebx], 0
je .3
inc ebx
jmp short .0
..1: inc ebx
dec esi
jz .0 ; a*31=a*32-a
mov edx, eax
shl eax, 5
add eax, ecx
sub eax, edx
..2: mov cl, [ebx]
cmp ecx, 0
jne .1
..3: mov edx, [esp+12]
mov ecx, HASHSIZE
sub ebx, edx
shl eax, 4 ; in b e' len
xor edx, edx
add eax, ebx
div ecx
mov eax, edx
mov ecx, ebx ; eax==edx
clc ; c=strlen(name)
..z:
pop esi
pop ebx
ret 4


; u32* Lookup(u8* name)
; ritorna a=0 CF==1, hashtab posizi. nodo in edx
; strlen(name) in ecx
; se non troavato
; -----------------------------------------
; altrimenti l'indirizzo del nodo trovato in eax
; l'indirizzo del precedente in edx
; strlen(name) in ecx
; 0k,4i,8j,12b,16ra,20P_name
Lookup:
push ebx
push esi
push edi
push ebp
mov esi, [esp+20]
xor ebp, ebp
cmp dword[hashtab], 0
je .e
cmp esi, 0
jne .1
..e: xor eax, eax
stc
jmp short .z
..0: mov eax, ebx
clc
jmp short .z
..1: push esi
call Hash
mov ebp, ecx
mov ecx, [hashtab]
lea eax, [ecx+edx*4]
mov ebx, [eax]
mov edx, eax
cmp ebx, 0
je .e ; non trovato
..2: mov edi, [ebx+4]
cmp edi, 0
je .e ; senza stringa???
push edx
call DCmp
pop edx
jnc .0 ; cmp(i:lenk, j:string)
..4: mov edx, ebx
mov ebx, [edx]
cmp ebx, 0
jne .2
jmp short .e
..z: mov ecx, ebp
pop ebp
pop edi
pop esi
pop ebx
ret 4


; FindMacro per stringhe
; u8* FindMacro(u8* name)
; ritorna c=a=0 CF=1 se errore di parametro
; ----------------------------------------
; ritorna a=name, c=strlen(name)
; CF=1 se non trovato nel lookup
; ----------------------------------------
; ritorna a=def, c=strlen(def), CF=0
; se e' trovato nel lookup
; ----------------------------------------
; 0ra,4P_name
FindMacro:
%define nx 0
%define nm 4
%define df 8
%define dfl 12
mov edx, [esp+4]
push edx
call Lookup
jc .0
mov ecx, [eax+dfl]
mov eax, [eax+df]
clc
jmp short .z
..0: mov eax, [esp+4]
..z:
%undef nx
%undef nm
%undef df
%undef dfl
ret 4

; la funzione chiamante se trova il commento esce
; quindi scrive il commento direttamente nell'argomento
; della funzione j
IsComment:
%define Result 52
call First_ch1
jc .e
mov ecx, edi
add ecx, ebp
xor eax, eax
cmp ebx, ';'
je .2
cmp ebx, '/'
jne .0
cmp byte[esi+1], '*'
jne .0
jmp short .1
..0: jmp .5
..e: mov byte[edi], 0
mov eax, -1
stc
jmp .z ; errore
..f: mov byte[edi], 0
or dword[esp+Result], 1
jmp short .f1
..f0: mov byte[edi], 0
or dword[esp+Result], 128
..f1: mov eax, 1
clc
jmp short .z ; trovata
..1: inc esi
..2: inc esi
or dword[esp+Result], 8
mov byte[edi], ';'
inc edi
..3: mov al, [esi]
mov [edi], al
cmp edi, ecx
jae .e
inc esi
inc edi
cmp al, 10
je .f
cmp al, 0
je .f0
jmp short .3
..5: mov byte[edi], 0
xor eax, eax ; non trovata
..z:
%undef Result
ret



; la funzione chiamante se trova la label esce
; quindi scrive la label direttamente nell'argomento
; della funzione j
IsLabel:
%define LetterCount 48
%define Result 52
call First_ch1
jc .e
cmp byte[MyTable+ebx], 3
jbe .0
jmp .7
..0: mov edx, esi
xor eax, eax ; r punta al primo char di una parola
..1: inc edx
mov al, [edx]
cmp byte[MyTable+eax], 3
jbe .1
mov ecx, edx
jmp short .3
..2: inc ecx
mov al, [ecx]
..3: cmp byte[MyTable+eax], Space
je .2
cmp eax, ':'
je .3a
jmp .7 ; trovata label
..3a: sub edx, esi
add edx, 5
cmp edx, ebp
jb .4
..e: mov eax, -1
stc
jmp .z
..4: mov dword[esp+ LetterCount], edx
mov ebp, edx
sub ebp, 5
jl .e
mov ebx, ecx
call DCopy
add edi, eax
mov byte[edi], ':'
inc edi
mov byte[edi], ' '
inc edi ;| B*j=0
mov byte[edi], ' '
inc edi
mov byte[edi], 0
mov esi, ebx
xor ebx, ebx
call Next_ch1
cmp ebx, 13
jne .6
mov byte[edi], 13
inc edi
inc esi
mov byte[edi], 0
mov bl, [esi]
cmp ebx, 10
jne .4a
..5: mov byte[edi], 10
inc edi
inc esi
mov byte[edi], 0
or dword[esp+Result], 1
jmp short .6a
..6: cmp ebx, 10
je .5
..4a: cmp ebx, 0
jne .5a
or dword[esp+Result], 128
jmp short .6a
..5a: or dword[esp+Result], 512 ; fine istruzione per label
..6a: or dword[esp+Result], 2
mov eax, 1
clc
jmp short .z
..7: xor eax, eax
..z:
%undef LetterCount
%undef Result
ret


; combine cambia j
combine:
mov ebp, eax
xor eax, eax ; k=risultato macro
mov ecx, [esp+2052]
mov edi, [esp+2056]
add ecx, edi
..0: mov al, [ebp]
cmp eax, 'õ'
jne .2 ; 1..64
inc ebp
mov al, [ebp]
cmp eax, 0
je .e
cmp eax, 64
ja .e
inc ebp
lea edx, [esp+80]
mov edx, [edx+eax*4]
cmp edx, 0
je .e
..1: mov al, [edx]
cmp eax, 0
je .0
mov [edi], al
cmp edi, ecx
jae .e
inc edx
add edi, 1
jnc .1
jmp short .e
..2: mov [edi], al
cmp edi, ecx
jae .e
cmp eax, 0
je .3
inc ebp
add edi, 1
jnc .0
..e: mov eax, 1
mov byte[edi], 0
stc
jmp short .z
..3: clc
..z:
ret

; i=origin
; ritorna in b l'ultimo carattere
; e in i la posizione del prossimo carattere
; non usa altri registri che b ed i
; quindi per uso informativo usare come in
Next_ch:
%define NowPC 44
%define PrecPC 56
inc esi
First_ch:
..1: mov bl, [esi]
cmp byte[MyTable+ebx], Space
jne .2
add esi, 1
jnc .1
jmp short .z
..2: mov eax, dword[esp+ NowPC]
mov dword[esp+ PrecPC], eax
mov dword[esp+ NowPC], esi
clc
..z:
%undef NowPC
%undef PrecPC
ret

; i=origin
; ritorna in b l'ultimo carattere
; e in i la posizione del prossimo carattere
; non usa altri registri che b ed i
; quindi per uso informativo usare come in
Next_ch1:
%define NowPC 48
%define PrecPC 60
inc esi
First_ch1:
..1: mov bl, [esi]
cmp byte[MyTable+ebx], Space
jne .2
add esi, 1
jnc .1
jmp short .z
..2: mov eax, dword[esp+ NowPC]
mov dword[esp+ PrecPC], eax
mov dword[esp+ NowPC], esi
clc
..z:
%undef NowPC
%undef PrecPC
ret

; il chiamante deve ++j quando trova che la parola è finita
ScriviParola:
%define B1Limit 72
%define B2Limit 68
%define DaiNumeroP 76
%define PointerArray 80
%define NowPC 44
%define PrecPC 56
%define InWord 60
%define InAsterisco 36
%define InParentesiTonde 64
%define InParentesiQ 40
%define AD 28
..0: cmp ebx, '"'
jne .4
..1: cmp byte[esi+1], bl
je .2
cmp byte[esi+2], bl
je .2
cmp byte[esi+3], bl
je .2
cmp byte[esi+4], bl
je .2
cmp byte[esi+5], bl
je .2
mov eax, dword[esp+ PrecPC]
cmp eax, 0
je .0a
cmp byte[eax], ','
jne .1a
..0a: cmp dword[esp+InParentesiTonde], 0
jne .3
cmp dword[esp+InAsterisco], 0
jne .3
cmp dword[esp+InParentesiQ], 0
jne .3
jmp short .2
..1a: cmp byte[eax], 'd'
jne .3
cmp byte[eax+1], 'b'
jne .3
xor edx, edx
mov dl, [eax+2]
cmp byte[MyTable+edx], Space
jne .3 ; qui copia stringa
..2: mov edx, edi
call CopyString
jc .e
jmp .6
..3: mov edx, edi
call CopyPseudoString
jc .e
jmp .6
..4: cmp ebx, 39
je .1 ; e' simbolo '
; qui r e' la prima lettera della stringa
; o pseudo stringa scritta: serve per scrivere B2
cmp ebx, '*'
jne .4a
cmp dword[esp+InParentesiQ], 0
jne .3a
cmp dword[esp+InParentesiTonde], 0
jne .3a
cmp dword[esp+InAsterisco], 1
jne .3b
..3a:
mov edx, edi
mov byte[edi], bl
inc esi
inc edi
jmp .6
..3b: mov dword[esp+ InAsterisco], 1
mov edx, edi
; B*j=' '|j>=[s+B1Limit]#.e|++j
mov byte[edi], '['
cmp edi, [esp+B1Limit]
jae .e
inc esi
inc edi
jmp .6
..e: mov eax, 1
stc
jmp .z
..4a:
..4b: cmp ebx, '^'
jne .5
mov edx, edi
mov eax, edi
add eax, 12
cmp edi, [esp+B1Limit]
jae .e
cmp dword[esp+ AD], 1
jne .4bb
mov dword[edi], " D[e"
add edi, 4
mov dword[edi], "sp+ "
add edi, 4
inc esi
jmp .6
..4bb: mov dword[edi], " dwo"
add edi, 4
mov dword[edi], "rd[e"
add edi, 4
mov dword[edi], "sp+ "
add edi, 4
inc esi
jmp .6
..5: cmp byte[MyTable+ebx], 3
jbe .5a ; scrive *tutto* anche i punti in B1
; solo le parole alfanumeriche possono
; utilizzare FindMacroWord()
mov edx, edi
cmp bl, '['
jne .3c
mov eax, dword[esp+ PrecPC]
cmp byte[eax], 'B'
je .3c
cmp byte[eax], 'W'
je .3c
cmp byte[eax], 'D'
je .3c
cmp byte[eax], 'Q'
je .3c
cmp byte[eax], 'T'
je .3c
mov byte[edi], ' '
cmp edi, [esp+B1Limit]
jae .e
inc edi
mov byte[edi], ' '
cmp edi, [esp+B1Limit]
jae .e
inc edi
..3c: mov [edi], bl
cmp edi, [esp+B1Limit]
jae .e
inc esi
inc edi
jmp .6
..5a: mov dword[esp+ 4], esi
push esi
call FindMacroWord
; r lunghezza della parola puntata da i
; a risultato della stringa in entrata
; c lunghezza del parametro precedente
; uso b
add esi, edx ; i e' aggiornato, r e' libero
mov bl, [eax]
cmp bl, '"'
je .4d
cmp bl, "'"
je .4d
mov edx, dword[esp+ PrecPC]
cmp edx, dword[esp+ 4]
je .5b ; sembra che r==^4 significa
cmp byte[edx], ','
je .4d ; la prima parola trattata
..4c: cmp byte[MyTable+ebx], 3
ja .5b ; controlla due alfanumeriche
cmp edx, 0
je .5b
mov bl, [edx]
cmp byte[MyTable+ebx], 3
ja .5b
..4d: mov byte[edi], ' '
mov edx, edi
cmp edi, [esp+B1Limit]
jae .e
inc edi
jmp short .5c
..5b: mov edx, edi
..5c: lea ebx, [edi+ecx]
cmp ebx, [esp+B1Limit]
jae .e
xor ebx, ebx
push ebp
push esi
push edx
mov ebp, ecx
mov esi, eax
call DCopy
pop edx
pop esi
pop ebp ; cambia solo c,a
add edi, eax ; aggiorna j
..6: cmp dword[esp+InWord], 0
je .8
..7: xor eax, eax
jmp .z
; Qui deve essere InWord==0
..ee: jmp .e
..8: mov dword[esp+InWord], 1
mov byte[ebp], 'õ'
cmp ebp, [esp+B2Limit]
jae .ee ; 1..64 sono 64 vettori
inc ebp
mov eax, dword[esp+ DaiNumeroP]
cmp eax, 0
je .ee
cmp eax, 64
ja .ee
inc dword[esp+ DaiNumeroP]
mov [ebp], al
cmp ebp, [esp+B2Limit]
jae .e
inc ebp ; mette un puntatore a inizio parola
lea ecx, [esp+80]
lea ecx, [ecx+eax*4]
mov [ecx], edx ; calcola da 76+4=80 poiche' l'indice
xor eax, eax ; parte da 1
..z:
%undef InParentesiTonde
%undef InParentesiQ
%undef AD
%undef NowPC
%undef PrecPC
%undef InWord
%undef B1Limit
%undef B2Limit
%undef DaiNumeroP
%undef PointerArray
ret


; u32 ToNasm(j:Destination, k:destinationSize, i:origin)
; c==0 Nasm, c==1 RosAsm
; in B*i vi e' il prossimo carattere da trattare
; a==eax==risultato della funzione
; se c!=0 nasm c==0 rosasm
; a& 1!=0: raggiunta la fine della linea con \n
; a& 2!=0: esiste la label
; a& 4!=0 [<=>CF==1] riscontrato errore
; a& 8!=0 commento
; a& 16!=0 commento doppio
; a& 32!=0 errore di parametro
; a& 64!=0 errore di copia
; a&128!=0 raggiunta la fine della istruzione con 0
; a&256!=0 raggiunta la fine della istruzione con "|", ";"
; a&512!=0 raggiunta la fine della istruzione per label
;
; j:Destination, k:destinationSize, vengono salvati nello stack
; nella routine: i:origin, b:LastChar, j=B1attuale, K=B2attuale
; in c vi e' la lunghezza della stringa scritta
; a,r sono libere
; 0, 4, 8, 12, 16, 20, 24, 28, 32, 36 variabili libere
; 40, 44, 48, 52, 56, 60, 64, 68, 72, 76
; 80, 84, ...,336 [64 puntatori]
; 340 ... 1364 [1024 Buffer1]
; 1368 ... 2040 [672 Buffer2]
; label: istruzione ; commento
ToNasm:
push edi
push ebp
sub esp, 2048 ; *s viene usato localmente ovunque anche in ScriviParola
%define PointerArray 76
%define DaiNumeroP 72
%define B1Limit 68
%define B2Limit 64
%define InParentesiTonde 60
%define InWord 56
%define PrecPC 52
%define Result 48
%define LetterCount 44
%define NowPC 40
%define InParentesiQ 36
%define InAsterisco 32
%define ParentesiTuttoFare 28
%define AD 24
%define NewLine 20
mov dword[esp+ Result], 0
mov dword[esp+ LetterCount], 0
mov dword[esp+ NowPC], 0
mov dword[esp+ PrecPC], 0
mov dword[esp+ AD], ecx
mov dword[esp+ NewLine], 0
xor ebx, ebx
call IsComment
jc .ee0
cmp eax, 1
je .f ; spostano j
call IsLabel
jc .ee0
cmp eax, 1
je .f ; il chiamante sa che e' tutta una linea
; quindi non esiste il bisogno di continuare
lea edi, [esp+340]
lea ebp, [esp+1368]
lea eax, [edi+1024]
lea edx, [ebp+672]
mov dword[esp+ B1Limit], eax
mov dword[esp+ B2Limit], edx
mov dword[esp+ InWord], 0
mov dword[esp+ DaiNumeroP], 1
mov dword[esp+ InParentesiTonde], 0
mov dword[esp+ InParentesiQ], 0
mov dword[esp+ InAsterisco], 0
mov dword[esp+ ParentesiTuttoFare], 0
jmp short .2
..ee0: xor ecx, ecx
..e: mov eax, dword[esp+ Result]
or eax, 4
stc
jmp .z ; non sposta j errore di buffer interno
..ej: mov ecx, edi
sub ecx, [esp+2052]
jmp short .e ; sposta j
..f: mov ecx, edi
sub ecx, [esp+2052] ; sposta j
mov eax, dword[esp+ Result]
clc
jmp .z
..1: call Next_ch
jc .ej ; aggorna "i" e "b"
..2: cmp ebx, ';'
je .1a
jmp .4
..1a: or dword[esp+Result], 256
cmp byte[esi], '|'
jne .2a ; incontrari ; oppure |
..3: inc esi
..2a: cmp dword[esp+InAsterisco], 0
je .3a
mov byte[edi], ']'
cmp edi, [esp+B1Limit]
jae .ej
inc edi
..3a: cmp dword[esp+InParentesiTonde], 0
jne .ej
cmp dword[esp+InParentesiQ], 0
jne .ej
mov byte[edi], 0
mov byte[ebp], 0 ; i vecchi j e k
lea edx, [esp+1368]
push edx
call FindMacro
call combine
jc .ej ; sposta j
; i nuovi j e k
; k j
mov ecx, [esp+2048]
mov edx, [esp+2052]
add ecx, edx
cmp dword[esp+ NewLine], 0
je .3ab
..3aa: mov byte[edi], 13
cmp edi, ecx
jae .ej
inc edi
mov byte[edi], 10
cmp edi, ecx
jae .ej
inc edi
mov byte[edi], 0
dec dword[esp+ NewLine]
jnz .3aa
..3ab: test dword[esp+ Result], 1
jnz .3b
cmp byte[esi], ';'
je .4b ; sposta j
cmp byte[esi], '/'
je .4b
cmp dword[esp+ AD], 2
jne .3b ; aggiunto RosAsm
mov byte[edi], ' '
cmp edi, ecx
jae .ej
inc edi
mov byte[edi], '|'
cmp edi, ecx
jae .ej
inc edi ; per \n
jmp short .4c
..3b:
mov eax, edi
add eax, 2
cmp eax, ecx
jae .ej

mov byte[edi], 13
inc edi
mov byte[edi], 10
inc edi
mov byte[edi], 0
jmp short .4c
..4b:
mov byte[edi], ' '
cmp edi, ecx
jae .ej
inc edi
..4c: mov ecx, edi
sub ecx, edx
jl .ej ; c= i caratteri scritti
jmp .f
..4: cmp ebx, 10
jne .5
or dword[esp+Result], 1
jmp .3
..5: cmp ebx, 13
jne .6
cmp byte[esi+1], 10
jne .6
inc esi
mov bl, [esi]
jmp short .4
..ee: jmp .ej ; "a|=b" "|=#.9"
..6: cmp ebx, 0
jne .5a
or dword[esp+Result], 128
jmp .2a
..5a: cmp ebx, '|'
jne .7
cmp dword[esp+InParentesiTonde], 0
jne .7
cmp byte[esi+1], '='
je .6a
..5b: inc dword[esp+ AD]
jmp .1a
..6a: cmp byte[esi+2], '#'
je .5b
..7: cmp ebx, '/'
jne .6b
cmp byte[esi+1], '*'
jne .6b
jmp .2a
..6b: cmp ebx, '\'
jne .4n
cmp byte[esi+1], 10
je .4d
cmp byte[esi+1], 13
je .4d
jmp short .4n
..4d: mov byte[esi], ' '
inc dword[esp+ NewLine]
cmp byte[esi+1], 13
jne .4e
mov byte[esi+1], ' '
jmp short .4f
..4e: cmp byte[esi+1], 10
jne .4f
mov byte[esi+1], ' '
..4f: cmp byte[esi+2], 13
jne .4g
mov byte[esi+2], ' '
jmp short .4h
..4g: cmp byte[esi+2], 10
jne .4h
mov byte[esi+2], ' '
..4h: call LevaSpaziDa_i
mov ebx, eax
jmp .2
..4n: cmp byte[MyTable+ebx], Punti
je .7a
jmp .m
..7a: cmp ebx, ','
jne .7c
cmp byte[esi+1], 10
jne .7b
mov byte[esi+1], ' '
inc dword[esp+ NewLine]
..6c: jmp .i ; NB qui cambia il vettore di "i"
..7b: cmp byte[esi+1], 13
jne .6c
cmp byte[esi+2], 10
jne .6c
inc dword[esp+ NewLine]
mov byte[esi+1], ' '
mov byte[esi+2], ' '
..7c: cmp dword[esp+InParentesiTonde], 0
je .b1
cmp ebx, ','
jne .a
jmp .i ; tratta virgola come punto
..a: cmp ebx, ')'
jne .b
mov dword[esp+ InParentesiTonde], 0
cmp dword[esp+ParentesiTuttoFare], 0
je .a1
mov dword[esp+ ParentesiTuttoFare], 0
..a0: mov [edi], bl
cmp edi, [esp+B1Limit]
jae .ee
inc edi
mov dword[esp+ InWord], 0
mov byte[edi], 0
cmp edi, [esp+B1Limit]
jae .ee
inc edi
jmp .1
..a1: jmp .i ; idem ')'
..b: jmp .o ; ma il resto e' parola
..b1: cmp dword[esp+InParentesiQ], 0
jne .b
cmp dword[esp+InAsterisco], 0
je .c

cmp ebx, '*'
je .b2
cmp ebx, '+'
je .b2
cmp ebx, '-'
je .b2
jmp short .b3
..b2: cmp byte[esi+1], '='
jne .c1
..b3: mov byte[edi], ']'
cmp edi, [esp+B1Limit]
jae .ee
inc edi
mov dword[esp+ InAsterisco], 0
jmp .i
..c: cmp ebx, '('
jne .c0
inc dword[esp+ InParentesiTonde]
mov eax, dword[esp+ PrecPC]
cmp eax, 0
je .b4
cmp byte[eax], '<'
je .b4
cmp byte[eax], ']'
je .b4
cmp byte[eax], '('
je .b4
xor edx, edx
mov dl, [eax]
cmp byte[MyTable+edx], 3
jbe .b4
mov dword[esp+ ParentesiTuttoFare], 1
jmp .o
..c0: cmp ebx, '*'
jne .c2
..c1: jmp .o
..b4: jmp .i
..c2: cmp ebx, '-'
jne .d
..c3: ; B[i+1]=='='#.i
xor eax, eax
mov al, [esi+1]
cmp byte[MyTable+eax], 0
jne .b4
mov al, [esi-1]
cmp byte[MyTable+eax], Space
jne .c1
mov byte[edi], ' '
cmp edi, [esp+B1Limit]
jae .e0
inc edi
mov byte[edi], 0
jmp .o
..d: cmp ebx, '+'
je .c3
cmp ebx, '^'
jne .i
cmp byte[esi+1], '='
je .i

mov dword[esp+ InAsterisco], 1
jmp .o
..i: cmp dword[esp+InWord], 0
je .l ; finiesce la parola precedente
..i0: mov dword[esp+ InWord], 0
mov byte[edi], 0
cmp edi, [esp+B1Limit]
jae .e0
inc edi
..l: mov [ebp], bl
cmp ebp, [esp+B2Limit]
jae .e0
inc ebp
jmp .1
..e0: jmp .ej
..m: ; gli altri casi non punti
cmp ebx, '['
jne .n
inc dword[esp+ InParentesiQ]
jmp short .o
..n: cmp ebx, ']'
jne .o
dec dword[esp+ InParentesiQ]
jmp .a0
..o: call ScriviParola
jc .e0
call First_ch
jmp .2
..z:
%undef ParentesiTuttoFare
%undef AD
%undef NewLine
%undef LetterCount
%undef NowPC
%undef InParentesiQ
%undef InAsterisco
%undef InParentesiTonde
%undef InWord
%undef PrecPC
%undef Result
%undef PointerArray
%undef DaiNumeroP
%undef B1Limit
%undef B2Limit
lea esp, [esp+2048]
pop ebp
pop edi
ret


; CopyUntil10Or0_jki(j,k,i)
; Copia la stringa di i, in j di size k
; se errore ritorna 0 altrimenti ritorna
; 1 se incontra \n
; 128 se incontra \0
CopyUntil10Or0_jki:
xor eax, eax
cmp ebp, 0
jne .1
..e: mov byte[edi], 0
xor eax, eax
stc
jmp short .z
..0: inc esi
inc edi
..1: mov al, [esi]
mov [edi], al
..2: dec ebp
jz .e
cmp eax, 0
je .3
cmp eax, 10
jne .0
inc esi
inc edi
dec ebp
jz .e
mov byte[edi], 0
mov eax, 1
jmp short .4 ; trovato \n
..3: mov eax, 128 ; trovato \0
..4: clc
..z:
ret


; VaiUntil10Or0_i()
; Copia la stringa di i, in j di size k
VaiUntil10Or0_i:
xor eax, eax
jmp short .1
..0: inc esi
..1: mov al, [esi]
..2: cmp eax, 0
je .3
cmp eax, 10
jne .0
inc esi
mov eax, 1
jmp short .z
..3: mov eax, 128
..z:
ret


; u32 LineToNasm(u8* dest, u32 dsize, u8* origin, u32 commento)
; come risultato ecx, caratteri scritti in j
; edx, caratteri di avanzamento di i
; a==eax==risultato della funzione
; a& 1!=0 raggiunta la fine della istruzione con \n
; a& 2==0 nessuna label nell'istruzione
; a& 2!=0 esiste la label
; a& 4==0 [<=>CF==0] nessun errore trovato
; a& 4!=0 [<=>CF==1] riscontrato errore
; a& 8!=0 commento semplice
; a& 16!=0 commento doppio
; a& 32!=0 errore di parametro
; a& 64!=0 errore di copia
; a&128!=0 raggiunta la fine della istruzione con 0
; a&256!=0 raggiunta la fine della istruzione con "|", ";"
; a&512!=0 raggiunta la fine della istruzione per label
; 0k,4j,8i,12b,16ra,20P_d,24P_dsize,28P_or,32P_comm
; j:Destination, k:destinationSize, i:origin, b:LastChar
; section, SECTION, %define, %undef: copia tutta la linea e esce
; usare come
; a=1; W(1){c=fgets(o,osize,fp)
; a=LineToNasm(d, ds, o, a);
; fputs(fp,d);
; if(c==EOF) break;
; }
LineToNasm:
push ebx
push esi
push edi
push ebp
mov edi, [esp+20]
mov ebp, [esp+24]
mov esi, [esp+28]
xor ebx, ebx
cmp edi, 0
je .e1
cmp ebp, 0
jle .e1
mov byte[edi], 0
xor eax, eax
cmp esi, 0
jne .1
..e1: or eax, 32
..e: or eax, 4
sub esi, [esp+28]
sub edi, [esp+20]
mov edx, esi
mov ecx, edi
test dword[esp+32], 16
jz .eee
or eax, 16
..eee: stc
jmp .z
..e2: or eax, 64
jmp short .e
..f0: sub esi, [esp+28]
sub edi, [esp+20]
mov edx, esi
mov ecx, edi
..f: clc
jmp .z
..f2: or eax, ebx
jmp short .f0 ; a=2 linea con ";" a=3 ";;"
..0: inc esi
..1: mov bl, [esi]
cmp byte[MyTable+ebx], Space
je .0
cmp ebx, 10
jne .1b
..1a: call CopyUntil10Or0_jki
jc .e2
mov ebx, [esp+32]
and ebx, 0FFFFFC10h
or eax, ebx
jmp short .f0
..1b: cmp ebx, 13
jne .1c
cmp byte[esi+1], 10
je .1a
..1c: cmp byte[MyTable+ebx], 5
je .f0
cmp ebx, ';'
jne .4
mov ebx, 8
cmp byte[esi+1], ';'
jne .3a
; caso ";;" trovato anche prima: D[s+32]&16!=0
..1c0: test dword[esp+32], 16
jnz .1d
mov ebx, 16
jmp short .2a
..1d:
mov ebx, 8
jmp short .2a
..2: mov ebx, 16
..3: cmp byte[esi], ';'
je .2a
mov byte[edi], ';'
dec ebp
jz .e2
inc edi
mov byte[edi], ' '
dec ebp
jz .e2
inc edi
..2a: call CopyUntil10Or0_jki
jc .e2
jmp .f2
; caso ";" ora e ";;" prima oppure no
..3a: cmp byte[esi+1], '*'
je .1c0
mov ebx, 16
test dword[esp+32], 16
jnz .3
mov ebx, 8
jmp short .3
..4: test dword[esp+32], 16
jnz .2
..5: mov eax, [esi]
mov edx, [esi+4]
; b e' il primo carattere effettivo
cmp ebx, 's'
jne .7
cmp eax, "sect"
jne .a
cmp edx, "ion "
jne .a ; viene vista come commento
..6: mov ebx, 8
call CopyUntil10Or0_jki
jc .e2
jmp .f2
..7: cmp ebx, 'S'
jne .8
cmp eax, "SECT"
jne .a
cmp edx, "ION "
je .6
..8: cmp ebx, '%'
je .6
; j destination, i origin, b last char,
..a: mov ecx, 0
call ToNasm
add edi, ecx
sub ebp, ecx
jle .e
test eax, 4
jnz .b
test eax, 128
jnz .a0
test eax, 1
jnz .a0
test eax, 2
jnz .a0
cmp ecx, 0
jne .a
; B*i#.a
..a0: sub esi, [esp+28]
sub edi, [esp+20]
mov edx, esi
mov ecx, edi
jmp .f
..b: sub esi, [esp+28]
sub edi, [esp+20]
mov edx, esi
mov ecx, edi
jmp .eee
..z:
pop ebp
pop edi
pop esi
pop ebx
ret 16


; DCmp(j,i,k)
; compara i di len k, con j terminato da 0
; Se 0 CF==0 allora la stringa i con
; l'array di lunghezza fissa j sono uguali
; altrimenti sono diversi
DCmp:
mov ecx, ebp
xor edx, edx
and ecx, 0FFFFFFFCh
jz .3
jmp short .1
..n: mov eax, -1
stc
jmp short .z
..1: mov eax, [edi+edx]
cmp eax, [esi+edx]
jne .n
add edx, 4
..2: cmp edx, ecx
jb .1
..3: mov ecx, ebp
and ecx, 3
jz .5
add ecx, edx
..4: mov al, [edi+edx]
cmp al, [esi+edx]
jne .n
inc edx
cmp edx, ecx
jb .4
..5: xor eax, eax
mov al, [edi+edx]
cmp byte[MyTableR+eax], 0
je .n
xor eax, eax
..z:
ret

; DCmp_old(j,i,k)
; compara i di len k, con j terminato da 0
; Se 0 CF==0 allora la stringa i con
; l'array di lunghezza fissa j sono uguali
; altrimenti sono diversi
DCmp_old:
mov ecx, ebp
xor edx, edx
and ecx, 0FFFFFFFCh
jz .3
jmp short .1
..n: mov eax, -1
stc
jmp short .z
..1: mov eax, [edi+edx]
cmp eax, [esi+edx]
jne .n
add edx, 4
..2: cmp edx, ecx
jb .1
..3: mov ecx, ebp
and ecx, 3
jz .5
add ecx, edx
..4: mov al, [edi+edx]
cmp al, [esi+edx]
jne .n
inc edx
cmp edx, ecx
jb .4
..5: ; B[j+r]!=0#.n
xor eax, eax
..z:
ret


; DCopy(j,i,k)
; Copia la stringa di i di lunghezza [len] k, in j
; ritorna la lunghezza della stringa
; modifica c,a,r
DCopy:
mov ecx, ebp
xor eax, eax
and ecx, 0FFFFFFFCh
jz .3
..1: mov edx, [esi+eax]
mov [edi+eax], edx
add eax, 4
..2: cmp eax, ecx
jb .1
..3: mov ecx, ebp
and ecx, 3
jz .5
add ecx, eax
..4: mov dl, [esi+eax]
mov [edi+eax], dl
inc eax
cmp eax, ecx
jb .4
..5: mov byte[edi+eax], 0 ; non necessario?
clc
..z:
ret


; find macro per parole alfanumeriche
; all'interno a stringhe
; u8* FindMacroWord(u8* name)
; ritorna c=a=0 CF=1 se errore di parametro
; ----------------------------------------
; ritorna a=name, c=lenUntilNotLetter(name)
; CF=1 se non trovato nel lookup
; r=strlen(name)
; ----------------------------------------
; ritorna a=def, c=strlen(def), CF=0
; se e' trovato nel lookup
; r=strlen(name)
; ----------------------------------------
; 0k,4j,8i,12b,16ra,20P_name
FindMacroWord:
push ebx
push esi
push edi
push ebp
%define nx 0
%define nm 4
%define df 8
%define dfl 12
mov esi, [esp+20]
cmp dword[hashtab], 0
je .e0
cmp esi, 0
jne .1
..e0: xor eax, eax
xor ecx, ecx
..e: stc
jmp short .z
..e1: mov eax, esi
mov ecx, ebp
mov edx, ebp
jmp short .e
..0: mov eax, [ebx+df]
mov ecx, [ebx+dfl]
mov edx, ebp
clc
jmp short .z
..1: push esi
call HashWord
mov ebp, ecx ; in k la lunghezza di i
mov ecx, [hashtab]
lea eax, [ecx+edx*4]
mov ebx, [eax]
cmp ebx, 0
je .e1 ; non trovato
..2: mov edi, [ebx+4]
cmp edi, 0
je .e1 ; senza stringa???
call DCmp
jnc .0 ; cmp(i:lenk, j:string)
..4: mov edx, ebx
mov ebx, [edx]
cmp ebx, 0
jne .2
jmp short .e1
..z:
%undef nx
%undef nm
%undef df
%undef dfl
pop ebp
pop edi
pop esi
pop ebx
ret 4


; a*31=a*(32-1)=a*32-a
; ritorna il valore di hash della parola alfanumerica
; puntata da b. in ogni caso edx==eax alla fine della funzione
; e in ecx vi e' la lunghezza della parola alfanumerica "name"
; u32 HashWord(u8* name)
; 0i,4b,8ra,12P_s
HashWord:
push ebx
push esi
mov ebx, [esp+12]
xor eax, eax
xor ecx, ecx
xor edx, edx
mov esi, 8
cmp ebx, 0
jne .2
..e: stc
jmp short .z
..0: mov cl, [ebx]
cmp byte[MyTable+ecx], 3
ja .3
inc ebx
jmp short .0
..1: inc ebx
dec esi
jz .0 ; a*31=a*32-a
mov edx, eax
shl eax, 5
add eax, ecx
sub eax, edx
..2: mov cl, [ebx]
cmp byte[MyTable+ecx], 3
jbe .1
..3: mov edx, [esp+12]
mov ecx, HASHSIZE
sub ebx, edx
shl eax, 4 ; in b e' len
xor edx, edx
add eax, ebx
div ecx
mov eax, edx
mov ecx, ebx ; eax==edx==valore di hash
clc ; c=strlen(name)
; notare che in "< ss" la lunghezza tornata
..z: ; è zero infatti "<" non è alfanumerico
pop esi
pop ebx
ret 4


; 0i,4ra,8P_a
AtoI:
push esi
mov edx, [esp+8]
xor eax, eax
xor ecx, ecx
cmp edx, 0
je .e
mov cl, [edx]
cmp byte[MyTable+ecx], 0
je .2
..e: mov eax, -1
stc
jmp short .z ; 10a=(4a+a)*2
..1: inc edx
mov cl, [edx]
cmp byte[MyTable+ecx], 0
jne .3
test eax, 0C0000000h
jnz .e
mov esi, eax
shl eax, 2
add eax, esi
jc .e
add eax, eax
jc .e
..2: sub ecx, '0'
add eax, ecx
jnc .1
jmp short .e
..3: clc
..z:
pop esi
ret 4


; u32 Undef(u8* name)
; 0i,4b,8ra,12P_name
Undef:
push ebx
push esi
%define nx 0
mov ebx, [esp+12]
cmp ebx, 0
jne .1
..e: mov eax, 1
jmp short .z ; in r precedente [compreso puntatore di hash]
..1: push ebx
call Lookup ; in a attuale
cmp eax, 0
je .e
mov ecx, [eax+nx]
mov [edx+nx], ecx
push eax
call FreeNodo
jc .e
; qui a==0 ed CF==0
..z:
%undef nx
pop esi
pop ebx
ret 4



; input in eax vi sta l'indice
; risultato in eax: posizione dell'indice
; a*16
; 0 1 2
; |0,0,0,0|0,0,0,0|0,0,0,0|


; u32* AllocNodo()
AllocNodo:
push ebx
mov ecx, [TheNext]
mov ebx, [NodeMem]
cmp ecx, 512
jae .e
cmp ebx, 0
jne .1
..e: xor eax, eax
stc
jmp short .z
..0: mov eax, ebx
jmp short .3
..1: shl ecx, 4
mov edx, 8192
lea eax, [ebx+ecx]
lea ecx, [ebx+edx]
mov edx, eax ; r=a=*TheNext
..2: cmp dword[eax+4], 0
je .4 ; c=NodeMem+512*4*4=
add eax, 16
cmp eax, ecx
je .0 ; =NodeMem+8192 Nodo limite
..3: cmp eax, edx
jne .2
jmp short .e
..4: mov ecx, eax
mov dword[eax+4], 1
sub eax, ebx
shr eax, 4
inc eax
cmp eax, 512
jne .5
mov eax, 0
..5: mov [TheNext], eax
mov eax, ecx
clc
..z:
pop ebx
ret

; u32 FreeNodo(u32* node)
; 0,12,24,36
; 0i,4b,8ra,12P_node
FreeNodo:
push ebx
push esi
%define nx 0
%define nm 4
%define df 8
%define dfl 12
mov ebx, [esp+12]
cmp ebx, 0
jne .1
..e: mov eax, 1
stc
jmp short .z
..1: mov edx, [NodeMem]
cmp ebx, edx
jb .e
mov esi, edx
mov eax, 512
shl eax, 4 ; k*16
add esi, eax
cmp ebx, esi
jae .e
mov eax, ebx
sub eax, edx
test eax, 0Fh
jnz .e ; non allineato
mov dword[ebx+nx], 0
mov dword[ebx+nm], 0
mov dword[ebx+df], 0
mov dword[ebx+dfl], 0
shr eax, 4
mov [TheNext], eax
xor eax, eax
..z:
%undef nx
%undef nm
%undef df
%undef dfl
pop esi
pop ebx
ret 4

; Struttura della tavola di Hash
; hashtable
; 0
; p-->|nx--->|nx=0
; 0 |nm |nm <---nodes
; 0 |df |df
; 0 |dfl |dfl
; 0
; p-->|nx=0
; 0 |nm
; 0 |df
; 0 |dfl


FreeMem:
push esi
push edi
mov esi, [NodeMem]
mov edi, [hashtab]
push esi
call Free_sys
push edi
call Free_sys
mov dword[NodeMem], 0
mov dword[hashtab], 0
mov dword[TheNext], 0
mov esi, [StringPointers]
cmp esi, 0
je .9
cmp dword[PointerSize], 0
jle .9
xor edi, edi
..1: mov eax, [esi+edi*4]
push eax
call Free_sys
inc edi
cmp edi, [PointerSize]
jb .1
..9: push esi
call Free_sys
mov dword[PointerSize], 0
mov dword[TheNextPointer], 0
mov dword[StringPointers], 0
mov dword[MacroDefinizioniGeneraliLed], 0
mov dword[NasmDefLed], 0
mov dword[RosAsmDefLed], 0
pop edi
pop esi
ret

; InstalMacro(u8* Def, u8* Sost, u32 delimtatore)
; il delimitatore vale solo per trovare sost
; il delimitatore per def e' lo spazio: la prima
; parola e' presa
; InstalMacro(b,i,0)|jc .e
; il delimitatore e' 0 => prende sost fino a \0
; InstalMacro(b,i,1)|jc .e
; il delimitatore e' 1 => prende sost fino allo spazio successivo
; 0k,4j,8i,12b,16ra,20P_Def,24P_Sost, 28P_delim +64
; 84 88 92
InstalMacro:
push ebx
push esi
push edi
push ebp
sub esp, 64
mov eax, [TheNextPointer]
mov ebp, [StringPointers]
mov ecx, eax
cmp ebp, 0
je .e
cmp eax, [PointerSize]
jl .3
..e: xor eax, eax
stc
jmp .z
..0: inc eax
cmp eax, [PointerSize]
jne .1
xor eax, eax
..1: cmp ecx, eax
je .e
..3: mov edx, [ebp+eax*4]
cmp edx, 0
jne .0
mov edi, eax
mov esi, dword[esp+ 84]
call WordLen_i
cmp ecx, 0
jle .e
mov ebx, ecx
mov esi, dword[esp+ 88]
cmp dword[esp+ 92], 0
jne .3a
call LenStr_i
cmp ecx, 0
jle .e
jmp short .3b
..3a:
call WordLen_i
cmp ecx, 0
jle .e
..3b: add ebx, ecx
jle .e
add ebx, 8
jle .e
push ebx
call Malloc_sys
cmp eax, 0
je .e
mov [ebp+edi*4], eax ; conserva il vettore nell'int_array
inc edi ; StringPointers
cmp edi, [PointerSize]
jb .4
xor edi, edi
..4: mov [TheNextPointer], edi
mov ebp, ebx
sub ebp, 2
mov [esp], eax
mov edi, eax
mov esi, dword[esp+ 84]
call PrendiWord_jki
jc .e
inc edi
dec ebp
jle .e
mov dword[esp+ 4], edi
mov esi, dword[esp+ 88]
cmp dword[esp+ 92], 0
jne .5
call CopyLine_jki
jc .e
jmp short .6
..5:
call PrendiWord_jki
jc .e
..6: mov eax, [esp]
mov edx, dword[esp+ 4]
push edx
push eax
call Install
jc .e
..z:
lea esp, [esp+64]
pop ebp
pop edi
pop esi
pop ebx
ret 12


; input export one, two, none
; 0i,4r,8c,12b,16ra,20P_Str
PushExport:
push ebx
push ecx
push edx
push esi
mov esi, dword[esp+ 20]
xor eax, eax
cmp esi, 0
jne .1
..e: stc
jmp .z
..0: clc
jmp .z
..1: mov eax, [esi]
cmp eax, "expo"
jne .e
mov edx, [esi+4]
and edx, 000FFFFFFh
cmp edx, "rt "
jne .e
..2: call FindNextWord_i
cmp eax, 0
je .e
cmp eax, 10
je .e
cmp eax, 13
je .e
push 1
push esi
push esi
call InstalMacro
jc .e
call FindNextWord_i
cmp eax, 0
je .0
cmp eax, 10
je .0
cmp eax, 13
je .0
cmp eax, ','
je .2
jmp short .e
..z:
pop esi
pop edx
pop ecx
pop ebx
ret 4


; input %define one two
; input << a=b, c=d
; 0i,4b,8ra,12P_Str + 1024
PushMacro:
push ebx
push esi
sub esp, 1024
mov esi, [esp+1036]
xor eax, eax
cmp esi, 0
jne .1
..e: stc
jmp .z
..1: mov al, byte[esi]
cmp eax, '%'
jne .2
mov eax, [esi]
mov edx, [esi+4]
cmp eax, "%def"
jne .e
cmp edx, "ine "
jne .e
call FindNextWordTraSPazi_i
cmp eax, 0
je .e
mov ebx, esi
call FindNextWordTraSPazi_i
cmp eax, 0
je .e
push 0
push esi
push ebx
call InstalMacro
jc .e
..1a: jmp .9
..2: mov eax, [esi]
and eax, 00000FFFFh
cmp eax, "<<"
jne .e
jmp short .4
..3: call FindNextWord_i
cmp eax, 0
je .1a ; parola
cmp eax, ','
jne .e
..4: call FindNextWord_i
cmp eax, 0
je .e ; parola
mov al, byte[esi]
cmp byte[MyTableR+eax], 0
jne .e
mov ebx, esi
call FindNextWord_i
cmp eax, '='
jne .e ; =
call FindNextWord_i
cmp eax, 0
je .e ; parola
mov al, byte[esi]
cmp byte[MyTableR+eax], 0
jne .e
xor eax, eax
mov edx, ebx
lea ecx, [esp+8]
mov dword[esp], ecx
add dword[esp], 1000
jmp short .5a
..5: inc edx
inc ecx
cmp ecx, [esp]
jae .e
..5a: mov al, [edx]
mov [ecx], al
cmp eax, 0
je .6
cmp byte[MyTableR+eax], 0
je .5
mov byte[ecx], 0
..6: inc ecx
mov ebx, ecx
jmp short .7a ; "b" e' il secondo s+8 e'primo
..7: inc esi
inc ecx
cmp ecx, [esp]
jae .e
..7a: mov al, [esi]
mov [ecx], al
cmp eax, 0
je .8
cmp byte[MyTableR+eax], 0
je .7
mov byte[ecx], 0
dec esi ; punta un carattere prima la virgola
..8: lea eax, [esp+8]
push 1
push ebx
push eax
call InstalMacro
jc .e
jmp .3
..9: clc
..z:
lea esp, [esp+1024]
pop esi
pop ebx
ret 4

; 0j,4ra,8P_Str
FreeIfFindAddressInString:
push edi
xor eax, eax
mov edi, [StringPointers]
mov ecx, dword[esp+ 8]
cmp edi, 0
je .e
cmp dword[PointerSize], 0
jg .3
..e: xor eax, eax
stc
jmp short .z
..0: inc eax
cmp eax, [PointerSize]
je .e
..3: mov edx, [edi+eax*4]
cmp edx, ecx
jne .0
push eax
push edx
call Free_sys
pop eax
jc .e
mov dword[edi+eax*4], 0
mov [TheNextPointer], eax
..z:
pop edi
ret 4


; 0i,4b,8ra,12P_Str + 1024
; 1036
UndefMacro:
push ebx
push esi
sub esp, 1024
%define nx 0
%define nm 4
%define df 8
mov ebx, [esp+1036]
cmp ebx, 0
jne .1
..e: mov eax, 1
stc
jmp short .z ; in r precedente [compreso puntatore di hash]
..1: mov edx, esp
mov ecx, 1020
add ecx, edx
xor eax, eax
..2: mov al, [ebx]
cmp byte[MyTableR+eax], 0
jne .3
cmp eax, 0
je .3
mov [edx], al
inc edx
inc ebx
cmp edx, ecx
jae .e
jmp short .2
..3: mov byte[edx], 0
mov eax, esp
push eax
call Lookup ; in a attuale
cmp eax, 0
je .e
mov ecx, [eax+nx]
mov [edx+nx], ecx
mov ebx, [eax+nm]
push eax
call FreeNodo
jc .e
; qui a==0 ed CF==0
push ebx
call FreeIfFindAddressInString
jc .e
..z:
lea esp, [esp+1024]
%undef nx
%undef nm
%undef df
pop esi
pop ebx
ret 4

; input %undef one
; input >> a,b, c, d
; 0i,4b,8ra,12P_Str
PopMacro:
push ebx
push esi
mov esi, [esp+12]
xor eax, eax
cmp esi, 0
jne .1
..e: stc
jmp .z
..1: mov al, byte[esi]
cmp eax, '%'
jne .2
mov eax, [esi]
mov edx, [esi+4]
and edx, 000FFFFFFh
cmp eax, "%und"
jne .e
cmp edx, "ef "
jne .e
inc esi
call FindNextWordTraSPazi_i
cmp eax, 0
je .e
push esi
call UndefMacro
jmp short .z
..2: mov eax, [esi]
and eax, 00000FFFFh
cmp eax, ">>"
jne .e
..3: call FindNextWord_i
cmp eax, 0
je .e
..4: mov al, byte[esi]
cmp byte[MyTableR+eax], 0
jne .e
push esi
call UndefMacro
jc .e
call FindNextWord_i
cmp eax, 0
je .5
cmp eax, ','
jne .e
jmp short .3
..5: clc
..z:
pop esi
pop ebx
ret 4

; u32 Install(u8* name, u8* defn)
; name e defn devono essere stringhe
; che vengono deallocate alla fine del programma
; se ritorna 0 [<=>CF==1] errore
; altrimenti ok ed in eax vi e'
; l'indirizzo del nodo istallato
; 0j,4i,8ra,12P_name,16P_defn
Install:
push esi
push edi
%define nx 0
%define nm 4
%define df 8
%define dfl 12
mov esi, [esp+12]
mov edi, [esp+16]
cmp esi, 0
je .e
cmp edi, 0
jne .1
jmp short .e
..0: call FreeMem
..e: xor eax, eax
stc
jmp .z
..1: cmp dword[hashtab], 0
jne .a
; HASHSIZE=4019
; (4019+1)*4= 16080
push 16080
call Malloc_sys
cmp eax, 0
je .0
mov [hashtab], eax
push 16080
push eax
call Zero
..a: cmp dword[StringPointers], 0
jne .b
; 2048 * 4 = 8192
push 8192
call Malloc_sys
cmp eax, 0
je .0
mov [StringPointers], eax
mov dword[TheNextPointer], 0
mov dword[PointerSize], 2048
push 8192
push eax
call Zero
..b: cmp dword[NodeMem], 0
jne .i
; 512 * 4 * 4 = 8192
; Serbatoio di 512 nodi di 4 u32
push 8192
call Malloc_sys
cmp eax, 0
je .0
mov [NodeMem], eax
mov dword[TheNext], 0
push 8192
push eax
call Zero
..i: push esi
call Lookup
jc .5
; point to next:nx puntatore
; name:nm nome
; defn:df definizione
; defnlen:dfl lenDefinizione
; << nx=0, nm=4, df=8, dfl=12
; u32* Lookup(u8* name)
; ritorna a=0 CF==1, hashtab posizi. nodo in edx
; strlen(name) in ecx
; se non troavato
; -----------------------------------------
; altrimenti l'indirizzo del nodo trovato in eax
; l'indirizzo del precedente in edx
; strlen(name) in ecx

; Nodo trovato
cmp eax, 0
je .e ; se Lookup ok => a==c
..2: mov [eax+df], edi
jmp short .4 ; Caso: Nodo Esistente
..3: inc edi ; => sovrascrivi
..4: cmp byte[edi], 0
jne .3
sub edi, [eax+df]
mov [eax+dfl], edi
clc
jmp short .z

..5: push edx
call AllocNodo
pop edx ; r indirizzo di Hash
jc .e
mov ecx, [edx]
mov [eax+nm], esi
mov [eax+nx], ecx
mov [edx], eax
jmp short .2 ; a indirizzo nodo
..z:
%undef nx
%undef nm
%undef df
%undef dfl
pop edi
pop esi
ret 8

; 0i,4b,8ra,12P_w
Installl:
push ebx
push esi
mov ebx, [esp+12]
mov esi, ebx
jmp short .2
..1: inc esi
..2: cmp byte[esi], 0
jne .1
..1a: inc esi
..1b: cmp byte[esi], 0
je .1a
push esi
push ebx
call Install
jnc .4
..e: mov eax, -1
stc
jmp short .z
..3: inc esi
..4: cmp byte[esi], 0
jne .3
..4a: inc esi
..4b: cmp byte[esi], 0
je .4a
mov ebx, esi
cmp byte[esi], 0FFh
jne .2
xor eax, eax
clc
..z:
pop esi
pop ebx
ret 4

InstallGenerali:
clc
cmp dword[MacroDefinizioniGeneraliLed], 0
jne .z
push MacroDefinizioniGenerali
call ConvertiNumeriTavola
jc .z
push MacroDefinizioniGenerali
call Installl
jc .z
mov dword[MacroDefinizioniGeneraliLed], 1
..z:
ret

InstallNasm:
clc
cmp dword[MacroDefinizioniGeneraliLed], 0
jne .0
push MacroDefinizioniGenerali
call SostituisciSbarraCon13_10
jc .z
push MacroDefinizioniGenerali
call ConvertiNumeriTavola
jc .z
push MacroDefinizioniGenerali
call Installl
jc .z
mov dword[MacroDefinizioniGeneraliLed], 1
..0: cmp dword[NasmDefLed], 0
jne .z
push NasmDef
call SostituisciSbarraCon13_10
jc .z
push NasmDef
call ConvertiNumeriTavola
jc .z
push NasmDef
call Installl
jc .z
mov dword[NasmDefLed], 1
..z:
ret

InstallRos:
clc
cmp dword[MacroDefinizioniGeneraliLed], 0
jne .0
push MacroDefinizioniGenerali
call ConvertiNumeriTavola
jc .z
push MacroDefinizioniGenerali
call Installl
jc .z
mov dword[MacroDefinizioniGeneraliLed], 1
..0: cmp dword[RosAsmDefLed], 0
jne .z
push RosAsmDef
call ConvertiNumeriTavola
jc .z
push RosAsmDef
call Installl
jc .z
mov dword[RosAsmDefLed], 1
..z:
ret

FreeTab:
push esi
push edi
push ebp
%define nx 0
mov esi, [hashtab]
mov eax, HASHSIZE
cmp esi, 0
je .z
lea ebp, [esi+eax*4]
..1: mov edx, [esi]
cmp edx, 0
je .3
..2: mov edi, [edx+nx]
push edx
call FreeNodo
mov edx, edi
cmp edi, 0
jne .2
..3: add esi, 4
cmp esi, ebp
jb .1
mov dword[MacroDefinizioniGeneraliLed], 0
mov dword[NasmDefLed], 0
mov dword[RosAsmDefLed], 0
..z:
%undef nx
pop ebp
pop edi
pop esi
ret

; parametri i la stringa da leggere
; j la stringa da scrivere
; c la size di j
;
; il primo carattere puntato da i
; deve essere " oppure '
; in j scrive in i legge
; il numero di carattere di j e' c
; aggiorna sia i sia j, il numero di
; caratteri avanzati si trova in a
; modifica a,r i,j
PrendiNomeTraVirgoletteDa_i:
push ecx
xor eax, eax
xor edx, edx
cmp ecx, 0
mov dl, [esi]
jl .e
cmp edx, '"'
je .1
cmp edx, "'"
je .1
jmp short .e
..ee: mov eax, [esp]
sub eax, ecx
mov byte[edi], 0
..e: stc
jmp short .z
..0: inc esi
inc edi
dec ecx
jz .ee
..1: mov al, [esi]
mov [edi], al
cmp eax, 0
je .3
cmp eax, edx
jne .0
inc esi
inc edi
dec ecx
mov eax, [esp]
sub eax, ecx
..3: mov byte[edi], 0
clc
..z:
pop ecx
ret


; parametri i la stringa da leggere
; j la stringa da scrivere
; c la size di j
;
; il primo carattere puntato da i
; deve essere un non spazio
; il loop finisce se trova uno spazio
; oppure la stringa in i finisce.
; in j scrive in i legge
; il numero di carattere letti in i
; scritti in j e' eax
; aggiorna sia i sia j, il numero di
; caratteri avanzati si trova in a
; modifica a,i,j
PrendiNomeTraSpaziDa_i:
push ecx
xor eax, eax
cmp ecx, 0
jl .e
jmp short .1
..ee: mov eax, [esp]
sub eax, ecx
mov byte[edi], 0
..e: stc
jmp short .z
..0: inc esi
inc edi
dec ecx
jz .ee
..1: mov al, [esi]
mov [edi], al
cmp eax, 0
je .3
cmp byte[MyTable+eax], Space
jne .0
..3: mov byte[edi], 0
..z:
pop ecx
ret


; In i vi e' il nome
; In j vi e' dove lo si vuole scrivere
; In c vi e' la dimensione di j
; modifica a,r,c i,j
PrendiNomeDa_i:
call LevaSpaziDa_i
mov al, [esi]
cmp eax, '"'
jne .1
..0: call PrendiNomeTraVirgoletteDa_i
jmp short .2
..1: cmp eax, "'"
je .0
call PrendiNomeTraSpaziDa_i
..2:
ret


; a=1File, r=2File
;
MacroNasm:
push ebx
push esi
push edi
push ebp ; 400 FileLine=656..1680 size=1024
sub esp, 2048 ; b1=128..384, b2=392..648 size=256
%define InpHandle 16
%define OutHandle 20
%define MemFile 24
%define InpFName 128
%define OutFName 392
%define FileLine 656
%define FileSize 28
%define MemLimit 44
mov esi, eax
mov ebx, edx
call InstallNasm
jc .e
lea edi, [esp+InpFName]
mov ecx, 256
call PrendiNomeDa_i
jc .e1
mov esi, ebx
lea edi, [esp+OutFName]
mov ecx, 256
call PrendiNomeDa_i
jnc .1
..e1: mov eax, 1

..e: call FreeMem
stc
jmp .z
..e2: mov eax, 2
jmp short .e ; errore di file input
..e5: mov edx, [esp+OutHandle]
push edx
call FlushCloseHandle
..e4: mov eax, [esp+MemFile]
push eax
call Free_sys
..e3: mov edx, [esp+InpHandle]
push edx
call CloseHandle
mov eax, ebx
jmp short .e ; errore di file output
..1: ; Apri file di input
lea edx, [esp+InpFName]
push 0
push FILE_ATTRIBUTE_NORMAL
push OPEN_EXISTING
push 0
push 0
push GENERIC_READ
push edx
call CreateFileA
mov [esp+InpHandle], eax

mov ebx, 3
cmp eax, INVALID_HANDLE_VALUE
je .e2
mov ebx, 4
mov edx, esp
push edx
push eax
call GetFileSize
cmp eax, -1
je .e3
cmp dword[esp], 0
jne .e3
mov ebx, 5
mov dword[esp+ FileSize], eax
add eax, 64
push eax
call Malloc_sys
cmp eax, 0
je .e3
mov [esp+MemFile], eax
mov edx, dword[esp+ FileSize]
mov dword[esp+ MemLimit], eax
add dword[esp+ MemLimit], edx
add edx, 32
mov dword[eax+edx], 0 ; per essere sicuri che termini
lea edx, [esp+OutFName]
mov ebx, 6 ; line to nasm
push 0
push FILE_ATTRIBUTE_NORMAL
push CREATE_ALWAYS
push 0
push 0
push GENERIC_WRITE
push edx
call CreateFileA
mov [esp+OutHandle], eax

cmp eax, INVALID_HANDLE_VALUE
je .e4
mov edx, dword[esp+ InpHandle]
mov ecx, dword[esp+ FileSize]
add ecx, 32
mov esi, dword[esp+ MemFile]
mov eax, esp
mov ebx, 7
push 0
push eax
push ecx
push esi
push edx
call ReadFile
cmp eax, 0
je .e5
mov ecx, [esp]
cmp [esp+FileSize], ecx
jne .e5
mov ebx, 8
; in i vi e' tutto il file di lunghezza c
mov edx, [esp+InpHandle]
push edx
call CloseHandle
cmp eax, 0
je .e5
xor ebp, ebp
mov ebx, 9
lea edi, [esp+656]
..2: push ebp
push esi
push 1024
push edi
call LineToNasm
mov ebp, eax
cmp edx, 0
je .9
; ^Result=a|^Chars_i=r|^Chars_j=c
add esi, edx
jc .e5
cmp esi, [esp+MemLimit]
ja .e5
mov edx, dword[esp+ OutHandle]
mov eax, esp
push 0
push eax
push ecx
push edi
push edx
call WriteFile
cmp eax, 0
je .e5
cmp esi, [esp+MemLimit]
jb .2
..9: mov ebx, 10
mov edx, [esp+OutHandle]
push edx
call FlushCloseHandle
jc .e4
mov edx, [esp+MemFile]
push edx
call Free_sys
call FreeMem
..z:
%undef FileSize
%undef MemLimit
%undef InpFName
%undef OutFName
%undef FileLine
%undef InpHandle
%undef OutHandle
%undef MemFile
lea esp, [esp+2048]
pop ebp
pop edi
pop esi
pop ebx
ret


; AssegnaVettori(u32* vettori, u32 NParole, u8* str)
; assume che vettori sia abbastanza per Nparole+1
; nel vettore finale si scrive dove e' arrivato i
; 28P_str, 24P_Nvettori, 20P_vettori,16Ra,b12,c8,r4,i0
AssegnaVettori:
push ebx
push ecx
push edx
push esi
mov ecx, dword[esp+ 24]
mov esi, dword[esp+ 28]
mov edx, dword[esp+ 20]
shl ecx, 2
xor eax, eax
xor ebx, ebx
add ecx, edx
jmp short .3
..2: inc esi
..3: mov al, [esi]
..4: cmp byte[MyTable+eax], Space
je .2
cmp eax, 0
je .8
inc ebx
mov [edx], esi
add edx, 4
cmp edx, ecx
je .8
..5: inc esi
..6: mov al, [esi]
..7: cmp byte[MyTableR+eax], 0
je .5
cmp eax, '"'
je .5
cmp eax, "'"
je .5
cmp eax, 0
jne .4
..8: mov [edx], esi
..z: mov eax, ebx
pop esi
pop edx
pop ecx
pop ebx
ret 12

; j:Destination, k:destinationSize, i:origin
;
GetData_jki:
push edi
sub esp, 64
mov dword[esp], 0
cmp ebp, 0
jle .e
jmp short .tris0
..inizio:
mov dword[esp], 1
..tris0:
call LevaSpaziDa_i
mov eax, [esi]
cmp al, 0
je .0
cmp al, 10
jne .1
mov byte[edi], 10
dec ebp
jz .e0
inc edi
..bis0: mov byte[edi], 0
mov eax, 1
..biss: clc
jmp .z
..0: mov byte[edi], 0
mov eax, 128
clc
jmp .z
..e0: mov byte[edi], 0
..e: xor eax, eax
stc
jmp .z
..1: cmp ax, 00A0Dh
jne .2
sub ebp, 2
jbe .e0
mov word[edi], ax
add edi, 2
add esi, 2
jmp short .bis0
..2: cmp ax, 02A2Fh
jne .0x ; /*
mov byte[edi], ';'
dec ebp
jz .e0
inc edi
add esi, 2
..2aa: call CopyUntil10Or0_jki
jc .e0
jmp .biss
..0x: cmp al, ';'
jne .0y
mov byte[edi], ';'
dec ebp
jz .e0
inc edi
inc esi
jmp short .2aa
..0y: cmp al, '"'
jne .1d
..1a: cmp dword[esp], 0
je .1b
call PrendiWordTraVirgolette_jki
jc .e0
jmp .inizio
..1b: call PrendiPseudoWordTraVirgolette_jki
jc .e0
mov byte[edi], ':'
dec ebp
jz .e0
inc edi
mov byte[edi], ' '
dec ebp
jz .e0
inc edi
jmp .inizio
..1d: cmp al, "'"
je .1a
mov edx, [esi+4]
cmp eax, "time"
je .2b
..2a: jmp .7
..2b: cmp dx, "s "
jne .2a ; 0==time 1==48 2==db 3==num 4==fine
lea eax, [esp+8]
push esi
push 5
push eax
call AssegnaVettori
cmp eax, 5
jne .e0
mov edx, [esp+8+(4*2)]
mov eax, [edx]
and eax, 000FFFFFFh
cmp al, 'd'
jne .e0
and ah, 05fh ; da minuscola a maiuscola
mov [edi], ah
dec ebp
jz .e0
inc edi
sub ebp, 2
jle .e0
mov word[edi], "$ "
add edi, 2
shr eax, 16
cmp byte[MyTable+eax], Space
jne .e0
mov edx, [esp+8+(4*3)]
cmp byte[edx], '"'
je .3
cmp byte[edx], "'"
je .3
push esi
mov esi, edx
call CopyMacro_jki
pop esi
jc .6a
jmp short .4
..3: mov al, [edx]
mov [edi], al
dec ebp
jz .e0
cmp eax, 0
je .4
cmp eax, 13
je .4
cmp eax, 10
je .4
inc edx
inc edi
cmp byte[MyTable+eax], Space
jne .3
..4: mov byte[edi], ' '
dec ebp
jz .e0
inc edi
mov byte[edi], '#'
dec ebp
jz .e0
inc edi
mov edx, [esp+8+(4*1)]
push esi
mov esi, edx
call CopyMacro_jki
pop esi
jc .6a
;.5: al=*r|*j=al|--k!#.e0|a==0#.6
; ++r,j|B[MyTable+a]!=Space#.5
..6: mov esi, [esp+8+(4*4)]
mov byte[edi], ' '
dec ebp
jz .6a
inc edi
jmp .inizio
..6a: jmp .e0
..7: and eax, 000FFFFFFh
cmp eax, "res"
jne .7a
cmp byte[esi+4], ' '
jne .7a
mov dl, [esi+3]
sub ebp, 6
jle .6a
and dl, 05fh ; da minuscola a maiuscola
mov byte[edi], dl
inc edi
mov dword[edi], "$ ? "
add edi, 4
add esi, 4
mov byte[edi], "#"
inc edi
call LevaSpaziDa_i
call PrendiWord_jki
jc .6a
mov byte[edi], ' '
dec ebp
jz .6a
inc edi
jmp .inizio
..7a: cmp al, 'd'
jne .8
cmp byte[esi+2], ' '
jne .8
mov dl, [esi+1]
sub ebp, 3
jle .6a
and dl, 05fh ; da minuscola a maiuscola
mov byte[edi], dl
inc edi
mov word[edi], "$ "
add edi, 2
add esi, 2
jmp .inizio
..8: and eax, 0FFh ; Numeri
cmp byte[MyTable+eax], 0
jne .9
..7b: call PrendiWord_jki
jc .6a
mov byte[edi], ' '
dec ebp
jz .6a
inc edi
jmp .inizio
; Alfanumerici non numeri
..9: cmp byte[MyTableR+eax], 0
jne .a
cmp dword[esp], 0
jne .9a
call PrendiWord_jki
jc .9b
cmp byte[esi], ':'
jne .8a
inc esi
..8a: mov word[edi], ": "
sub ebp, 2
jle .9b
add edi, 2 ; appendi ':'
jmp .inizio
..9a: call CopyMacro_jki
jc .9b
jmp .inizio
..9b: jmp .e0
..a: cmp byte[MyTable+eax], 9
je .7b
mov byte[edi], al
dec ebp
jz .9b
inc edi
inc esi
jmp .inizio
..z:
lea esp, [esp+68]
ret

; FindCarattereFromEnd(u8* inizio, u8* fine, u32 carattere)
; trova la parentesi quadra a partire dalla fine
; CF==1 trovato CF==0 non trovato
; 0ra, 4P_inizio, 8P_fine
FindCarattereFromEnd:
mov ecx, dword[esp+ 4]
mov edx, dword[esp+ 8]
xor eax, eax
..1: cmp edx, ecx
jb .a
mov al, [edx]
cmp eax, dword[esp+ 12]
je .b
dec edx
cmp byte[MyTableR+eax], 16
jae .1
cmp byte[MyTableR+eax], 9
jb .1
..a: clc
jmp short .z
..b: stc
..z:
ret 12


; CF==1 means find
; CF==0 means not find
; trova nella linea attuale
; 0i,4b,8ra,12P_Str,16P_StrToFind
Find:
push ebx
push esi
xor eax, eax
xor ebx, ebx
mov edx, dword[esp+ 12]
mov ecx, dword[esp+ 16]
mov bl, [ecx]
cmp ebx, 0
je .5
jmp short .3
..0: mov esi, edx
..1: inc esi
inc ecx
mov bl, [ecx]
cmp ebx, 0
je .5
cmp byte[MyTable+ebx], Space
je .5
cmp bl, [esi]
je .1
mov ecx, dword[esp+ 16]
mov bl, [ecx]
..2: inc edx
..3: mov al, [edx]
cmp eax, ebx
je .0
cmp eax, 10
je .4
cmp eax, 13
je .4
cmp eax, 0
jne .2
..4: clc
jmp short .6
..5: stc
..6:
pop esi
pop ebx
ret 8



FindData_i:
sub esp, 32
mov dword[esp+ 0], "DATA"
mov dword[esp+ 4], 0
mov eax, esp
push eax
push esi
call Find
jc .z
mov dword[esp+ 0], "data"
mov dword[esp+ 4], 0
mov eax, esp
push eax
push esi
call Find
jc .z
mov dword[esp+ 0], "bss"
mov dword[esp+ 4], 0
mov eax, esp
push eax
push esi
call Find
jc .z
mov dword[esp+ 0], "BSS"
mov dword[esp+ 4], 0 ; BSS e' anche data
mov eax, esp
push eax
push esi
call Find
..z:
lea esp, [esp+32]
ret

FindCode_i:
sub esp, 32
mov dword[esp+ 0], "CODE"
mov dword[esp+ 4], 0
mov eax, esp
push eax
push esi
call Find
jc .z
mov dword[esp+ 0], "code"
mov dword[esp+ 4], 0
mov eax, esp
push eax
push esi
call Find
jc .z
mov dword[esp+ 0], "text"
mov dword[esp+ 4], 0
mov eax, esp
push eax
push esi
call Find
jc .z
mov dword[esp+ 0], "TEXT"
mov dword[esp+ 4], 0
mov eax, esp
push eax
push esi
call Find
..z:
lea esp, [esp+32]
ret




; u32 LineToRosAsm(u8* dest, u32 dsize, u8* origin, u32 commento)
; come risultato ecx, caratteri scritti in j
; edx, caratteri di avanzamento di i
; a==eax==risultato della funzione
; a& 1!=0 raggiunta la fine della istruzione con \n
; a& 2!=0 esiste la label
; a& 4==0 [<=>CF==0] nessun errore trovato
; a& 4!=0 [<=>CF==1] riscontrato errore
; a& 8!=0 commento semplice
; a& 16!=0 commento doppio
; a& 32!=0 errore di parametro
; a& 64!=0 errore di copia
; a& 128!=0 raggiunta la fine della istruzione con 0
; a& 256!=0 raggiunta la fine della istruzione con "|", ";"
; a& 512!=0 raggiunta la fine della istruzione per label
; a&1024!=0 data
; a&2048!=0 linea dello stesso tipo di dati
; a&4096!=0 Stampa "["
; 0k,4j,8i,12b,16ra,20P_d,24P_dsize,28P_or,32P_comm
; j:Destination, k:destinationSize, i:origin, b:LastChar
LineToRosAsm:
push ebx
push esi
push edi
push ebp
mov edi, [esp+20]
mov ebp, [esp+24]
mov esi, [esp+28]
xor ebx, ebx
cmp edi, 0
je .e1
cmp ebp, 7
jle .e1
mov byte[edi], 0
xor eax, eax
cmp esi, 0
jne .1
..e1: mov edx, [esp+32]
and edx, 0FFFFFC10h ; levo \n ed \0
; levo 1,2,4,32,64,128,256,512
or eax, 32
or eax, edx
..e: mov byte[edi], 0
or eax, 4
sub esi, [esp+28]
sub edi, [esp+20]
mov edx, esi
mov ecx, edi
..eee: stc
jmp .z
..e2: mov edx, [esp+32]
and edx, 0FFFFFC10h
or eax, 64
or eax, edx
jmp short .e
..f0: mov byte[edi], 0
sub esi, [esp+28]
sub edi, [esp+20]
mov edx, esi
mov ecx, edi
..f: clc
jmp .z
..f1: mov edx, [esp+32]
and edx, 0FFFFFC10h
or eax, edx
jmp short .f0
..f2: mov eax, ebx
jmp short .f0 ; a=2 linea con ";" a=3 ";;"
..0: inc esi
..1: mov bl, [esi]
cmp byte[MyTable+ebx], Space
je .0
cmp ebx, 10
jne .1b
..1a: call CopyUntil10Or0_jki
jc .e2
jmp short .f1
..1b: cmp ebx, 13
jne .1c
cmp byte[esi+1], 10
je .1a
..1c: cmp byte[MyTable+ebx], 5
jne .1k
test dword[esp+32], 1024
jz .f1
mov eax, [esp+32]
and eax, 0FFFFFC10h
and eax, 0FFFFFBFFh
or eax, 128
mov byte[edi], ']'
inc edi
dec ebp
jz .e
..1d: jmp .f0
..1k: cmp ebx, ';'
jne .4
mov ebx, [esp+32]
and ebx, 0FFFFFC10h
or ebx, 8
cmp byte[esi+1], ';'
jne .3a
; caso ";;" trovato anche prima: D[s+32]&16!=0
test dword[esp+32], 16
jnz .22
..2: or ebx, 16
jmp short .3
..22: and ebx, 0FFFFFFEFh
..3: call CopyUntil10Or0_jki
jc .e2
or ebx, eax
jmp .f2
; caso ";" ora e ";;" prima oppure no
..3a: test dword[esp+32], 16
jnz .3
or ebx, 8
jmp short .3
..4: test dword[esp+32], 16
jz .5
mov ebx, [esp+32]
and ebx, 0FFFFFC10h
jmp short .2
..5: cmp ebx, '/'
jne .1o
cmp byte[esi+1], '*'
jne .1o
mov ebx, [esp+32]
and ebx, 0FFFFFC10h
or ebx, 8
mov byte[edi], ';'
inc edi
dec ebp
add esi, 2
jmp short .3
..1o: test dword[esp+32], 2048
jz .3f
mov ebx, [esp+32]
and ebx, 0FFFFFC10h
or ebx, 8
call CopyUntil10Or0_jki
jc .e2
or ebx, eax
mov eax, [esp+20]
push ']'
push edi
push eax
call FindCarattereFromEnd
jnc .3b
and ebx, 0FFFFF7FFh ; trova la parentesi quadra not(2048)
..3b: jmp .f2
..3c: jmp .7
..3d: jmp .a
..3f: mov eax, [esi]
mov edx, [esi+4]
; b e' il primo carattere effettivo
cmp ebx, 's'
jne .3c
cmp eax, "sect"
jne .3d
cmp edx, "ion "
jne .3d ; viene vista come commento
..6: mov ebx, [esp+32]
and ebx, 0FFFFFC10h
or ebx, 8 ; commento
call FindData_i
jnc .6d
test ebx, 1024
jz .3g
test ebx, 4096
jnz .3g
mov byte[edi], ']'
inc edi
dec ebp ; fine del segmento precedente
..3g: or ebx, 1024 ; aggiungo data
..6a: call VaiUntil10Or0_i
or ebx, eax
test eax, 1
jz .3h
mov byte[edi], 13
inc edi
mov byte[edi], 10
inc edi
sub ebp, 2
..3h: test ebx, 1024
jz .6c
test ebx, 8
jz .6c
or ebx, 4096 ; quando arriva ai dati deve
; stampare '['
..6c: jmp .f2
..6d: call FindCode_i
jnc .6a
test ebx, 1024
jz .5b
test ebx, 4096
jnz .5b
mov byte[edi], ']'
inc edi
dec ebp
..5b: and ebx, 0FFFFFBFFh
jmp short .6a ; levo data
..6f: jmp .e2
..7: cmp ebx, 'S'
jne .8
cmp eax, "SECT"
jne .a
cmp edx, "ION "
je .6
..8: cmp ebx, '%'
jne .a
cmp eax, "%def"
jne .8b
cmp edx, "ine "
jne .8b
..8a: mov ebx, [esp+32]
and ebx, 0FFFFFC10h
push esi
call PushMacro
jmp .6a ; definizione di macro
..8b:
cmp eax, "%und"
jne .6a
cmp dx, "ef"
jne .6a
..8c: mov ebx, [esp+32]
and ebx, 0FFFFFC10h
push esi
call PopMacro
jmp .6a
..des_e: jmp .e
..des_e2: jmp .e2
; j destination, i origin, b last char,
..a: cmp ax, "<<"
je .8a
cmp ax, ">>"
je .8c
and edx, 000FFFFFFh
cmp eax, "expo"
jne .7a
cmp edx, "rt "
jne .7a
mov ebx, [esp+32]
and ebx, 0FFFFFC10h
push esi
call PushExport
jmp .6a
..7a: cmp eax, "glob"
jne .1x
cmp edx, "al "
jne .1x
..1q: mov ebx, [esp+32]
and ebx, 0FFFFFC10h
or ebx, 8
call VaiUntil10Or0_i
or ebx, eax
test eax, 1
jz .1r
mov byte[edi], 13
inc edi
mov byte[edi], 10
inc edi
sub ebp, 2
..1r: jmp .f2
..1x: cmp eax, "exte"
jne .1z
cmp edx, "rn "
je .1q
..1z: test dword[esp+32], 1024
jz .8d ; settore "data"
mov ebx, [esp+32]
and ebx, 0FFFFFC10h
or ebx, 8 ; commento
call HaLaLineaQualcheParola_i
jc .a0
call CopyUntil10Or0_jki
jc .des_e2
or ebx, eax
test eax, 128
jz .a01
mov byte[edi], ']'
inc edi
dec ebp
jz .des_e
and ebx, 0FFFFFBFFh ; fine stringa
..a01: jmp .f2 ; quando finisce il file
..a0: test ebx, 4096
jz .a1
mov byte[edi], '['
inc edi
dec ebp
jz .des_e
and ebx, 0FFFFEFFFh ; toglie 4096
..a1: call GetData_jki
or ebx, eax
..6g: jmp .f2
..8d: cmp al, '['
jne .8e
call IsNextWordLabel_i
jnc .8e
mov ebx, [esp+32]
and ebx, 0FFFFFC10h
call CopyUntil10Or0_jki
jc .6f
or ebx, eax
mov eax, [esp+20]
push ']'
push edi
push eax
call FindCarattereFromEnd
jc .6g
or ebx, 2048
jmp .f2
..8e: mov ecx, 1
call ToNasm
add edi, ecx
sub ebp, ecx
jle .des_e
push ecx
push edi
sub edi, ecx
mov ecx, dword[esp+ 0]
call FromNasmToRos
pop edi
pop ecx
test eax, 4
jnz .b
test eax, 128
jnz .a9
test eax, 1
jnz .a9
cmp ecx, 0
jne .8e ;B*i#.8e
..a9: jmp .f0
..b: jmp .e
..z:
pop ebp
pop edi
pop esi
pop ebx
ret 16


;
; FromNasmToRos(j,a)
; in "j" vi e' l'inizio della stringa in "a" la sua fine
; Non cambia la lunghezza di j
; trasforma j->" stringa " stringa
; in-place
; da Nasm a Ros
; mov [eax], ebx
; < a272, b268, c264, i260, j256
FromNasmToRos:
push eax
push ebx
push ecx
push esi
push edi
sub esp, 256
test eax, 8
jnz .0
test eax, 16
jnz .0
jmp short .0b
..0: clc
jmp .z
..e: stc
jmp .z
; mov D[esp],90 -> mov D$esp , 90
; | || | |
; mov [esp],eax -> mov D$esp , eax /* r==1
; | | | |
; mov eax, [esp] -> mov eax, D$esp /* r==2
; | | | |
; call [eax]
; | | |
; call D$eax
; | ||| |
..0a: mov edi, [esp+ebx*4-4]
inc edi
cmp edi, dword[esp+ 264]
jae .0
..0b: mov eax, esp
push edi
push 60
push eax
call AssegnaVettoriIstruzione
jc .e
mov ebx, eax
xor edx, edx
xor eax, eax
cmp ebx, 0
je .0
cmp ebx, 1
jne .0c
mov esi, [esp+edx*4]
cmp byte[esi], ';'
je .0
cmp byte[esi], 13
je .0
cmp byte[esi], 10
je .0
cmp byte[esi], 0
je .0
..0c: cmp ebx, 1
je .0a
cmp ebx, 2
je .0a
cmp ebx, 3
jne .1a
mov esi, [esp+(4*1)]
mov al, [esi]
cmp eax, '$'
jne .0a
mov byte[esi-1], 'D'
jmp short .0a ; call dword
cmp ebx, 4
jne .0a
..1a: inc edx
cmp edx, 3
je .0a ; r==1,2
..1b: mov esi, [esp+edx*4]
mov al, [esi]
..2: cmp eax, '$'
jne .1a
cmp edx, 2
je .3
mov ecx, [esp+edx*4+4]
..2a: push edx
push ecx
call Isreg
pop edx
cmp eax, 0
je .0a
xor ecx, ecx
mov cl, [ IZBWIDIIIIQIT +eax]
mov byte[esi-1], cl
jmp .0a
..3: mov ecx, [esp+edx*4-4]
jmp short .2a
..z:
lea esp, [esp+256]
pop edi
pop esi
pop ecx
pop ebx
pop eax
ret

; CF==1 Find
; CF==0 not Find
IsExport_k:
pushad
jmp short .1
..notfind: clc
jmp .z
..find: stc
jmp .z
..1: push ebp
call FindMacroWord
jc .notfind
cmp edx, ecx
jne .notfind
mov esi, eax
mov edi, ebp
mov ebp, ecx
call DCmp
jnc .find ; trovato
jmp short .notfind
..z:
popad
ret

; AssegnaVettoriIstruzione(u32* vettori, u32 NMaxParole, u8* str)
; assume che NMaxParole siano abbastanza per trattare l'istruzione
; nel vettore finale si scrive dove e' arrivato i
; 36P_str, 32P_Nvettori, 28P_vettori,24Ra,b20,c16,r12,i8,j4, k0
AssegnaVettoriIstruzione:
push ebx
push ecx
push edx
push esi
push edi
push ebp
mov edx, dword[esp+ 28]
mov ecx, dword[esp+ 32]
mov esi, dword[esp+ 36]
shl ecx, 2
xor eax, eax
xor ebx, ebx
add ecx, edx
jmp short .3
..e: mov eax, ebx
stc
jmp .z
..1: jmp .9
..2: inc esi
..3: mov al, [esi]
..4: cmp byte[MyTableR+eax], Space
je .2
cmp eax, '|'
je .1
cmp eax, 0
je .1
cmp eax, 10
je .1
cmp eax, ';'
je .1
cmp eax, ','
je .2
cmp eax, '.'
jne .4a
mov byte[esi], '@'
cmp byte[esi+1], '.'
jne .4a
mov byte[esi+1], '@'
..4a: inc ebx
mov [edx], esi
add edx, 4
cmp edx, ecx
je .e
cmp eax, '['
jne .4m
mov eax, ']'
mov byte[esi], '$'
..4h: mov edi, eax
..4i: inc esi
mov al, [esi]
cmp eax, 0
je .9
cmp eax, 10
je .9
cmp eax, edi
jne .4i
cmp eax, ']'
jne .2
mov byte[esi], ' '
jmp .2
..4m: cmp eax, '('
je .4h
cmp eax, "'"
je .4h
cmp eax, '"'
je .4h
mov ebp, esi
..5: inc esi
..6: mov al, [esi]
..7: cmp byte[MyTableR+eax], 0
je .5
cmp eax, ':'
jne .8
sub edx, 4
dec ebx
inc esi
call IsExport_k
jnc .8
mov byte[esi], ':'
inc esi
..8: cmp eax, 0
jne .4
..9: mov [edx], esi
lea eax, [ebx+1]
clc
..z:
pop ebp
pop edi
pop esi
pop edx
pop ecx
pop ebx
ret 12


; a=1File, r=2File
MacroRosAsm:
push ebx
push esi
push edi
push ebp ; 400 FileLine=656..1680 size=1024
sub esp, 2048 ; b1=128..384, b2=392..648 size=256
%define InpHandle 16
%define OutHandle 20
%define MemFile 24
%define InpFName 128
%define OutFName 392
%define FileLine 656
%define FileSize 28
%define MemLimit 44
mov esi, eax
mov ebx, edx
call InstallRos
jc .e
lea edi, [esp+InpFName]
mov ecx, 256
call PrendiNomeDa_i
jc .e1
mov esi, ebx
lea edi, [esp+OutFName]
mov ecx, 256
call PrendiNomeDa_i
jnc .1
..e1: mov eax, 1

..e: call FreeMem
stc
jmp .z
..e2: mov eax, 2
jmp short .e ; errore di file input
..e5: mov edx, [esp+OutHandle]
push edx
call FlushCloseHandle
..e4: mov eax, [esp+MemFile]
push eax
call Free_sys
..e3: mov edx, [esp+InpHandle]
push edx
call CloseHandle
mov eax, ebx
jmp short .e ; errore di file output
..1: ; Apri file di input
lea edx, [esp+InpFName]
push 0
push FILE_ATTRIBUTE_NORMAL
push OPEN_EXISTING
push 0
push 0
push GENERIC_READ
push edx
call CreateFileA
mov [esp+InpHandle], eax

mov ebx, 3
cmp eax, INVALID_HANDLE_VALUE
je .e2
mov ebx, 4
mov edx, esp
push edx
push eax
call GetFileSize
cmp eax, -1
je .e3
cmp dword[esp], 0
jne .e3
mov ebx, 5
mov dword[esp+ FileSize], eax
add eax, 64
push eax
call Malloc_sys
cmp eax, 0
je .e3
mov [esp+MemFile], eax
mov edx, dword[esp+ FileSize]
mov dword[esp+ MemLimit], eax
add dword[esp+ MemLimit], edx
add edx, 32
mov dword[eax+edx], 0 ; per essere sicuri che termini
lea edx, [esp+OutFName]
mov ebx, 6 ; line to nasm
push 0
push FILE_ATTRIBUTE_NORMAL
push CREATE_ALWAYS
push 0
push 0
push GENERIC_WRITE
push edx
call CreateFileA
mov [esp+OutHandle], eax

cmp eax, INVALID_HANDLE_VALUE
je .e4
mov edx, dword[esp+ InpHandle]
mov ecx, dword[esp+ FileSize]
add ecx, 32
mov esi, dword[esp+ MemFile]
mov eax, esp
mov ebx, 7
push 0
push eax
push ecx
push esi
push edx
call ReadFile
cmp eax, 0
je .e5
mov ecx, [esp]
cmp [esp+FileSize], ecx
jne .e5
mov ebx, 8
; in i vi e' tutto il file di lunghezza c
mov edx, [esp+InpHandle]
push edx
call CloseHandle
cmp eax, 0
je .e5
xor ebp, ebp
mov ebx, 9
lea edi, [esp+656]
..2: push ebp
push esi
push 1024
push edi
call LineToRosAsm
mov ebp, eax ; | r==0#.9
add esi, edx
jc .e5
cmp esi, [esp+MemLimit]
ja .e5
mov edx, dword[esp+ OutHandle]
mov eax, esp
push 0
push eax
push ecx
push edi
push edx
call WriteFile
cmp eax, 0
je .e5
cmp byte[edi], 0
jne .2
; i<[s+MemLimit]#.2
..9: mov ebx, 10
mov edx, [esp+OutHandle]
push edx
call FlushCloseHandle
jc .e4
mov edx, [esp+MemFile]
push edx
call Free_sys
call FreeMem
..z:
%undef FileSize
%undef MemLimit
%undef InpFName
%undef OutFName
%undef FileLine
%undef InpHandle
%undef OutHandle
%undef MemFile
lea esp, [esp+2048]
pop ebp
pop edi
pop esi
pop ebx
ret

;------------------------------

GetStdIo:
jmp short .1
..e: mov eax, -1
stc
jmp .z
..1: push STD_ERROR_HANDLE
call GetStdHandle
mov [stderr], eax
cmp eax, -1
je .e
push STD_INPUT_HANDLE
call GetStdHandle
mov [stdin], eax
cmp eax, -1
je .e
push STD_OUTPUT_HANDLE
call GetStdHandle
mov [stdout], eax
cmp eax, -1
je .e
cmp eax, [stdin]
je .e
mov edx, [stdout]
push BufInfo
push edx
call GetConsoleScreenBufferInfo
cmp eax, 0
je .2
mov edx, BufInfo
add edx, 2
xor eax, eax
mov ax, [edx]
cmp eax, 0
je .3
dec eax
jz .2
mov [consoley], eax ; consoley non e' corretto[-1]
sub edx, 2
mov ax, [edx]
cmp eax, 0
je .3
mov [consolex], eax
..2: xor eax, eax
..3: clc
..z:
ret


CloseStdIo:
mov edx, [stderr]
push edx
call FlushCloseHandle
mov edx, [stdin]
cmp edx, -1
je .1
push edx
call CloseHandle
..1: mov edx, [stdout]
push edx
call FlushCloseHandle
mov dword[stderr], -1
mov dword[stdin], -1
mov dword[stdout], -1
xor eax, eax
..z:
ret

;0j,4i,8ra,12P_Handle
FlushCloseHandle:
push esi
push edi
mov esi, dword[esp+ 12]
cmp esi, -1
jne .1
..e: xor eax, eax
stc
jmp short .z ; bene a!=0
..1: push esi
call FlushFileBuffers
mov edi, eax
push esi
call CloseHandle
cmp eax, 0
je .e
cmp edi, 0
je .e
clc
..z:
pop edi
pop esi
ret 4

; 0j,4i,8b,12ra,16P_hexValue +256
HexPrint:
push ebx
push esi
push edi
sub esp, 256
mov ebx, dword[esp+ 272]
xor edi, edi
xor eax, eax
mov ecx, 28
mov byte[esp+edi], '0'
inc edi
mov byte[esp+edi], 'x'
inc edi
mov esi, 0F0000000h
..0: mov edx, esi
and edx, ebx
shr edx, cl
mov al, [ I0123456789ABCDEF +edx]
mov [esp+edi], al
inc edi
shr esi, 4
sub ecx, 4
jge .0
mov byte[esp+edi], 0
mov esi, [stderr]
mov eax, esp
push eax
push esi
call SPuts
lea esp, [esp+256]
pop edi
pop esi
pop ebx
ret 4

;u32 SPuts(u32 Handle, u32 String)
; scrive in Handle la stringa String
; 0j,4ra,8P_Handle,12P_Str + 8
; 16 , 20
SPuts:
push edi
sub esp, 8
mov eax, dword[esp+ 20]
xor ecx, ecx
mov edx, eax
cmp dword[esp+16], -1
je .e
cmp eax, 0
jne .2
..e: stc
jmp short .z
..1: inc eax
inc ecx
..2: cmp byte[eax], 0
jne .1
mov edi, dword[esp+ 16]
mov eax, esp
push 0
push eax
push ecx
push edx
push edi
call WriteFile
mov ecx, eax
mov eax, [esp]
cmp ecx, 0
je .e
clc
..z:
lea esp, [esp+8]
pop edi
ret 8

; r=*stderr| PrintError(r)
; FORMAT_MESSAGE_FROM_SYSTEM 01000h
; 32P_FHeader,ra28,a24,b20,c16,r12,i8,j4,k0
PrintError:
push eax
push ebx
push ecx
push edx
push esi
push edi
push ebp
mov ebp, [esp+32]
cmp ebp, -1
je .e
call GetLastError
mov esi, eax
jmp short .1
..e0: push edi
call Free_sys
..e: stc
jmp short .z
..1: push 1024
call Malloc_sys
cmp eax, 0
je .e
mov edi, eax
push 0
push 1020
push edi
push 0
push esi
push 0
push 01000h
call FormatMessageA
cmp eax, 0
je .e0
push edi
push ebp
call SPuts
jc .e0
mov byte[edi], 13
mov byte[edi+1], 10
mov word[edi+2], 0
push edi
push ebp
call SPuts
jc .e0
push edi
call Free_sys
..z:
pop ebp
pop edi
pop esi
pop edx
pop ecx
pop ebx
pop eax
ret 4

; u32 SPutsLine(u32 Handle, u32 String)
; scrive in Handle la stringa String
; ritorna in a la lunghezza della stringa
; scritta mentre r==1 se ha raggiunto la
; fine della stringa
; r=0 non ha raggiunto la fine della stringa
; 0j,4ra,8P_Handle,12P_Str + 16
; 24 , 28
SPutsLine:
push edi
sub esp, 16
mov eax, dword[esp+ 28]
xor ecx, ecx
mov edx, eax
mov dword[esp+8], 0
cmp eax, 0
jne .2
mov edx, 1
..e: stc
jmp short .z
..1: inc eax
inc ecx
..2: cmp byte[eax], 10
je .3
cmp byte[eax], 0
jne .1
mov dword[esp+8], 1
jmp short .4
..3: inc ecx
..4: mov edi, dword[esp+ 24]
mov eax, esp
push 0
push eax
push ecx
push edx
push edi
call WriteFile
mov ecx, eax
mov edx, [esp+8]
mov eax, [esp]
cmp ecx, 0
je .e
clc
..z:
lea esp, [esp+16]
pop edi
ret 8

;0j,4j,8i,12b, 16ra, 20P_FileH
ScriviChi:
push ebx
push esi
push edi
push edi
mov edi, dword[esp+ 20]
mov ebx, nome
mov esi, nome1
push esi
push edi
call SPutsLine
..0: xor eax, eax
mov al, [ebx]
cmp eax, 0
je .1
xor edx, edx
mov dl, [esi]
xor eax, edx
mov dword[esp+ 0], eax
inc esi
inc ebx
mov eax, esp
push eax
push edi
call SPuts
jnc .0
..1: push nl
push edi
call SPutsLine
..z:
pop edi
pop edi
pop esi
pop ebx
ret 4

; ShowHelpConsole(u32* string)
; 0k,4j,8i,12ra,16P_String
ShowHelpConsole:
push esi
push edi
push ebp
mov esi, [esp+16]
xor ebp, ebp
mov edi, [stdout]
push edi
call ScriviChi
add ebp, 2
..1: inc ebp
push esi
push edi
call SPutsLine
cmp edx, 0
jne .z
cmp eax, 0
je .z
add esi, eax
cmp ebp, [consoley]
jne .1
xor ebp, ebp
mov edx, [stderr]
mov eax, IIPremiIInII
push eax
push edx
call SPuts
mov edx, [stderr]
push edx
call FlushFileBuffers
mov edx, [stdin]
push edx
push 1024
push qui
call SGetLine
jmp short .1
..z: cmp dword[consoley], 1024
je .zz
mov edx, [stderr]
mov eax, IIPremiIInII
push eax
push edx
call SPuts
mov edx, [stderr]
push edx
call FlushFileBuffers
mov edx, [stdin]
push edx
push 1024
push qui
call SGetLine
..zz: mov eax, ebp
pop ebp
pop edi
pop esi
ret 4

; 0k,4j,8i,12b,16ra,20P_w
ShowMacro:
push ebx
push esi
push edi
push ebp
mov ebx, [esp+20]
xor ebp, ebp
mov edi, [stdout]
mov esi, ebx
cmp dword[stderr], -1
je .ee
cmp edi, -1
je .ee
jmp short .2
..ee: jmp .e
..1: inc esi
..2: cmp byte[esi], 0
jne .1
..1a: inc esi
..1b: cmp byte[esi], 0
je .1a
cmp dword[consoley], 1024
je .1c
inc ebp
cmp ebp, 18
jne .1c
mov ebp, 0
mov eax, IIPremiIInII
mov edx, [stderr]
push eax
push edx
call SPuts
mov edx, [stderr]
push edx
call FlushFileBuffers
mov edx, [stdin]
push edx
push 1024
push qui
call SGetLine
..1c: push ebx
push edi
call SPutsLine
jc .e
mov eax, IIIIIIIII
push eax
push edi
call SPutsLine
jc .e
push esi
push edi
call SPutsLine
jc .e
push nl
push edi
call SPutsLine
jnc .4
..e: mov eax, -1
stc
jmp short .z
..3: inc esi
..4: cmp byte[esi], 0
jne .3
..4a: inc esi
..4b: cmp byte[esi], 0
je .4a
mov ebx, esi
cmp byte[esi], 0FFh
jne .2
xor eax, eax
clc
..z:
pop ebp
pop edi
pop esi
pop ebx
ret 4


; ritorna la lunghezza della stringa presa
; c==1 significa raggiunto EOF
; c==0 significa non raggiunto EOF
; 0k,4j,8i,12b,16ra,
; 20PArr,24PArrSize,28PHandle + 8
; 28 j |32 k |36 i
SGetLine:
push ebx
push esi
push edi
push ebp
sub esp, 8
mov edi, dword[esp+ 28]
mov ebp, dword[esp+ 32]
mov esi, dword[esp+ 36]
mov ebx, esp
cmp ebp, 0
jle .e0
cmp edi, 0
jne .1
..e0: xor eax, eax
..e: xor ecx, ecx
stc
jmp short .z
..e1: mov byte[edi], 0
sub edi, [esp+28]
mov eax, edi
jmp short .e
..1: add ebp, edi
..2: cmp edi, ebp
jae .e1
push 0
push ebx
push 1
push edi
push esi
call ReadFile
cmp eax, 0
je .e1
cmp dword[esp], 1
jne .3 ;raggiunto EOF
inc edi
cmp byte[edi-1], 10
jne .2
xor ecx, ecx
jmp short .4
..3: mov ecx, 1
..4: mov byte[edi], 0
sub edi, [esp+28]
mov eax, edi
clc
..z:
lea esp, [esp+8]
pop ebp
pop edi
pop esi
pop ebx
ret 12


; CREATE_NEW_PROCESS_GROUP 0200h
; NORMAL_PRIORITY_CLASS 020h 0220h
;0k,4j,8i,12ra,16Ps + 1024
SystemA:
push esi
push edi
push ebp
sub esp, 1024
mov esi, [esp+1040]
mov dword[esp], 0
cmp esi, 0
jne .1
..e1: mov eax, 1
..e: stc
jmp .z
..e2: mov eax, [stderr]
push eax
call PrintError
mov eax, 2
jmp short .e
..e3: mov eax, 3
jmp short .e
..e4: mov edx, [ProcInfo+4]
push edx
call CloseHandle
cmp eax, 0
je .e3
mov edx, [ProcInfo]
push edx
call CloseHandle
cmp eax, 0
je .e3
mov eax, 4
jmp short .e
..1: mov edx, [stderr]
push esi
push edx
call SPuts
mov edx, [stderr]
push nl
push edx
call SPuts
push StartInfo
call GetStartupInfoA
push ProcInfo
push StartInfo
push 0
push 0
push 0220h
push 1
push 0
push 0
push esi
push 0
call CreateProcessA
cmp eax, 0
je .e2
mov esi, [ProcInfo]
push 0FFFFFFFFh
push esi
call WaitForSingleObject
cmp eax, -1
je .e4
mov eax, esp
push eax
push esi
call GetExitCodeProcess
mov edx, [ProcInfo+4]
push edx
call CloseHandle
cmp eax, 0
je .e3
push esi
call CloseHandle
cmp eax, 0
je .e3
mov eax, [esp]
clc ; significa che la chiamate c'e' stata
..z:
lea esp, [esp+1024]
pop ebp
pop edi
pop esi
ret 4

; u32 PrendiArgomenti(u32** arr, u32 NArrElements)
; ritorna il numero di argomenti presi CF==0 tutto ok
; alla fine un puntatore permesso del vettore arr
; punta a un array di char che descrive l'argomento
; che risulta essere finito da ' ' spazio o tab
; se non inizia con ' oppure "
; altrimenti e' finito rispettivamente da ' e da "
; altrimenti se errore es il vettore e' tutto riempito
; o i parametri sono sbagliati: ritorna
; il numero di argomenti ed CF==1
; 0j,4i,8b, 12ra,16P_arr, 20P_limite
PrendiArgomenti:
push ebx
push esi
push edi
mov ebx, dword[esp+ 16]
cmp dword[esp+20], 0
jle .e0
cmp ebx, 0
jne .a
..e0: xor eax, eax
..e: stc
jmp .z
..ee: mov eax, ecx
jmp short .e
..a: call GetCommandLineA
mov esi, eax ; nel puntatore 0 vi e' il primo argomento
cmp eax, 0
je .e0
xor ecx, ecx
xor eax, eax
mov edx, dword[esp+ 20]
jmp short .2 ; c=contatore; r=il limite;
..0: inc esi
mov al, [esi]
cmp eax, 0
je .e
cmp eax, edi
jne .0
..1: inc esi ; leva gli eventuali spazi prima
..2: mov al, [esi]
cmp byte[MyTable+eax], Space
je .1
cmp eax, 0
je .3
mov [ebx+ecx*4], esi ; assegna al puntatore il primo carattere
inc ecx
cmp ecx, edx
jae .ee
mov edi, eax
cmp eax, '"'
je .0
cmp eax, 39
je .0
..2a: inc esi
..2b: mov al, [esi]
cmp eax, 0
je .3
cmp byte[MyTable+eax], Space
jne .2a ; scorre la parola
jmp short .1
..3: mov eax, ecx
clc
..z:
pop edi
pop esi
pop ebx
ret 8

LevaSpaziDa_i:
xor eax, eax
..0: mov al, [esi]
cmp byte[MyTable+eax], Space
jne .1
inc esi
jmp short .0
..1: ret

; prende una parola separata da spazi
; se i punta a qualche spazio prima la
; parola => ritorna la prima parola incontrata
; se i punta gia' a una parola, scarta tale
; parola e ritorna quella dopo
FindNextWordTraSPazi_i:
xor eax, eax
mov edx, esi
..0: mov al, [esi]
cmp byte[MyTableR+eax], Space
jne .1
inc esi
jmp short .0
..1: cmp edx, esi
jne .z ; *i non e' spazio
cmp eax, 0
je .z
cmp eax, 13
je .z
cmp eax, 10
je .z
; se e' fine linea esci
; scarta la parola attuale
..2: inc esi
mov al, [esi]
cmp eax, 0
je .z
cmp byte[MyTableR+eax], Space
jne .2
; scarta gli spazi
..3: inc esi
mov al, [esi]
cmp eax, 0
je .z
cmp byte[MyTableR+eax], Space
je .3
..z:
ret

; trova la prossima parola alfanumerica
; o formata da punti
; se i punta a qualche spazio prima la
; parola => ritorna la prima parola incontrata
; se i punta gia' a una parola, scarta tale
; parola e ritorna quella dopo
FindNextWord_i:
xor eax, eax
mov edx, esi
..0: mov al, [esi]
cmp byte[MyTableR+eax], Space
jne .1
inc esi
jmp short .0
..1: cmp edx, esi
jne .z ; *i non e' spazio
cmp eax, 0
je .z
cmp eax, 13
je .z
cmp eax, 10
je .z
; se e' fine linea esci
; scarta la parola attuale
mov dl, [MyTableR+eax] ; La prima lettera
..2: inc esi
mov al, [esi]
cmp eax, 0
je .z
cmp byte[MyTableR+eax], dl
je .2
jmp short .4
; scarta gli spazi
..3: inc esi
mov al, [esi]
cmp eax, 0
je .z
..4: cmp byte[MyTableR+eax], Space
je .3
..z:
ret

; a==128 fine di i con \0
; a== 1 fine di i con \n
; a== 0 trovato qualcosa di diverso
HaLaLineaQualcheParola_i:
xor eax, eax
mov edx, esi
..0: mov al, [edx]
cmp byte[MyTableR+eax], Space
jne .1
inc edx
jmp short .0
cmp eax, 13
jne .1
inc edx
mov al, [edx]
..1: cmp eax, 10
je .4
cmp eax, 0
je .5
xor eax, eax
stc
jmp short .z
..4: mov eax, 1
clc
jmp short .z
..5: mov eax, 128
clc
..z:
ret

; ritorna in c la lunghezza della prossima parola
; incontrata senza far muovere i
WordLenTraSpazi_i:
xor eax, eax
mov ecx, esi ; leva gli spazi
..0: mov al, [ecx]
cmp byte[MyTableR+eax], Space
jne .1
inc ecx
jmp short .0
..1: mov edx, ecx ; conserva la posizione
cmp eax, 0
je .3
cmp eax, 10
je .3
cmp eax, 13
je .3 ; se e' fine linea esci
..2: inc ecx
mov al, [ecx]
cmp eax, 0
je .3
cmp byte[MyTableR+eax], Space
jne .2
; scarta gli spazi
..3: sub ecx, edx
..z:
ret

; ritorna in c la lunghezza della prossima parola
; incontrata senza far muovere i
WordLen_i:
push ebx
xor eax, eax
mov ecx, esi ; leva gli spazi
..0: mov al, [ecx]
cmp byte[MyTableR+eax], Space
jne .1
inc ecx
jmp short .0
..1: mov edx, ecx ; conserva la posizione
cmp eax, 0
je .3 ; se e' fine linea esci
mov bl, [MyTableR+eax] ; La prima lettera
..2: inc ecx
mov al, [ecx]
cmp eax, 0
je .3
cmp byte[MyTableR+eax], bl
je .2
..3: sub ecx, edx
..z:
pop ebx
ret

LenStr_i:
mov eax, esi
jmp short .1
..0: inc eax
..1: cmp byte[eax], 0
jne .0
sub eax, esi
mov ecx, eax
ret


; i+c punta alla fine della
; prossima parola: non modifica i
; modifica a, c[risultato], r
; qui la parola puo' essere delimitata
; da virgolette
FindEndNextWordTraSpazi_i:
call LevaSpaziDa_i
xor eax, eax
mov edx, esi
xor ecx, ecx
mov cl, [esi]
cmp ecx, 0
je .2
inc edx
cmp ecx, '"'
je .1
cmp ecx, "'"
je .1
cmp ecx, 96
je .1
jmp short .4
..0: inc edx
..1: mov al, [edx]
cmp eax, 0
je .2
cmp eax, 10
je .2
cmp eax, 13
je .2
cmp eax, ecx
jne .0
inc edx
..2: mov ecx, edx
sub ecx, esi
clc
jmp short .z
..3: inc edx
..4: mov al, [edx]
cmp byte[MyTable+eax], Space
je .2
cmp eax, 10
je .2
cmp eax, 13
je .2
cmp eax, 0
jne .3
jmp short .2
..z:
ret

; non modifica i
; salta, se sono in parola, l'attuale parola
; trova la fine della prossima parola
; vede se ci sono due punti ":"
; ritorna CF==1 label trovata altrimenti CF==0
; sono preservati tutti i registri anche eax
IsNextWordLabel_i:
push eax
push edx
push ecx
mov edx, esi
xor ecx, ecx
xor eax, eax
mov al, [edx]
cmp eax, 0
je .9
mov cl, [MyTableR+eax]
cmp ecx, Space
je .0
..0a: inc edx
mov al, [edx]
cmp eax, 0
je .9 ; elimina l'attuale parola
cmp byte[MyTableR+eax], cl
je .0a ; nel caso l'attuale carattere nella parola
cmp byte[MyTableR+eax], 0
je .2 ; parola
cmp byte[MyTableR+eax], Space
jne .9
..0: inc edx
..1: mov al, [edx]
cmp byte[MyTableR+eax], Space
je .0
cmp eax, 0
je .9
cmp byte[MyTableR+eax], 0
jne .9
..2: inc edx
mov al, [edx]
cmp byte[MyTableR+eax], 0
je .2
cmp eax, ':'
jne .9
..8: stc
jmp short .z
..9: clc
..z:
pop ecx
pop edx
pop eax
ret

; i+c punta al punto '.' piu' vicino alla fine
; della stringa puntata da i, oppure all'ultimo
; catattere cie' \0
; in "a" vi e' l'ultimo carattere non nullo trattato
; o zero se errore o fine stringa
; NB modifica i (leva gli spazi)
; qui la parola puo' essere delimitata
; da virgolette
FindLastPoint_i:
push ebx
push edx
call LevaSpaziDa_i
xor eax, eax
xor ecx, ecx
xor ebx, ebx
mov cl, [esi]
mov edx, esi
cmp ecx, 0
je .2
inc edx
cmp ecx, '"'
je .1
cmp ecx, "'"
je .1
cmp ecx, 96
je .1
jmp short .4
..0: inc edx ; finisce con a=0,10,13 clc
..1: mov al, [edx]
cmp eax, 0
je .2
cmp eax, 10
je .2
cmp eax, 13
je .2
cmp eax, '.'
je .1a
cmp eax, ecx
jne .0
inc edx
jmp short .2
..1a: mov ebx, edx
jmp short .0
..2: cmp ebx, 0
jne .2a
mov ebx, edx
..2a: mov ecx, ebx
sub ecx, esi
clc
jmp short .z
..3: inc edx
..4: mov al, [edx]
cmp byte[MyTable+eax], Space
je .2
cmp eax, 10
je .2
cmp eax, 13
je .2
cmp eax, '.'
je .5
cmp eax, 0
jne .3
jmp short .2 ; finisce con a=0 clc
..5: mov ebx, edx
jmp short .3
..z:
pop edx
pop ebx
ret

; 0ra, 4Pspazi
Spazi_j:
mov ecx, [esp+4]
cmp ebp, 0
jl .ee
jz .e
cmp ecx, 0
jg .0
..e: mov byte[edi], 0
..ee: stc
jmp short .z
..0: mov byte[edi], ' '
dec ebp
jz .e
inc edi
dec ecx
jnz .0
mov byte[edi], 0
..z:
ret 4


; parametri: i la stringa da leggere
; j la stringa da scrivere
; k la size di j
; alla fine modifica sia i,j,k
; Ritorna in ecx la lunghezza della stringa
; scritta in j
Copy_jki:
push ebp
xor eax, eax
cmp ebp, 0
jg .1
..e: mov ecx, [esp]
sub ecx, ebp
mov byte[edi], 0
stc
jmp short .z
..1: mov al, [esi]
mov [edi], al
cmp eax, 0
je .2
dec ebp
jz .e
inc esi
inc edi
jmp short .1
..2: mov ecx, [esp]
sub ecx, ebp
clc
..z:
lea esp, [esp+4]
ret

; parametri: i la stringa da leggere
; j la stringa da scrivere
; k la size di j
; alla fine modifica sia i,j,k
; Ritorna in ecx la lunghezza della stringa
; scritta in j
CopyMacro_jki:
push ecx
mov dword[esp+ 0], 0
cmp esi, 0
je .e
push esi
call FindMacroWord
cmp eax, 0
je .e
cmp ebp, ecx
jbe .e
mov [esp], ecx
add esi, edx
push esi
push ebp
mov esi, eax
mov ebp, ecx
call DCopy
pop ebp
pop esi
add edi, eax
sub ebp, eax
jmp short .9
..e: stc
jmp short .z
..9: clc
..z:
pop ecx
ret

CopyLine_jki:
push ebp
xor eax, eax
cmp ebp, 0
jg .1
..e: mov ecx, [esp]
sub ecx, ebp
mov byte[edi], 0
stc
jmp short .z
..1: mov al, [esi]
cmp eax, 13
je .1a
cmp eax, 10
je .1a
mov [edi], al
cmp eax, 0
je .2
dec ebp
jz .e
inc esi
inc edi
jmp short .1
..1a: mov byte[edi], 0
..2: mov ecx, [esp]
sub ecx, ebp
clc
..z:
lea esp, [esp+4]
ret


; parametri: i la stringa da leggere
; j la stringa da scrivere
; k la size di j
; alla fine modifica sia i,j,k
; Ritorna in ecx la lunghezza della stringa
; scritta in j
;
; il primo carattere puntato da i
; deve essere " oppure '
; modifica i,j,k,a,c,r
PrendiWordTraVirgolette_jki:
push ebp
xor eax, eax
xor ecx, ecx
cmp ebp, 0
mov cl, [esi]
jl .e
jz .ee
cmp ecx, '"'
je .1
cmp ecx, "'"
je .1
cmp ecx, 96
je .1
jmp short .e
..ee: mov ecx, [esp]
sub ecx, ebp
mov byte[edi], 0
..e: stc
jmp short .z
..1: mov [edi], cl
..2: dec ebp
jz .ee
inc esi
inc edi
mov al, [esi]
mov [edi], al
cmp eax, 0
je .3
cmp eax, ecx
jne .2
dec ebp
inc esi
inc edi
mov byte[edi], 0
..3: mov ecx, [esp]
sub ecx, ebp
clc
..z:
lea esp, [esp+4]
ret

; parametri: i la stringa da leggere
; j la stringa da scrivere
; k la size di j
; alla fine modifica sia i,j,k
; Ritorna in ecx la lunghezza della stringa
; scritta in j
;
; il primo carattere puntato da i
; deve essere " oppure '
; modifica i,j,k,a,c,r
PrendiPseudoWordTraVirgolette_jki:
push ebp
xor eax, eax
xor ecx, ecx
cmp ebp, 0
mov cl, [esi]
jl .e
jz .ee
cmp ecx, '"'
je .1
cmp ecx, "'"
je .1
cmp ecx, 96
je .1
jmp short .e
..ee: mov ecx, [esp]
sub ecx, ebp
mov byte[edi], 0
..e: stc
jmp short .z
..1: mov byte[edi], 'I'
..2: dec ebp
jz .ee
inc esi
inc edi
mov al, [esi]
cmp eax, '.'
je .1a0
cmp byte[MyTable+eax], 2
jbe .1a
..1a0: mov byte[edi], 'I'
jmp short .1b
..1a: mov [edi], al
..1b: cmp eax, 0
je .3
cmp eax, ecx
jne .2
inc esi
..3: mov byte[edi], 0
mov ecx, [esp]
sub ecx, ebp
clc
..z:
lea esp, [esp+4]
ret


; parametri: i la stringa da leggere
; j la stringa da scrivere
; k la size di j
; alla fine modifica sia i,j,k
; Ritorna in ecx la lunghezza della parola
; scritta in j
;
; il primo carattere puntato da i
; non deve essere spazio
; modifica i,j,k,a,c
PrendiWordTraSpazi_jki:
push ebp
xor eax, eax
cmp ebp, 0
jl .e
jz .ee
jmp short .1
..ee: mov ecx, [esp]
sub ecx, ebp
mov byte[edi], 0
..e: stc
jmp short .z
..0: dec ebp
jz .ee
inc esi
inc edi
cmp eax, ','
je .2
cmp eax, ';'
je .2
..1: mov al, [esi]
mov [edi], al
cmp eax, 0
je .3
cmp byte[MyTable+eax], Space
jne .0
..2: mov byte[edi], 0
..3: mov ecx, [esp]
sub ecx, ebp
clc
..z:
lea esp, [esp+4]
ret

; prende parola alfanumerica o di punti
; parametri: i la stringa da leggere
; j la stringa da scrivere
; k la size di j
; alla fine modifica sia i,j,k
; Ritorna in ecx la lunghezza della parola
; scritta in j
;
; il primo carattere puntato da i
; non deve essere spazio
; modifica i,j,k,a,c
PrendiWord_jki:
push ebp
xor eax, eax
cmp ebp, 0
jl .e
jz .ee
mov al, [esi]
mov cl, byte[MyTableR+eax]
jmp short .1
..ee: mov ecx, [esp]
sub ecx, ebp
mov byte[edi], 0
..e: stc
jmp short .z
..0: dec ebp
jz .ee
inc esi
inc edi
mov al, [esi]
..1: mov [edi], al
cmp eax, 0
je .3
cmp byte[MyTableR+eax], cl
je .0
..2: mov byte[edi], 0
..3: mov ecx, [esp]
sub ecx, ebp
clc
..z:
lea esp, [esp+4]
ret



; In i vi e' il nome
; In j vi e' dove lo si vuole scrivere
; In k vi e' la dimensione di j
PrendiWordSpaziVirgolette_jki:
call LevaSpaziDa_i
xor eax, eax
mov al, [esi]
cmp eax, '"'
jne .1
..0: call PrendiWordTraVirgolette_jki
jmp short .2
..1: cmp eax, "'"
je .0
cmp eax, 96
je .0
call PrendiWordTraSpazi_jki
..2:
ret


; ShowHelp(u32* string)
; 0ra, 4P_String
ShowHelp:
mov eax, [esp+4]
mov edx, [stderr]
cmp edx, -1
je .z
push eax
push edx
call SPuts
jc .z
mov edx, [stderr]
push IIPremiInI
push edx
call SPuts
jc .z
mov edx, [stderr]
push edx
call FlushFileBuffers
mov edx, [stdin]
cmp edx, -1
je .z
push edx
push 1024
push qui
call SGetLine
..z:
ret 4


; u32 FormatA(u32* ArrOut,u32 ArrSize,u32* ArrIn)
; 0k,4j,8i,12b,16ra,
; 20PArrOut,24PArrSize,28PArrIn
FormatA:
push ebx
push esi
push edi
push ebp
mov edi, [esp+20]
mov ebp, [esp+24]
mov esi, [esp+28]
cmp edi, 0
je .e
cmp ebp, 0
jle .e
cmp esi, 0
jne .2
..e: stc
jmp .z
..1: call Copy_jki
jmp .z
..2: call LevaSpaziDa_i
cmp eax, ';'
je .1
cmp eax, '%'
je .1
cmp eax, 13
je .1
cmp eax, 10
je .1
cmp eax, 0
je .1
mov eax, dword[esi]
mov edx, dword[esi+4]
cmp eax, "sect"
jne .3
cmp edx, "ion "
je .1
jmp short .4
..f: clc
jmp .z
..3: cmp eax, "SECT"
jne .4
cmp edx, "ION "
je .1
..4: cmp eax, "segm"
jne .3a
cmp edx, "ent "
je .1
jmp short .3b
..3a: cmp eax, "SEGM"
jne .3b
cmp edx, "ENT "
je .1
jmp short .3b
..3b: cmp eax, "resb"
jne .3c
cmp byte[esi+4], ' '
je .1
..3c: cmp eax, "resw"
jne .3d
cmp byte[esi+4], ' '
je .1
..3d: cmp eax, "resd"
jne .3e
cmp byte[esi+4], ' '
je .1
..3e: and edx, 000FFFFFFh
cmp eax, "exte"
jne .3f
cmp edx, "rn "
je .1
..3f: cmp eax, "glob"
jne .3g
cmp edx, "al "
je .1
..3g: cmp eax, "time"
jne .3h
cmp dx, "s "
je .1
..3h:
and eax, 000FFFFFFh
cmp eax, "db "
je .1
cmp eax, "dd "
je .1
cmp eax, "dt "
je .1
cmp eax, "dq "
je .1
cmp eax, "dw "
je .1
cmp eax, "do "
je .1
cmp eax, "dy "
je .1
call FindEndNextWordTraSpazi_i
jc .e
jmp short .4b
..4a: inc edx ; dopo gli spazi
..4b: mov al, [edx]
cmp eax, 0
je .f
cmp byte[MyTable+eax], Space
je .4a
mov eax, dword[edx]
mov ebx, dword[edx+4]

cmp eax, "resb"
jne .1c
cmp byte[edx+4], ' '
je .1
..1c: cmp eax, "resw"
jne .1d
cmp byte[edx+4], ' '
je .1
..1d: cmp eax, "resd"
jne .1e
cmp byte[edx+4], ' '
je .1
..1e:
and ebx, 00000FFFFh
cmp eax, "time"
jne .4c
cmp ebx, "s "
je .1
..4c:
and eax, 000FFFFFFh
cmp eax, "db "
je .1
cmp eax, "dd "
je .1
cmp eax, "dt "
je .1
cmp eax, "dq "
je .1
cmp eax, "dw "
je .1
cmp eax, "do "
je .1
cmp eax, "dy "
je .1
mov ebx, 10
cmp byte[esi+ecx-1], ':'
jne .5
call PrendiWordSpaziVirgolette_jki
jc .e
cmp eax, 0
je .f
sub ebx, ecx
jg .5
mov ebx, 1
..5: push ebx
call Spazi_j
; .e1: pop õ8
mov ebx, 6
call LevaSpaziDa_i
cmp eax, ";"
je .1
call PrendiWordSpaziVirgolette_jki
jc .e
cmp eax, 0
je .f
sub ebx, ecx
jg .6
mov ebx, 1
..6: push ebx
call Spazi_j
..7: call LevaSpaziDa_i
cmp eax, ";"
jne .7a
..5a: mov ebx, 32
mov ecx, edi
sub ecx, [esp+20]
sub ebx, ecx
jg .6a
mov ebx, 1
..6a: push ebx
call Spazi_j
jmp .1
..7a: cmp eax, 0
je .f
cmp eax, ","
je .8
push 2
call Spazi_j
jc .e
..8: call PrendiWordSpaziVirgolette_jki
jc .e
cmp eax, 0
je .f
cmp byte[edi-1], ';'
jne .9
mov byte[edi-1], 0
dec edi
dec esi
jmp short .5a
..9: jmp short .7
..z:
pop ebp
pop edi
pop esi
pop ebx
ret 12


; b1= 40..296 256 buffer fileIn
; b2=300..556 256 buffer fileOut
; b4=580..1604 1024 buffer
; b5=1608..2632 1024 buffer
; 0k,4j,8i,12b,16ra, 20PArr + 3072
; 3092
Beautyfy:
push ebx
push esi
push edi
push ebp
sub esp, 3072
%define InpHandle 4
%define OutHandle 8
%define InpFName 40
%define OutFName 300
mov esi, dword[esp+ 3092]
cmp esi, 0
jne .0
..e1: mov eax, 1
..e: stc
jmp .z
..0: lea edi, [esp+InpFName]
mov ebp, 256
call PrendiWordSpaziVirgolette_jki
jc .e1
lea edi, [esp+OutFName]
mov esi, dword[esp+ 3092]
mov ebp, 256
call PrendiWordSpaziVirgolette_jki
jc .e1
lea edx, [esp+OutFName] ; c==CH_Lunghezza
cmp edi, edx
je .e
mov ecx, edi
sub ecx, edx
jle .e1
mov eax, 256
sub eax, ecx
cmp eax, 12
jle .e1
mov ebx, 0
cmp byte[edi-1], '"'
jne .1a
mov ebx, '"'
jmp short .1b
..1a: cmp byte[edi-1], "'"
jne .1b
mov ebx, "'"
..1b: xor eax, eax
jmp short .2
..ee: jmp .e1
..e2: mov edx, [esp+InpHandle]
push edx
call CloseHandle
mov eax, 2
jmp .e
..1: inc edx
dec ecx
..2: mov al, [edx]
cmp ecx, 0
jle .3
cmp eax, '.'
jne .1
..3: mov dword[edx], "_Btf"
add edx, 4
mov dword[edx], ".asm"
add edx, 4
mov byte[edx], 0
cmp ebx, 0
je .4
mov byte[edx], bl
inc edx
mov byte[edx], 0
..4: lea edx, [esp+InpFName]
push 0
push FILE_ATTRIBUTE_NORMAL
push OPEN_EXISTING
push 0
push 0
push GENERIC_READ
push edx
call CreateFileA
mov [esp+InpHandle], eax

cmp eax, INVALID_HANDLE_VALUE
je .ee
lea edx, [esp+OutFName]
push 0
push FILE_ATTRIBUTE_NORMAL
push CREATE_ALWAYS
push 0
push 0
push GENERIC_WRITE
push edx
call CreateFileA
mov [esp+OutHandle], eax

cmp eax, INVALID_HANDLE_VALUE
je .e2
lea edi, [esp+580]
mov esi, dword[esp+ InpHandle]
mov ebp, dword[esp+ OutHandle]
lea ebx, [esp+1608]
jmp short .5
..e3: mov edx, [esp+InpHandle]
push edx
call CloseHandle
mov edx, [esp+OutHandle]
push edx
call CloseHandle
mov eax, 3
jmp .e
..5: push esi
push 1024
push edi
call SGetLine
jc .e3
cmp eax, 0
je .7
mov [esp], ecx
push edi
push 1024
push ebx
call FormatA
jc .e3
..6: push ebx
push ebp
call SPuts
jc .e3
cmp dword[esp], 0
je .5
..7: mov edx, [esp+InpHandle]
push edx
call CloseHandle
cmp eax, 0
je .e3
mov edx, [esp+OutHandle]
push edx
call FlushCloseHandle
jc .z
clc
..z:
%undef InpFName
%undef OutFName
%undef InpHandle
%undef OutHandle
lea esp, [esp+3072]
pop ebp
pop edi
pop esi
pop ebx
ret 4


; AppendPointName(u8* res, u32 resSize, u8* array1, u8* arr2)
; Ritorna la lunghezza della stringa
; 0k,4j,8i,12b,16ra, 20P_res, 24P_resSize, 28P_arr1, 32P_arr2
AppendPointName:
push ebx
push esi
push edi
push ebp
mov edi, [esp+20]
mov ebp, [esp+24]
mov esi, [esp+28]
cmp edi, 0
je .e
cmp ebp, 1
jle .e
cmp esi, 0
jne .1
..e: xor eax, eax
stc
jmp short .z
..1: call FindLastPoint_i
cmp ecx, ebp
ja .e
push ebp
mov ebp, ecx
call DCopy
pop ebp
jc .e
sub ebp, eax
add edi, eax
mov byte[edi], '.'
dec ebp
jz .e
inc edi
mov byte[edi], 0
mov esi, [esp+32]
cmp byte[esi], '.'
jne .2
dec edi
inc ebp
mov byte[edi], 0
..2: push esi
push ebp
push edi
call CatStr
sub ebp, eax
add edi, eax
mov esi, [esp+20]
cmp byte[esi], '"'
jne .3
cmp ebp, 2
jle .e
mov byte[edi], '"'
inc edi
..3: mov byte[edi], 0
sub edi, esi
mov eax, edi
clc
..z:
pop ebp
pop edi
pop esi
pop ebx
ret 16

; u32 [size] CatStr(u8* dest, u32 Size, u8* stringCat)
; 0j,4ra,8P_dest,12P_size,16P_stringCat a,c,r,j
CatStr:
push edi
mov edi, [esp+8]
mov ecx, [esp+12]
mov edx, [esp+16]
cmp edi, 0
je .e
xor eax, eax
cmp ecx, 1
jg .2
..ee: mov byte[edi], 0
..e: xor eax, eax
stc
jmp short .z
..1: inc edi
dec ecx
jz .e
..2: cmp byte[edi], 0
jne .1
..3: mov al, [edx]
mov [edi], al
cmp eax, 0
je .4
dec ecx
jz .ee
inc edx
inc edi
jmp short .3
..4: mov eax, edi
mov byte[edi], 0
sub eax, [esp+8]
clc
..z:
pop edi
ret 12

InizioTempo:
pushad
call GetTickCount
mov [TempoA], eax
popad
ret

StampaDelta:
pushad
sub esp, 8
call GetTickCount
sub eax, [TempoA]
mov edi, eax
mov esi, [stderr]
push IIIOkIDeltaITimeII
push esi
call SPuts
push edi
call HexPrint ; a=s|B*a=' '|B[a+1]=0
push nl
push esi
call SPuts
add esp, 8
popad
ret

; 0k,4j,8i,12b,16ra, 20P_Arry1 + 2048
; 2068
FaiObj:
push ebx
push esi
push edi
push ebp
sub esp, 2048
mov ebp, [esp+2068]
lea edi, [esp+256]
cmp ebp, 0
jne .1
..e: xor eax, eax
stc
jmp .z
..1: mov dword[esp], ".asm"
mov dword[esp+4], 0
mov eax, esp
push eax
push ebp
push 760
push edi
call AppendPointName
jc .e
call InizioTempo
pushad
mov esi, [stderr]
push IMacro2DIn
push esi
call SPuts
popad
mov eax, ebp
mov edx, edi
call MacroNasm
jc .e
call StampaDelta
lea esi, [esp+1024]
mov eax, INasmwIIIfobjII
mov byte[esi], 0
push eax
push 1020
push esi
call CatStr
jc .e
mov edx, 1020
sub edx, eax
add esi, eax
push edi
push edx
push esi
call CatStr
jc .e
lea esi, [esp+1024]
call InizioTempo
push esi
call SystemA
jc .e
cmp eax, 0
jne .e
call StampaDelta
mov eax, 1
clc ; per ok
..z:
lea esp, [esp+2048]
pop ebp
pop edi
pop esi
pop ebx
ret 4

; 0k,4j,8i,12b,16ra, 20P_Arry1 + 2048
; 2068
FaiPe:
push ebx
push esi
push edi
push ebp
sub esp, 2048
mov ebp, [esp+2068]
lea edi, [esp+256]
cmp ebp, 0
jne .1
..e: xor eax, eax
stc
jmp .z
..1: push ebp
call FaiObj
jc .e ; macro+nasm
mov dword[esp], ".obj"
mov dword[esp+4], 0
mov eax, esp
push eax
push ebp
push 760
push edi
call AppendPointName
jc .e
lea esi, [esp+1024]
mov eax, IalinkIIIoPEIII
mov byte[esi], 0
push eax
push 1020
push esi
call CatStr
jc .e
mov ebx, 1020
sub ebx, eax
add esi, eax
push edi
push ebx
push esi
call CatStr
jc .e
mov edx, IIwin32Ilib
sub ebx, eax
add esi, eax
push edx
push ebx
push esi
call CatStr
jc .e
lea esi, [esp+1024]
call InizioTempo
push esi
call SystemA
jc .e ; Alink
cmp eax, 0
jne .e
call StampaDelta
mov eax, 1
clc
..z:
lea esp, [esp+2048]
pop ebp
pop edi
pop esi
pop ebx
ret 4

; 0k,4j,8i,12b,16ra, 20P_Arry1 + 2048
; 2068
FaiDll:
push ebx
push esi
push edi
push ebp
sub esp, 2048
mov ebp, [esp+2068]
lea edi, [esp+256]
cmp ebp, 0
jne .1
..e: xor eax, eax
stc
jmp .z
..1: push ebp
call FaiObj
jc .e ; macro+nasm
mov dword[esp], ".obj"
mov dword[esp+4], 0
mov eax, esp
push eax
push ebp
push 760
push edi
call AppendPointName
jc .e
lea esi, [esp+1024]
mov eax, IalinkIIoPEIIdllI
mov byte[esi], 0
push eax
push 1020
push esi
call CatStr
jc .e
mov ebx, 1020
sub ebx, eax
add esi, eax
push edi
push ebx
push esi
call CatStr
jc .e
mov edx, IIwin32Ilib
sub ebx, eax
add esi, eax
push edx
push ebx
push esi
call CatStr
jc .e
lea esi, [esp+1024]
call InizioTempo
push esi
call SystemA
jc .e ; Alink
cmp eax, 0
jne .e
call StampaDelta
mov eax, 1
clc
..z:
lea esp, [esp+2048]
pop ebp
pop edi
pop esi
pop ebx
ret 4


; 0k,4j,8i,12b,16ra, 20P_Arry1 + 2048
; 2068
FaiConsole:
push ebx
push esi
push edi
push ebp
sub esp, 2048
mov ebp, [esp+2068]
lea edi, [esp+256]
cmp ebp, 0
jne .1
..e: xor eax, eax
stc
jmp .z
..1: push ebp
call FaiObj
jc .e ; macro+nasm
mov dword[esp], ".obj"
mov dword[esp+4], 0
mov eax, esp
push eax
push ebp
push 760
push edi
call AppendPointName
jc .e
lea esi, [esp+1024]
mov eax, IalinkIIoPEIIsubsysIconI
mov byte[esi], 0
push eax
push 1020
push esi
call CatStr
jc .e
mov ebx, 1020
sub ebx, eax
add esi, eax
push edi
push ebx
push esi
call CatStr
jc .e
mov edx, IIwin32Ilib
sub ebx, eax
add esi, eax
push edx
push ebx
push esi
call CatStr
jc .e
lea esi, [esp+1024]
call InizioTempo
push esi
call SystemA
jc .e ; Alink
cmp eax, 0
jne .e
call StampaDelta
mov eax, 1
clc
..z:
lea esp, [esp+2048]
pop ebp
pop edi
pop esi
pop ebx
ret 4

InterattivoNasm:
push ebx
push esi
push edi
push ebp
sub esp, 1024
mov edi, [stdout]
mov esi, [stdin]
xor ebp, ebp
cmp edi, -1
je .e
cmp esi, -1
je .e
cmp dword[stderr], 0
je .e
call InstallNasm
jnc .1
..e: call FreeMem
stc
jmp .z
..1: mov ebx, IInserisciINasmIMacroIII
..2: mov edx, [stderr]
push ebx
push edx
call SPuts
jc .e
lea eax, [esp+8]
push esi
push 510
push eax
call SGetLine
jc .e
cmp eax, 0
je .7
mov [esp], ecx
lea eax, [esp+8]
lea edx, [esp+512]
push ebp
push eax
push 500
push edx
call LineToNasm
mov ebp, eax
jc .2
lea edx, [esp+512]
push edx
push edi
call SPuts
jc .e
cmp dword[esp], 0
je .2
..7: call FreeMem
clc
..z:
lea esp, [esp+1024]
pop ebp
pop edi
pop esi
pop ebx
ret

ProvaFunzioni:
push ebx
push esi
push edi
push ebp
sub esp, 1024
mov edi, [stdout]
mov esi, [stdin]
xor ebp, ebp
cmp edi, -1
je .e
cmp esi, -1
je .e
cmp dword[stderr], 0
je .e
call InstallRos
jnc .1
..e: call FreeMem
stc
jmp .z
..1: mov ebx, IInserisciINasmIMacroIII
..2: mov edx, [stderr]
push ebx
push edx
call SPuts
jc .e
lea eax, [esp+8]
push esi
push 510
push eax
call SGetLine
jc .e
cmp eax, 0
je .7
mov [esp], ecx
lea eax, [esp+8]
lea edx, [esp+512]

push ebp
push eax
push 500
push edx
call LineToRosAsm
mov ebp, eax
cmp ecx, 0
je .7
; jc .2
lea edx, [esp+512]
push edx
push edi
call SPuts
jc .e
cmp dword[esp], 0
je .2
..7: call FreeMem
clc
..z:
lea esp, [esp+1024]
pop ebp
pop edi
pop esi
pop ebx
ret



; P --> little help
; P -h[elp*] --> little help
; P -howuse --> big help
; P a.asm --> fomat(a.asm) -> a_Btf.asm
; P a.m --> a.asm
; P a.m b.m --> b.m [lo scrive in b]
; P -Ob a.m --> a.asm
; nasmw -fobj a.asm -> a.obj
; P -Pe a.m --> a.asm
; nasmw -fobj a.asm -> a.obj
; alink -oPe a.obj win32.lib -> a.exe
; P -Co a.m --> a.asm
; nasmw -fobj a.asm -> a.obj
; alink -oPe -subsys con a.obj win32.lib -> a.exe
;------------------------------
; "123 456", 7
; 40,44,48, 840 sono 200 elementi
; per memorizzare i possibili parametri

...start:
_main:
AsmMain:
push ebx
push esi
push edi
push ebp
sub esp, 2048
finit
call GetStdIo
jc .e0
lea eax, [esp+40]
push 200
push eax
call PrendiArgomenti
jnc .1
..e: mov ebx, [stderr]
cmp ebx, -1
je .0
push IErroreIdiIargomentiII
push ebx
call SPuts
push ebx
call PrintError
..0: call CloseStdIo
..e0: mov eax, 1
stc
jmp .z
..1: cmp eax, 0
je .e
mov ecx, eax
dec ecx
cmp ecx, 0
je .4
cmp ecx, 1
je .2
jmp .8
..2: mov edx, [esp+ecx*4+40]
cmp byte[edx], '-'
jne .2b
cmp dword[edx], "-In "
jne .2c
..2a: call InterattivoNasm
jmp .y
..2b: jmp .6
..2c: cmp dword[edx], "-In"
je .2a
cmp byte[edx+1], 'h'
jne .e
cmp byte[edx+2], 0
je .4
cmp byte[edx+2], ' '
je .4
cmp dword[edx+1], "help"
je .4
cmp dword[edx+1], "howu"
je .5
jmp .e
..4: push Litlehelp
call ShowHelpConsole
jmp .y
..5: mov eax, dword[edx+5]
and eax, 00000FFFFh
cmp eax, "se"
jne .e
push helpText
call ShowHelpConsole
push MacroDefinizioniGenerali
call ShowMacro
push NasmDef
call ShowMacro
jmp .y
..6: mov esi, edx
call FindLastPoint_i
cmp byte[esi+ecx], 0
je .7
cmp dword[esi+ecx], ".asm"
jne .7
push esi
call Beautyfy
jc .e
jmp .y
..7: xor eax, eax
xor edx, edx
lea edi, [esp+1024]
cmp ecx, 1000
jae .e
mov ebp, ecx
call DCopy
mov dword[edi+eax], ".asm"
mov byte[edi+eax+4], 0
cmp byte[esi], '"'
jne .7a
mov byte[edi+eax+4], '"'
mov byte[edi+eax+5], 0
jmp short .7b
..ee: jmp .e
..7a: cmp byte[esi], "'"
jne .7b
mov byte[edi+eax+4], "'"
mov byte[edi+eax+5], 0
..7b: mov eax, [esp+4+40] ; I argomento
mov edx, edi ; II argomento
..7c: call MacroNasm
jc .ee
jmp .y
..8: cmp ecx, 2
je .8a
jmp .x
..8a: mov ebx, ecx ; conserva il numero di argomenti
mov edx, [esp+ebx*4+40] ; II argomento
mov eax, [esp+ebx*4+40-4] ; I argomento
cmp dword[eax], "-Ob "
jne .9
..8b: push edx
call FaiObj
jc .eee
jmp .y
..9: cmp dword[eax], "-ob "
je .8b
cmp dword[eax], "-Pe "
jne .a
..9a: push edx
call FaiPe
jc .eee
jmp .y
..a: cmp dword[eax], "-pe "
je .9a
cmp dword[eax], "-Co "
jne .b
..aa: push edx
call FaiConsole
jc .eee
jmp .y
..b: cmp dword[eax], "-co "
je .aa
cmp dword[eax], "-Dl "
jne .b1
..b0: push edx
call FaiDll
jc .eee
jmp .y
..b1: cmp dword[eax], "-dl "
je .b0
mov edx, [esp+ecx*4+40] ; II argomento
mov eax, [esp+ecx*4+40-4] ; I argomento
jmp .7c
..eee: mov ebx, [stderr]
cmp ebx, -1
je .c
push IErroreInellIorigineII
push ebx
call SPuts

push ebx
call PrintError
..c: jmp .0
..x: cmp ecx, 3
jne .4
mov eax, [esp+ecx*4+40-8] ; I argomento
mov edx, dword[eax]
and edx, 000FFFFFFh
cmp edx, "-r "
jne .4
mov eax, [esp+ecx*4+40-4] ; II argomento
mov edx, [esp+ecx*4+40] ; III argomento
call MacroRosAsm
jc .ee
..y: call CloseStdIo
xor eax, eax
..z:
lea esp, [esp+2048]
pop ebp
pop edi
pop esi
pop ebx
ret




.



Relevant Pages

  • One RosAsm Pre-parser
    ... cmp eax 0 | ja L0<< ... mov ecx, D ...
    (alt.lang.asm)
  • Re: Macro2D
    ... mov, eax ... cmp eax, -1 ... push STD_INPUT_HANDLE ...
    (alt.lang.asm)
  • ascii to st0
    ... push IDC_ARROW ... cmp eax, 0 ... mov ebp, esp ... cmp dword @Message, WM_CLOSE ...
    (alt.lang.asm)
  • Re: recvfrom
    ... push ebx ... mov eax, ... cmp eax, SOCKET_ERROR ...
    (alt.lang.asm)
  • Re: Insert a byte
    ... push ebx ... mov ebx, dword ... cmp dword, 0 ... ..e0: xor eax, eax ...
    (alt.lang.asm)