Tight_Coder_Ex 17 Posting Whiz in Training

It is different, and yes probably has something to do with alignment, but without seeing code in its entirety and more importantly the switches your passing to GCC it's hard to say why this is happening.

Tight_Coder_Ex 17 Posting Whiz in Training

Definately, as that is what I try to do with my apps, espcially those with high interation loops. I found that link pretty easy, so maybe do your query more like a question that keywords.

Tight_Coder_Ex 17 Posting Whiz in Training

Here is http://www.penguin.cz/~literakl/intel/intel.html instruction set with clocks

Keep in mind, in a multithreaded operating system, cycles are only realative as other concurrent processes are using CPU at same time, which will affect the throughput of application of interest.

Tight_Coder_Ex 17 Posting Whiz in Training

Line 26: loadsb should be lodsb

Tight_Coder_Ex 17 Posting Whiz in Training

What your doing is passing the address of the proceedure to MesssageBox instead of xd

invoke  MessageBox, NULL, addr xd, addr xd, MB_OK.

It will look kid of odd those, your caption being exactly the same as text

Tight_Coder_Ex 17 Posting Whiz in Training

Depending upon the compiler, it will tell you how large these areas can be, but it's not good practice as it actually allocates that much space in your application much better to

arr     dd     0

and then use the appropriate API to allocate whatever space you need and then move the pointer to arr. As an example, for windows XP

push  70000
     push  LMEM_FIXED or LMEM_ZEROINIT
     call  LocalAlloc
     mov   arr, eax
Tight_Coder_Ex 17 Posting Whiz in Training

In Linux INT 80 is probably the best option. This site will probably be a good resource.

I have limited experience with Linux, but have had enough exposure in the past that I may be able to help with specifics

Tight_Coder_Ex 17 Posting Whiz in Training

Example 1: You've declared single byte, whereas word declares 2

array1  dw  4   dup(?)

Example 2: is correct. In both cases you are declaring space in uninialized space and has no effect of executable size. If however you used dup (0) you'd wind up with an executable of 20k bytes.

Tight_Coder_Ex 17 Posting Whiz in Training

What platform are you using, as there is a distinct way of calling interrupts through BIOS, DOS or LINUX.

These calling conventions allow you to access hardware directly (BIOS) or near directly (DOS). Windows just won't allow you to do it at all.

This page deliniates how to use INT 10 Video

Tight_Coder_Ex 17 Posting Whiz in Training

Let's see what you've done so far

Tight_Coder_Ex 17 Posting Whiz in Training
.data
				
  V1		dd		24
  V2		dd		37
  V3		dd		123
  V4		dd		18
  
  V5		dd		-1
  
	-(( 24 + 37 ) - 123) + ( 37 - 18 )
           ( 61 - 123) + 19
          -(-62) + 19
             62  + 19 = 81

		.code
  Start: 			mov	eax, V2                    ; EAX = 37
  			push	eax                        ; Save temporarily
  			sub	eax, V4                    ; 37 - 18 = 19
  			mov	ecx, eax			; ECX = 19
  			
  			pop	eax                        ; EAX = 37 again
  			add	eax, V1			; EAX = 61
  			sub	eax, V3			; EAX = -62
  			neg	eax			; EAX = 62
  			add	eax, ecx			; Resolve parethesis
  			
  			mov	V5, eax			; V5 = 81
  			
 				ret
Tight_Coder_Ex 17 Posting Whiz in Training

Q1: Assuming your using MASM

PUBLIC   Str1

             .const
    Str1     db     'Backward', 0

Then in all other modules you would use

extern   Str1:DWORD

so the linker will resolve the global context

Q2: Eventhough some assembers have "switch" macros, there isn't a switch statement in assembly. It is accomplished by testing and branching accordingly.

Str2     db     'something',0

    cmp    al, 1
    ja    @F
    push  offset Str2
    call  _printf
@@:

These examples are incomplete and meant only to convey a concept

Tight_Coder_Ex 17 Posting Whiz in Training

What part needs to be in assembly?
Is the array necessary?
Calculation to consider interations other than 4?
Where does test1 through 4 come from?

Post the details of the assignment as they were given to you by the instructor

