The MASM Forum

General => The Laboratory => Topic started by: Biterider on March 10, 2024, 01:12:02 AM

Title: Assembler in Windows OS
Post by: Biterider on March 10, 2024, 01:12:02 AM
Hi
Discussing WinOS sources with a friend of mine, I remembered that some years ago the NT5 (~WinXP) sources were leaked. Today they can be legally downloaded from Microsoft's repository here https://github.com/tongzx/nt5src (https://github.com/tongzx/nt5src)

If you download it and search for dir .asm files, you will find a ton of gems. Granted, they are from older times, but still very interesting.

There are whole chunks of code that our greedy specialists will dissect and analyse to finally give their verdict.

Some things I found are the implementation of critical sections, GDI procedures, x87 emulation, the cruntime memcpy, memcmp, etc. etc.

You could spend hours reading this fascinating stuff.  :biggrin:


Biterider

Title: Re: Assembler in Windows OS
Post by: fearless on March 10, 2024, 02:18:10 AM
That and the ReactOS are good sources of information related to all things win32 api related: https://github.com/reactos/reactos (https://github.com/reactos/reactos)

How the various standard and common controls are created: edit, listbox, combo, listview, treeview, richedit etc.

Could be that the richedit control is of particular interest to jj2007 - who could take the source and adapt it further or fix some issues?
Title: Re: Assembler in Windows OS
Post by: jj2007 on March 10, 2024, 06:13:39 AM
Quote from: fearless on March 10, 2024, 02:18:10 AMCould be that the richedit control is of particular interest to jj2007 - who could take the source and adapt it further or fix some issues?

Guess what? I already looked at it... :biggrin:

But my C is rusty, and I can't find assembler files in the RichEdit section. That archive is huge, over 2GB compressed. I wanted to search for *.asm files inside nt5src-master.zip, but UnzipInit (https://www.jj2007.eu/MasmBasicQuickReference.htm#Mb1392) gives me HeapAlloc error. One of the pretty rare occasions where 32-bit applications meet their limits :cool: 

My 7-zip does not have a search function, strange. In the end I had to extract everything, and found some files (sorted with largest files on top - 96027 bytes for ntfsn98.asm):
D:\WinXpSource\Source\XPSP1\NT\base\boot\bootcode\ntfs\i386\ntfsn98.asm
D:\WinXpSource\Source\XPSP1\NT\base\boot\bootcode\ntfs\i386\ntfsboot.asm
D:\WinXpSource\Source\XPSP1\NT\base\boot\bootcode\etfs\i386\etfsboot.asm
D:\WinXpSource\Source\XPSP1\NT\base\boot\bootcode\fat\i386\fat32nec.asm
D:\WinXpSource\Source\XPSP1\NT\base\boot\bootcode\fat\i386\fat32bt.asm
D:\WinXpSource\Source\XPSP1\NT\base\boot\bootcode\fat\i386\fatboot.asm
D:\WinXpSource\Source\XPSP1\NT\base\boot\bootcode\fat\i386\fatnec98.asm
D:\WinXpSource\Source\XPSP1\NT\base\boot\bootcode\mbr\i386\x86mboot.asm
D:\WinXpSource\Source\XPSP1\NT\base\boot\bd\i386\trap.asm
D:\WinXpSource\Source\XPSP1\NT\base\boot\bootcode\etfs\i386\bootfix.asm
D:\WinXpSource\Source\XPSP1\NT\base\boot\bd\i386\state.asm
D:\WinXpSource\Source\XPSP1\NT\admin\wmi\wbem\providers\smbios\smbdpmi\startup.asm
Title: Re: Assembler in Windows OS
Post by: NoCforMe on March 10, 2024, 07:28:19 AM
Wow. A treasure trove for sure. Haven't looked yet but will for sure.
Title: Re: Assembler in Windows OS
Post by: LiaoMi on March 10, 2024, 10:43:25 AM
Quote from: Biterider on March 10, 2024, 01:12:02 AMToday they can be legally downloaded from Microsoft's repository here https://github.com/tongzx/nt5src (https://github.com/tongzx/nt5src)
Hi Biterider,

I don't think it's legal, they're just tired of deleting it :)
Title: Re: Assembler in Windows OS
Post by: NoCforMe on March 10, 2024, 11:20:33 AM
I wonder about that. Seems to me that Micro$oft is pretty aggressive in protecting its intellectual property, so if they know it's there, they're probably OK with it, since it's legacy code.

