Click here to Skip to main content
15,898,222 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
QuestionODS_HOTLIGHT not work Pin
thanhvinh09065-Sep-09 21:49
thanhvinh09065-Sep-09 21:49 
AnswerRe: ODS_HOTLIGHT not work Pin
Code-o-mat5-Sep-09 23:43
Code-o-mat5-Sep-09 23:43 
GeneralRe: ODS_HOTLIGHT not work Pin
thanhvinh09066-Sep-09 3:06
thanhvinh09066-Sep-09 3:06 
GeneralRe: ODS_HOTLIGHT not work Pin
Code-o-mat6-Sep-09 10:08
Code-o-mat6-Sep-09 10:08 
AnswerRe: ODS_HOTLIGHT not work Pin
Iain Clarke, Warrior Programmer6-Sep-09 9:16
Iain Clarke, Warrior Programmer6-Sep-09 9:16 
QuestionLabel adresses in inline assembly Pin
Remco Hoogenboezem5-Sep-09 11:21
Remco Hoogenboezem5-Sep-09 11:21 
AnswerRe: Label adresses in inline assembly Pin
Stuart Dootson5-Sep-09 13:46
professionalStuart Dootson5-Sep-09 13:46 
AnswerRe: Label adresses in inline assembly Pin
Randor 5-Sep-09 16:24
professional Randor 5-Sep-09 16:24 
Hi Remco,

I created this little inline assembly sample for you. It loads the addresses of code labels into a jump table and allows you to jump to the offset based on a user choice. I commented each line.

#include "stdafx.h"

int _tmain(int argc, _TCHAR* argv[])
{
	#pragma pack (1)
		unsigned long table[3] = {0};
	#pragma pack(pop)

	char szError[] = "Invalid choice.\n";
	char szPrompt[] = "Enter a number between 1 and 3:\n";
	char szNotify[] = "You entered jump number: %d";
	char szFmt[] = "%d";
	int iChoice =0;
	int iSizeArray = (sizeof(table) / sizeof(table[0]));

	__asm
	{
		lea esi, table			;Load address of table into esi
		mov edx, DWORD PTR jump1		;Move address of jump1 into edx
		mov [esi], edx			;Move edx into table[0]
		add esi, 4				;Increment esi by size of unsigned long
		mov edx, DWORD PTR jump2		;Move address of jump2 into edx
		mov [esi], edx			;Move edx into table[1]
		add esi, 4				;Increment esi by size of unsigned long
		mov edx, DWORD PTR jump3		;Move address of jump3 into edx
		mov [esi], edx			;Move edx into table[2]
		lea eax, szPrompt			;Load effective address of prompt
		push eax				;push eax onto stack
#ifdef _DLL						;Are we dynamically linked to C runtime?
		call DWORD PTR printf		;Call dynamic linked printf
#else
		call printf				;Call static linked printf
#endif
		add esp, 4				;adjust stack pointer because we pushed eax
		lea eax, iChoice			;Load effective address of iChoice
		push eax				;Push it onto the stack
		lea ebx, szFmt			;Load effective address of fmt
		push ebx				;Push it on the stack
#ifdef _DLL						;Are we dynamically linked to C runtime?
		call DWORD PTR scanf		;Call dynamic linked scanf
#else
		call scanf				;Call static linked scanf
#endif
		add esp, 8				;adjust stack pointer because we pushed eax and ebx
		mov eax, iChoice			;Move iChoice value into eax
		mov ebx, iSizeArray		;Move the size of our array into ebx 
		cmp eax, ebx				;compare
		ja error				;Jump to the error lable if iChoice is larger than table array
		dec eax					;Decrement iChoice by 1 because the table is zero based array
		lea esi, table			;Load address of table into esi
		mov eax,[esi + 4*eax]		;Move value of table array onto eax by calculating offset
		jmp eax				;Jump to address stored in eax
jump1:
		mov eax, 1				;Move number 1 into eax
		jmp notify				;Absolute jump to notify label
jump2:
		mov eax, 2				;Move number 1 into eax
		jmp notify				;Absolute jump to notify label
jump3:
		mov eax, 3				;Move number 1 into eax
		jmp notify				;Absolute jump to notify label
error:
		lea eax, szError			;Load effective address of error
		push eax				;push eax onto stack
#ifdef _DLL						;Are we dynamically linked to C runtime?
		call DWORD PTR printf		;Call dynamic linked printf
#else
		call printf				;Call static linked printf
#endif
		add esp, 4				;adjust stack pointer because we pushed eax
		jmp end				;Absolute jump to end label
notify:
		push eax
		lea ebx, szNotify			;Load effective address of notify
		push ebx
#ifdef _DLL						;Are we dynamically linked to C runtime?
		call DWORD PTR printf		;Call dynamic linked printf
#else
		call scanf				;Call static linked printf
#endif
		add esp, 8				;adjust stack pointer because we pushed eax and ebx
end:
	}
	return 0;
}


Best Wishes,
-David Delaune
GeneralRe: Label adresses in inline assembly Pin
Stuart Dootson5-Sep-09 23:39
professionalStuart Dootson5-Sep-09 23:39 
AnswerRe: Label adresses in inline assembly Pin
Remco Hoogenboezem6-Sep-09 0:56
Remco Hoogenboezem6-Sep-09 0:56 
GeneralRe: Label adresses in inline assembly Pin
Luc Pattyn6-Sep-09 1:16
sitebuilderLuc Pattyn6-Sep-09 1:16 
GeneralRe: Label adresses in inline assembly Pin
Remco Hoogenboezem6-Sep-09 9:02
Remco Hoogenboezem6-Sep-09 9:02 
GeneralRe: Label adresses in inline assembly Pin
Luc Pattyn6-Sep-09 9:32
sitebuilderLuc Pattyn6-Sep-09 9:32 
QuestionHow to handle breaks during debugging Pin
prithaa5-Sep-09 8:43
prithaa5-Sep-09 8:43 
AnswerRe: How to handle breaks during debugging Pin
Stuart Dootson5-Sep-09 10:23
professionalStuart Dootson5-Sep-09 10:23 
GeneralRe: How to handle breaks during debugging Pin
prithaa5-Sep-09 20:19
prithaa5-Sep-09 20:19 
GeneralRe: How to handle breaks during debugging Pin
Stuart Dootson5-Sep-09 23:36
professionalStuart Dootson5-Sep-09 23:36 
GeneralRe: How to handle breaks during debugging Pin
prithaa6-Sep-09 0:20
prithaa6-Sep-09 0:20 
GeneralRe: How to handle breaks during debugging Pin
Stuart Dootson6-Sep-09 0:57
professionalStuart Dootson6-Sep-09 0:57 
GeneralRe: How to handle breaks during debugging Pin
prithaa6-Sep-09 1:00
prithaa6-Sep-09 1:00 
GeneralRe: How to handle breaks during debugging Pin
Stuart Dootson6-Sep-09 1:03
professionalStuart Dootson6-Sep-09 1:03 
GeneralRe: How to handle breaks during debugging Pin
iraclyKv6-Sep-09 23:50
iraclyKv6-Sep-09 23:50 
AnswerRe: How to handle breaks during debugging Pin
Iain Clarke, Warrior Programmer6-Sep-09 9:25
Iain Clarke, Warrior Programmer6-Sep-09 9:25 
GeneralRe: How to handle breaks during debugging Pin
prithaa6-Sep-09 19:11
prithaa6-Sep-09 19:11 
QuestionCalling Unmanaged Class From DLL Pin
İsmail Durmaz5-Sep-09 5:27
İsmail Durmaz5-Sep-09 5:27 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.