Tight_Coder_Ex 17 Posting Whiz in Training

Sounds like one of these incidious errors and without seeing your entire code, I'm confounded to finding a solution

Tight_Coder_Ex 17 Posting Whiz in Training

I'm not familiar with OpenGL, but I agree with taking a closer look at WM_SIZE as clicking in the non-client area and moving the mouse does trigger WM_SIZE. Most debuggers will allow you to trap an event based on the contents of register or memory, so catch the entry to WM_SIZE and see if it is triggered and single step to follow its path.

Tight_Coder_Ex 17 Posting Whiz in Training

Look for any handlers you have in your app relative to non-client area such as WM_NCLBUTTONDOWN or UP.

Tight_Coder_Ex 17 Posting Whiz in Training

Show an example of what you've done so far

Tight_Coder_Ex 17 Posting Whiz in Training

So what part do you actually need help with?

Which platform?

If Windows, DOS or GUI?

Most importantly show something of the source as you understand it should be done

Tight_Coder_Ex 17 Posting Whiz in Training

You don't need line 18 or line 25 as getenv only takes one argument, that being a string pointer.

I generally like using kernel32 library functions and in this case may work for you

GetEnvironmentVariable

The GetEnvironmentVariable function retrieves the value of the specified variable from the environment block of the calling process. The value is in the form of a null-terminated string of characters.

DWORD GetEnvironmentVariable(
LPCTSTR lpName, // address of environment variable name
LPTSTR lpBuffer, // address of buffer for variable value
DWORD nSize // size of buffer, in characters
);

Line 26 would be replaced with

invoke GetEnviromentVariable, lpName, lpBuffer, nSize

or

push    nSize
        push    lpBuffer
        push    lpName
        call      GetEnvironmentVariable
Tight_Coder_Ex 17 Posting Whiz in Training

This procedure dispatches application defined event handlers and alternately executes default process for both standard or sub/super classed windows.

Map is defined as follows. In most cases I define this table in .data, but in can be in .const also. I choose writeable memory as application can redefine characteristics.

MWMap	            dd	0					; Address of sub or super class default proc
		dw	(MWEnd - MWMap - 6) / 6		; Determine number of messages in map
		dw	WM_DESTROY
		dd	QuitApp
		dw	WM_CREATE
		dd	CMainWnd
  MWEnd	equ	$

Entry point of windows procedure requires only two instructions

MWndProc		proc

	  		mov	esi, offset MWMap			; Point to message map for this window
	  		jmp	ScanMap
	    
  MWndProc		endp

By whatever means you choose to intialize WNDCLASSEX then entry point need only be specified as the 3 parameter

Wc		WNDCLASSEX	< 30h, CS_HREDRAW or CS_VREDRAW, MWndProc, 0, 0,\
				 0, 0, 0, COLOR_APPWORKSPACE + 1, NULL, AppName, 0>

Here is an example of the actual handler

CMainWnd		proc	uses	ebx edi
  
  		LOCAL	Rc:RECT
  		
  			lea	ebx, Rc
  			mov	edi, [esi]
  			
  			invoke	GetClientRect, dword ptr [esi], ebx	; Get client windows metrics
  			invoke	InflateRect, ebx, -32, -32		; Adjust for border
 			mov	eax, [ebx + 8]
 			sub	eax, [ebx]
 			  			
			invoke	CreateWindowEx,
				WS_EX_STATICEDGE or WS_EX_CLIENTEDGE,  ADDR EditClass, NULL, \
				WS_VISIBLE or WS_BORDER or WS_CHILD or ES_AUTOHSCROLL, \
				32, 32, eax, 22, edi, 64, Wc.hInstance, NULL
			
			mov	EditWnd, eax
			mov	edi, eax				; Save copy of window
			and	eax, eax
			jnz	@f
			
			int	3
			
		@@:	invoke	SetWindowLong, eax, GWL_WNDPROC, …
Tight_Coder_Ex 17 Posting Whiz in Training

I use GetTickCount in a lot of my applications, so I built this snippet to convert to hours minutes and seconds. Leading extraneous data is excluded from output.

Tight_Coder_Ex 17 Posting Whiz in Training

User can enter an ascii string of up to 48 characters consisting of 1's or 0's, with randomly interspersed whitespace.