My guess, anyhow.
Title: Re: Assembler in Windows OS
Post by: sinsi on March 10, 2024, 12:57:36 PM
Quote from: jj2007 on March 10, 2024, 06:13:39 AMMy 7-zip does not have a search function, strange.
View -> Flat View then View -> Type will sorta sort them.

1430 / 302535 are .asm
Title: Re: Assembler in Windows OS
Post by: jj2007 on March 10, 2024, 08:46:30 PM
Quote from: sinsi on March 10, 2024, 12:57:36 PM1430 / 302535 are .asm

That is a bit more than the handful found after extracting everything (reply #3). I had the feeling that 7-zip had some problems; my XPSP1 folder is "only" about 530MB... oh well :cool:
Title: Re: Assembler in Windows OS
Post by: Biterider on March 11, 2024, 04:43:24 AM
Hi
Still looking at some interesting assembler code :biggrin:
I found a syntax that I had never seen before

  lea r10, 8[rax]
Did you know that this is equivalent to
  lea r10, [rax+8]
Biterider
Title: Re: Assembler in Windows OS
Post by: greenozon on March 11, 2024, 07:57:58 AM
For those who look for assembler - it's possible to explore it right on the GH repo
how?
press '/' then type in .asm
it'll give you 2K+ files :)

2.4k files
 (103 ms)
2.4k files
in
tongzx/nt5src
(press backspace or delete to remove)

Title: Re: Assembler in Windows OS
Post by: NoCforMe on March 11, 2024, 11:21:11 AM
Nifty, I'm sure, but it looks as if you have to be signed up with GitHub for that to work.
Title: fDiv Bug
Post by: Biterider on March 17, 2024, 01:15:03 AM
Hi
For those of you who remember the old fdiv pentium bug (Pentium_FDIV_bug (https://en.wikipedia.org/wiki/Pentium_FDIV_bug)), here's a historical gem: https://github.com/tongzx/nt5src/blob/master/Source/XPSP1/NT/base/crts/fpw32/tran/i386/adj_fdiv.asm (https://github.com/tongzx/nt5src/blob/master/Source/XPSP1/NT/base/crts/fpw32/tran/i386/adj_fdiv.asm)

The file contains references to the intended course of action that MS intended to take to resolve the problem. Microsoft software developer James "Jamie" Warren MacCalman was responsible for implementing Intel's workaround.

Biterider
Title: Re: Assembler in Windows OS
Post by: FORTRANS on March 18, 2024, 04:03:44 AM
Hi,

Quote from: Biterider on March 17, 2024, 01:15:03 AMFor those of you who remember the old fdiv pentium bug (Pentium_FDIV_bug (https://en.wikipedia.org/wiki/Pentium_FDIV_bug)), here's a historical gem:

  Well the assembly code that points to is rather beyond me.
But I did take a look because I own (owned?) one of those
Pentiums.

Regards,

Steve N.
Title: Re: Assembler in Windows OS
Post by: sudoku on April 07, 2024, 11:44:04 PM
Two of my favorite programs from Windows xp that I still use to this day are mspaint.exe and freecell.exe.
I occasionally use sol.exe as well.

Very simple programs that perform as expected without a lot of bells and whistles.   :azn:

So of course, I had to look at the sources for those. Thanks for posting this.
Title: Re: Assembler in Windows OS
Post by: sudoku on April 28, 2024, 01:49:15 AM
Quote from: Biterider on March 11, 2024, 04:43:24 AMI found a syntax that I had never seen before

  lea r10, 8[rax]
Did you know that this is equivalent to
  lea r10, [rax+8]
I just noticed this. We often have new members posting in rather odd syntax. I usually attributed it to them coming from another language (which might use different syntax).
It really goes against my grain to see sources like that. I am so set in the 'usual' Masm32/64 way of doing things.  :tongue:
Title: Re: Assembler in Windows OS
Post by: sinsi on April 28, 2024, 03:47:44 AM
                lea     eax,[ebx][esi]
8d0433          lea     eax,[ebx+esi]

                lea     eax,[ebx][esi*2]
8d0473          lea     eax,[ebx+esi*2]

                lea     eax,[ebx][2][esi*2][class]
8d84731150bb00  lea     eax,app!class+0x2 (00bb5011)[ebx+esi*2]

ML isn't smart enough to encode this, though it should be able to
    lea eax,[ebx][esi][esi]    ;lea eax,[ebx+esi*2]