String merging, in assembly language, generally use loop and cx register, programming by yourself;
If it is win32 assembly, you can use the movsb instruction;
Generally, you will encounter splicing SQL statements in the development of applications. In C# languages, you can use the plus sign concatenated by strings; if you use the above two methods in assembly, it is extremely troublesome to splice SQL statements;
Consider using win32 API to achieve;
1.asm; uses lstrcpy, lstrcat functions;
MessageBox is for debugging and can be commented out;
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
; by bobo
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
.386
.model flat, stdcall
option casemap :none
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
include windows.inc
include user32.inc
includelib user32.lib
include kernel32.inc
includelib kernel32.lib
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
; Equ 等值定义
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
ICO_MAIN equ 1000h ;图标
DLG_MAIN equ 1
IDC_TXT1 equ 2001
IDC_TXT2 equ 2002
IDC_TXT3 equ 2003
IDC_TXT4 equ 2004
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
.data?
hInstance dd ?
sztxt1 db 50 dup (?)
sztxt2 db 50 dup (?)
sztxt3 db 50 dup (?)
.data
insstr BYTE "insert into mytable ",0h
jhstr BYTE " + ",0h
caption db "SQL拼接",0
sqlstr BYTE SIZEOF insstr DUP(0),0h
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
.code
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
_ProcDlgMain proc uses ebx edi esi hWnd,wMsg,wParam,lParam
mov eax,wMsg
.if eax == WM_CLOSE
invoke EndDialog,hWnd,NULL
.elseif eax == WM_INITDIALOG
invoke LoadIcon,hInstance,ICO_MAIN
invoke SendMessage,hWnd,WM_SETICON,ICON_BIG,eax
.elseif eax == WM_COMMAND
mov eax,wParam
.if ax == IDOK
;invoke EndDialog,hWnd,NULL
invoke GetDlgItemText,hWnd,IDC_TXT1,addr sztxt1,sizeof sztxt1
invoke GetDlgItemText,hWnd,IDC_TXT2,addr sztxt2,sizeof sztxt2
invoke GetDlgItemText,hWnd,IDC_TXT3,addr sztxt3,sizeof sztxt3
invoke lstrcpy, addr sqlstr, addr insstr
invoke lstrcat, addr sqlstr, addr sztxt1
invoke lstrcat, addr sqlstr, addr jhstr
invoke lstrcat, addr sqlstr, addr sztxt2
invoke lstrcat, addr sqlstr, addr jhstr
invoke lstrcat, addr sqlstr, addr sztxt3
invoke MessageBox,NULL,addr sqlstr,addr caption,MB_OK
invoke SetDlgItemText,hWnd,IDC_TXT4,addr sqlstr
.endif
.else
mov eax,FALSE
ret
.endif
mov eax,TRUE
ret
_ProcDlgMain endp
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
start:
invoke GetModuleHandle,NULL
mov hInstance,eax
invoke DialogBoxParam,hInstance,DLG_MAIN,NULL,offset _ProcDlgMain,NULL
invoke ExitProcess,NULL
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
end start
1.rc;
#include <resource.h>
#define ICO_MAIN 0x1000 //图标
#define DLG_MAIN 1
#define IDC_TXT1 2001
#define IDC_TXT2 2002
#define IDC_TXT3 2003
#define IDC_TXT4 2004
ICO_MAIN ICON "Main.ico"
DLG_MAIN DIALOG 350, 250, 300, 250
STYLE DS_MODALFRAME | WS_POPUP | WS_VISIBLE | WS_CAPTION | WS_SYSMENU
CAPTION "Win32汇编拼接SQL语句"
FONT 9, "宋体"
{
EDITTEXT IDC_TXT1, 50, 15, 200, 25, ES_AUTOHSCROLL | WS_BORDER | WS_TABSTOP
CTEXT "姓名:", -1, 5, 15, 40, 25
EDITTEXT IDC_TXT2, 50, 60, 200, 25, ES_AUTOHSCROLL | WS_BORDER | WS_TABSTOP
CTEXT "职务:", -1, 5, 60, 40, 25
EDITTEXT IDC_TXT3, 50, 105, 200, 25, ES_AUTOHSCROLL | WS_BORDER | WS_TABSTOP
CTEXT "部门:", -1, 5, 105, 40, 25
EDITTEXT IDC_TXT4, 50, 150, 200, 25, ES_AUTOHSCROLL | WS_BORDER | WS_TABSTOP
CTEXT "拼接的SQL:", -1, 5, 150, 40, 25
DEFPUSHBUTTON "GO!", IDOK, 58, 210, 50, 14
CONTROL "", -1, "Static", SS_ETCHEDHORZ | WS_CHILD | WS_VISIBLE, 6, 190, 103, 1
}
The operation is as follows; the spliced content is placed in the last text box;
Build process
It seems to be basically usable; you can add or change the code for the double quotation marks and field names in the spliced SQL; you can adjust the rc file in the interface;