IE: 1011111001011110 will be evaulated equally to
[1011][111....cc001cccx01 111hhhh0

Algorithm parses from right to left so will be truncated at 16 position

Purpose is to give all those still programming in 16 bit an example they can learn from and hopefully embellish and post their version

Tight_Coder_Ex 17 Posting Whiz in Training

There are numerous calls to Win32 API that return detailed information as to failure via GetLastError (). I've devised a method by which to get the textual information corresponding to error and the address of the call that caused the violation. If GetLastError () returns null, then it can serve as possibly a simpler way to use MessageBox (). I've only tested this on XP, but it failed miserably on a Sony Lapton running ME.

What you need to define is; style for message box, Caption & Text. If last error was not null, then you'll see

Error < 128> @ [ 40103A ]

Message from system

What you defined as message body text

and then dependant upon MessageBox style buttons for your response

Tight_Coder_Ex 17 Posting Whiz in Training

Additional features will be added to this section of code such as fixing window size proportial to monitors resolution and subclassing the single edit control of this program. You'll notice I don't call ShowWindow here as WS_VISIBLE in windows style is defined.

Tight_Coder_Ex 17 Posting Whiz in Training

I've never done anything in assembly for console, although the concept is very simple. This series I'm doing now will only have another couple of posts and it will be complete as far as displaying a window on the monitor. What I can do and what I think might be fairly informative is displaying "Hello World" in the default GUI font only while the left mouse button is being pressed at the cursor position at that time. This will be a little more consitent with my objective of this series of snippets. At that time I will post the entire source in thread18331. The complete source encorporates all the snippets I'm posting here.

Tight_Coder_Ex 17 Posting Whiz in Training

I've often wondered why M$ didn't make creating a window a simple as registering a class in that only one 32 bit value need be passed to calling routine. Although this is not ground breaking code design it does facilitate calling code only set EBX to point to all values required by CreateWindowEx.

Tight_Coder_Ex 17 Posting Whiz in Training

I prefer to use this method as it doesn't clutter a windows procedure with dozens of conditionals and it address my primary objective of coding as tight as possible [28 bytes]. If you think my method can be improved upon in size and/or speed please post your solution.

Note: I have not tested this algorithym yet

Tight_Coder_Ex 17 Posting Whiz in Training

The next few posts will be what's required to get a window to display on the monitor. The code between Main & Pump will probably change as time goes on, but for now this is all that is required. I choose this method or placement because only 28 bytes of stack are used at this point. Nesting pump deeper in application might unnecessarily retain unused stack space.

Tight_Coder_Ex 17 Posting Whiz in Training

These are a pair of routine I use quite often. I know MemSet is virtualy the same as ZeroMemory in kernel32.dll, but there may be a time I want to use these in an embedded system where this dll won't be avaliable.

Tight_Coder_Ex 17 Posting Whiz in Training

As part of a larger hobby project that I'm undertaking being a doubly linked list for 95/98/XP, this is the first in a series that I will be posting.

Upon completion, I will have a complete application written in assembly for the Windows platform. Compiled with NASM

Tight_Coder_Ex 17 Posting Whiz in Training

I am curious as to which compiler you used to create the executable. In know with VC++, not typecasting WindowProcedure will cause and error.

Secondly, why MS$ has done this I'll never know, but not adding 1 to the desired background color will yeild the wrong color. I must use HBRUSH (COLOR_BACKGROUND + 1) with VC++.

Maybe the headers you use have the background colors adjusted already.

Tight_Coder_Ex 17 Posting Whiz in Training

please help me quickly as you can i need it before sunday

Thanks you Before

Oh, Oh, panic homework assignment.

I don't understand what relevance word and sentence limits have in so much as the reversal algorithm and can there be more than one sentence in the string.

AND... are you using an Intel processor.

If so, establish a pointers to the first and last characters of string and use a register to temporarily move each character.

mov     al, [esi]
xchg    [edi], al
mov    [esi], al
inc      esi
dec     edi

Test for completion by:

If input length is even test if EDI < ESI finished; otherwise EDI = ESI.

AND NO! Because you haven't shared any of your code this is a much as I'll share with you.

Tight_Coder_Ex 17 Posting Whiz in Training

Interesting Nathan, however your example renders the computer redundant as you've already done the calculating, therefore a word processor would have been a better choice.

I do agree with your points of optimization and size should be included in there somewhere too, but at the end of the day examples should always exemplify the computers underlying premise, in that it does the computing.

Hypothetically, we are working in an IT department and now charged with modifying our applications to be dynamic in nature. IE: operator selectable range and pairs of factors (30,000 -> 200,000 & 8's and 18's). My application may increase in size to possibly 1500 bytes, yours would be 3.7 megs 2,500 times larger than mine.

I not beginning to suggest my code is the best or even better example, but rather optimization is far more encompassing and if I were to be in an interview and the recruiter was to evaluate my abilities based on "FIZZBUZZ", I would just simply get up and leave the room.

There doesn't seem to be much interest from others, but in the spirit of competition why don't we modify our applications to be dynamic as indicated above, post our examples and maybe if we are lucky we can have others critique them.

Criteria: User defined range
User defined factors to a maximum of 12

Tabbed output ie:

1
2
3 Fizz
4
5 Buzz
6 Fizz
7

Tight_Coder_Ex 17 Posting Whiz in Training

Here is my version of FizzBuss and it took me 2 1/2 hrs. I've read these little
blurbs about how this is used to test potential programmers and in fact the
overall method only took me 20 seconds to determine, but utilizing instructions
that are availiable in later CPU's took a little longer.

If there is interest in this thread I look forward to seeing others optimizations
that are tighter than mine (in ASM) and would probably work on my own version
that is better.

; Written using ML

		.686P
		.model flat, stdcall
		option casemap:none

	include	windows.inc
	include	kernel32.inc
	include	user32.inc

	includelib kernel32.lib
	includelib user32.lib

	Main	proto
	Print	proto	:DWORD

		.data

 Prompt1	db	13, 10, 13, 10, '3 & 5s Multiples', 13, 10
		db	'----------------', 13, 10, 0
 Epilogue	db	13, 10, '-- DONE --', 13, 10, 13, 10, 0

 Prompt2	db	'Fiss', 0
 Prompt3	db	'Buzz', 0
 CRLF		db	13, 10, 0
 FMT		db	'%4d', 0

		.data?

  StdOut	dd	?

		.code
; =============================================================================

  start:	invoke	GetStdHandle, STD_OUTPUT_HANDLE
		mov	StdOut, eax
		invoke	Print, offset Prompt1
		invoke	Main
		invoke	Print, offset Epilogue
		ret

;------------------------------------------------------------------------------
  Main		proc

		xor	eax, eax	; Intiialize working registers
		mov	ecx, eax
 		xor	 cx, 801H

	L1:	inc	eax		; bump counter
		cmp	 al, 100
		ja	Done		; and process till 100

		invoke	Print, offset CRLF	; append CRLF to previous output

 		shl	 cx, 1		; Shift mask bits for 3's & 5's
		pushfd
		btr	ecx, 3		; Test bit 3 and …
Tight_Coder_Ex 17 Posting Whiz in Training

Hello, I tried to convert below code, but I couldn't..

Actually that's not correct, you did convert it and a reasonably good job too, the only problem is it's not working as expected.

1. You only initialize AL to -1 (255 or 0FFH) once and then inside your loop it's modified.

L1:    push    eax
         sub      al, [esi]
         stosb
         pop     eax
         loop    L1

Note: mov [esi], al and then incrementing ESI is not wrong, it's just STOSB saves code space.

Tight_Coder_Ex 17 Posting Whiz in Training

Visualization is probably one of the best methods to comprehension. Invoke DEBUG and then step through the program one instruction at a time and just observe what's going on. OLLYBUG is even better as it lets you visualize registers memory and opcodes in a cleaner fashion

Tight_Coder_Ex 17 Posting Whiz in Training
Outer:   inc eax
            call Writeint
            push ecx
            mov  ecx, 3
Inner:   inc eax
            call Writeint
            loop Inner
            pop  ecx
            loop Outer

Your not very specific with iterators, so I assume you want to loop 3 times inner for every outer. If not, you just have to change the value of ECX before entering inner loop

Tight_Coder_Ex 17 Posting Whiz in Training

Your question if far to arbitrary to give a concise answer and google will give you lots of links to examples.

Tight_Coder_Ex 17 Posting Whiz in Training

masm32.com has all the resources you need to get started

Tight_Coder_Ex 17 Posting Whiz in Training

Maybe consider writing a small boot loader and use BIOS calls instead. Most of the functionality you need is provided by any of the PC BIOS's. That way you are completely independent of any operating system including DOS. As your project develops, then inevitably you can get rid of any BIOS dependence too like Linux

Tight_Coder_Ex 17 Posting Whiz in Training

I've gotten it to output in address format

Your computer must run quite a bit different than mine then.

Once you've entered your string

char word [80];
cin >> word;

or whatever size you think you need, then just cycle through all the characters changing # to carriage returns and anything after spaces and periods to upper case

int pntr;
for (pntr = 0; pntr < strlen (word); pntr++) 
     .... conditional code here
        word [pntr] ^= 0x20;

Invent whatever looping operation you like with DO, FOR or WHILE with either conditionals or SWITCH.

If your code would have at least output in the proper format I would have given you the solution, but it doesn't come anywhere near that.

Tight_Coder_Ex 17 Posting Whiz in Training

You can also let 'c','p' & 't' fall through to 'g'

switch (ch)
	{
		case 'c': 
		case 'p': 
		case 't': 
		case 'g': cout << "Option '" << ch << "' selected\n";
                             break;

		default : cout << msg;
			cin.clear();
			while (cin.get() != '\n')
				continue;
			invalid = true;
	}
Tight_Coder_Ex 17 Posting Whiz in Training

I also remebered the way I wanted to do it

LPMINMAXINFO  Info
        Info = LPMINMAXINFO (lParam)

I don't believe their is any advantage this way other than less to type and easier to read?

Tight_Coder_Ex 17 Posting Whiz in Training

Post your code please so we can see exactly what it is you have done

Tight_Coder_Ex 17 Posting Whiz in Training

Thank-you Duoas, my adaptation is as follows and works as expected

case	WM_GETMINMAXINFO:
	((LPMINMAXINFO) lParam)->ptMinTrackSize.x = WndInfo.MaxWidth;
	((LPMINMAXINFO) lParam)->ptMaxTrackSize.x = WndInfo.MaxWidth;
	((LPMINMAXINFO) lParam)->ptMaxTrackSize.y = WndInfo.MaxHeight;
	((LPMINMAXINFO) lParam)->ptMinTrackSize.y = WndInfo.MinHeight;
   break;
Tight_Coder_Ex 17 Posting Whiz in Training

How would I declare a pointer to MINMAXINFO that is passed to WPARAM

In WM_GETMINMAXINFO wParam is a pointer to a place on the stack that holds MINMAXINFO. I've tried

MINMAXINFO *Info;
Info = MINMAXINFO *wParam;

and several other variations to no avail.

Thanks

Tight_Coder_Ex 17 Posting Whiz in Training

Actually what you want is someone to do your homework not help with a specific problem. I can think of three places where you could find this exact answer, but I think you should at least make a feeble attempt at googling anyway.

Salem commented: Bang on the money! +13
Tight_Coder_Ex 17 Posting Whiz in Training

Based on your example and because you have variable length records SCASB is your best option

mov     edi, Emp1
mov     al, '$'
xor     ecx, ecx
dec     ecx
repnz    scasb

Now you are pointing to the numeric values and you just have to add 8 to edi to point to the next employee.

Although this does work, it is very problematic. Fixed record lengths or pointers via a table as Ancient Dragon has pointed out are the best way s to go.

Tight_Coder_Ex 17 Posting Whiz in Training

try

invoke RegOpenKeyEx HKEY_LOCAL_MACHINE, ADDR szRegSubKey, NULL, KEY_ALL_ACCESS, ADDR hKey)
Tight_Coder_Ex 17 Posting Whiz in Training

Assuming EAX is already null

or ah, 7
or al, 8a

would give you that result

ROL SAL SHL and instructions to do bitwise shifts either left in this case or right using ROR RAR SHR.

Knowing the instruction set goes a long way to becoming an effective assembly programmer