Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Dark GDK / Disassembly

Author
Message
Mahoney
16
Years of Service
User Offline
Joined: 14th Apr 2008
Location: The Interwebs
Posted: 4th Jul 2008 10:24 Edited at: 4th Jul 2008 10:25
I've looked at the disassembly to some very basic console apps in VC++ and compared the standard disassembly to that of the same program with the optimizations turned on. I must say, they really know what they're doing. Example:

This code



Has the following dissasembly without optimizations:



The same code has the following disassembly with optimizations enabled:



See what I mean?
Benjamin
21
Years of Service
User Offline
Joined: 24th Nov 2002
Location: France
Posted: 4th Jul 2008 11:30
Yeah, there are some really serious optimizations going on.

Mahoney
16
Years of Service
User Offline
Joined: 14th Apr 2008
Location: The Interwebs
Posted: 4th Jul 2008 11:39
It's nice to see that it's really doing some good under the hood. Hey, that rhymed!
sydbod
16
Years of Service
User Offline
Joined: 14th Jun 2008
Location: Just look at the picture
Posted: 4th Jul 2008 12:15 Edited at: 4th Jul 2008 12:27
I was about to say........ where is the rest of the code for the top part ... it is missing until I noticed:

Quote: "
00A91006 push 3
00A91008 push 3
"


Your sample demonstrates beautifully that provided full optimization is selected there is no real penalty in writing code for good readability rather than speed.

EDIT: how did you create the disassembly
Mahoney
16
Years of Service
User Offline
Joined: 14th Apr 2008
Location: The Interwebs
Posted: 4th Jul 2008 18:28
Debug->Step Into

Then

View->Other Windows->Disassembly
Mahoney
16
Years of Service
User Offline
Joined: 14th Apr 2008
Location: The Interwebs
Posted: 7th Jul 2008 08:02
I just found out how to use inline ASM. Anyone have a good tutorial link on ASM?
Mahoney
16
Years of Service
User Offline
Joined: 14th Apr 2008
Location: The Interwebs
Posted: 7th Jul 2008 08:03
Quote: "Your sample demonstrates beautifully that provided full optimization is selected there is no real penalty in writing code for good readability rather than speed."


Apparently, though, this rule doesn't apply in assembly.
jason p sage
17
Years of Service
User Offline
Joined: 10th Jun 2007
Location: Ellington, CT USA
Posted: 7th Jul 2008 12:53
Well - You should get NASM and see if you can't get the Programmer's reference manual for Intel P3 or P4. That's a start - but then couple this with some how to tutorials - they are out there I'm sure. Once you get to a certain point - you'll be using the intel programmer's reference more than anything - and after awhile - you start writing assembly with as much "FAMILiARITY" as you do writing C++ or C#.

Its a bit more cryptic - but you start to get it. And key with assembly - is writing a good lib of functions and subroutines - and there is a difference between a function and a subroutine - and in asembly you need both - and the goto statement (there are many flavors of it) is your friend

Mahoney
16
Years of Service
User Offline
Joined: 14th Apr 2008
Location: The Interwebs
Posted: 7th Jul 2008 17:44
I found a PDF book on learning NASM. From what I can tell, it's the purest assembly style.

Also, would it be good to move to MASM once I learn this well enough? It seems to have some high-level functions with the assembly for advanced assembly programs.
Benjamin
21
Years of Service
User Offline
Joined: 24th Nov 2002
Location: France
Posted: 7th Jul 2008 19:58
I'd start with MASM personally, purely because if you use VC++ you can experiment with inline assembly without having to write whole programs with it. You don't even need a separate assembler for it.

Mahoney
16
Years of Service
User Offline
Joined: 14th Apr 2008
Location: The Interwebs
Posted: 7th Jul 2008 21:32
I've messed with very minor inline assembly (
). But, all the guides seem to have things specific to either NASM or MASM, so I wasn't sure what to do. :/
Benjamin
21
Years of Service
User Offline
Joined: 24th Nov 2002
Location: France
Posted: 7th Jul 2008 23:36 Edited at: 7th Jul 2008 23:37
I think you'll find that the only thing specific is the syntax, which shouldn't be much of a problem as there isn't an awful lot of that to learn. This is a great source to learn from (if you look online you'll find that there are multiple versions of The Art Of Assembly Language Programming, I'd suggest finding the Windows one). Not only does it cover the language well, but it also explains a lot of useful concepts such as how memory access works and such.

Mahoney
16
Years of Service
User Offline
Joined: 14th Apr 2008
Location: The Interwebs
Posted: 8th Jul 2008 00:10
Thanks!
jason p sage
17
Years of Service
User Offline
Joined: 10th Jun 2007
Location: Ellington, CT USA
Posted: 8th Jul 2008 00:49
Agreed - MASM is the way to GO - however I remember having some issues getting pure object code blocks from it without coding what used to be known as a com file (exe sorta -limited to 64k).

This might not be the case - but the reason I mixed and matched was because witgh NASM it wasn't "only for windows" OS so it was easy to get relocatable code that I could use in windows, linux, or the OS I was making.

Back in the day - the gamers would fire up dos, flip on a flat model protected 32 mode - and make the games like that - utilizing the entire machines resources - ahh - the good old days when a million useless "required" services didn't run (unnecessarily).

But I too like MASM - as it made the object oriented "machine code" much easier - in all fairness - I haven't used either MASM or NASM in years. I thought micorosft stopped selling their MASM product though - the full product had TONS of resources in it...

Nasm - could be much better now for all I know.

MASM for inlining syntax - yeah - for vs c++ stuff - Benjamin is probably right in that the current inline stuff works on the same semantics as the MASM I know.

--Jason

Mahoney
16
Years of Service
User Offline
Joined: 14th Apr 2008
Location: The Interwebs
Posted: 8th Jul 2008 01:05
MASM was stopped as purchased software and made free. It's been updated with every VC++ release, and comes with it.
jason p sage
17
Years of Service
User Offline
Joined: 10th Jun 2007
Location: Ellington, CT USA
Posted: 8th Jul 2008 05:53
Quote: "MASM was stopped as purchased software and made free"


I'm a bit skeptical - at least in some ways about this statement - because I own a MASM license - though lost my "stuff" somewhere along the line - to my chagrin - along the way - I think in a move - but I had a 4 inches of reference materials, multiple exe, bin, dll, linker tools, an IDE, preprocessing tools - it was more than just the compiler/linker - and that's what made it special. All compilers (almost) like C, C++, turbo Pascal, freepascal - even gnu stuff comes with some sort of assembler/linker package - but the reference materials were as much part of the "system" as were the software bits.

Benjamin said for assembly "there's not much to learn" but I have to disaggree... there is like many versions of each command based on the addressing and "variation" used, each with their own opcode - and each opcode is gereated (meaning it knows which one to use) based on the addressing and registers, and stuff used with it - and each addressing mode has a different way that things like offsets, memaddresses, and pointers are calculated. Then there are commands that only work on intel data structures - that are different depending on the cpu architecture - with behaviors that may or may not vary depending on said architecture, and there are ways opcodes work in 16bit legacy, that work different in 286, 386, 468, 586, and beyond - granted you can code to p4 and be ok - but there is caching, prefetching things to consider ofr really fast code - how you set up branching can effect efficiency, how threading (REALLY) works in the CPU (not important admittedly if not writing an OS...making threaded software is so much easier than then setting up either realtime multiplexed or threaded process handling ...)

There is writing little assembly "snippets" and there is actual assembly language programming - this is mere semantics to describe what I'm thinking about - but nonetheless - there is assembly dabbling and assembly "mad man" and I think all is good and beneficial - and some parts are simple - but many are not. People can get sloppy writing assembly too. One shoudl at least have some basic concepts down like how all these opcodes are actully converted to a "intel - almost RISC" processing system under the hood - and what opcode combinations are treated in such a way they run faster than alternate ways of expressing the same "abstract".

Assembly language is at the lowest level we can communicate with the hard - its more work than any language - and harder to grasp in a way that one can make "complete software packages" with. Many say - NEVER! You shouldn't! Its to slow from a development time perspective - but - frankly - I'm all for the just use assembly where you need speed stuff - but I'm also convinced that a serious good programmer can build a power suite of code - that can interface with existing shared libs etc - and do anything you can with c, c++ - and I guarentee the performance will be mind boggling - especially when every jsr or call isn't to a dll -= where your assembly does alot of work - you'd be amazed.

Benjamin
21
Years of Service
User Offline
Joined: 24th Nov 2002
Location: France
Posted: 8th Jul 2008 05:57
Quote: "Benjamin said for assembly "there's not much to learn" but I have to disaggree... there is like many versions of each command based on the addressing and "variation" used, each with their own opcode"

I was only referring to the syntax. In regards to variations on instruction operands and addressing modes, I agree there is quite a bit to learn. I think when you write a disassembler it numbs you a bit from it.

Mahoney
16
Years of Service
User Offline
Joined: 14th Apr 2008
Location: The Interwebs
Posted: 8th Jul 2008 06:10
Quote: "I'm a bit skeptical - at least in some ways about this statement"


You may have meant this differently, but, if you really aren't sure in that statement, look here:

http://en.wikipedia.org/wiki/MASM

Thanks for the direction. So, I should start with some small test inline with C++, then move to full-on MASM?
jason p sage
17
Years of Service
User Offline
Joined: 10th Jun 2007
Location: Ellington, CT USA
Posted: 8th Jul 2008 14:44
@Benjamin - That I 100% agree with - now I know what you meant. Additionally - Disassemblers are a chore.

One thing you can do to make reverse engineering assembly difficult - is to occasionally - skip a byte, and make a bne or something skip appropriately - its funny how that screws things up and makes more work for the reverse engineer... The other trick - that windows doesn't allow - I don't know about linux and mac - but self modifying code allows some really good copyright protection techniques - that unfortunately - virus writers would likely abuse to hide signature bit patterns...but I digress.


Mahoney - Yes - you should try writing small assembly routines like you have to start - and maybe see if intel or amd has architecture programming reference manuals - so you can learn a new command (family) once you get a couple down.

Pay particular attention to how the stack works. In assembly language - or in machine code - these things (to me) actually make more sense then how they are often described in c++ or pascal programming manuals. Once you get it in machine code - I think you'll start to be enlightened on how programming languages work internally, and how dlls, and functions, and subroutines work under the hood.

Learn the difference between relocatable code and not - and what makes the difference- and try to recognize the benefits of each.

Typically a dll is made of one or more relocatable code blocks... and try to get a understanding of oop if you haven't already - and try to visualize how this might be accomplished in assembly.

It's not a necessary endeavor - but for making complex assembly language libraries - you might find the oop approach makes writing threadsafe and complex projects easier.

You're on the right track - and I'm explaining or directing you to things that do not happen overnight - just so you have these things in mind as you progress.

--Jason

Benjamin
21
Years of Service
User Offline
Joined: 24th Nov 2002
Location: France
Posted: 8th Jul 2008 15:58
Quote: "One thing you can do to make reverse engineering assembly difficult - is to occasionally - skip a byte, and make a bne or something skip appropriately - its funny how that screws things up and makes more work for the reverse engineer..."

Don't talk to me about things screwing up , I was disassembling the MS-DOS stub of an EXE the other night getting really confused with the nonsense instructions that were being used. This is when I realised that of course my disassembler was using 32-bit mode.

As for writing a disassembler being a chore, I guess it could be if you did it more than once. This stuff really fascinates me though.

Mahoney
16
Years of Service
User Offline
Joined: 14th Apr 2008
Location: The Interwebs
Posted: 8th Jul 2008 20:23
Will this do, with all it's links?

http://en.wikipedia.org/wiki/X86_assembly_language
Mahoney
16
Years of Service
User Offline
Joined: 14th Apr 2008
Location: The Interwebs
Posted: 9th Jul 2008 02:08
That link has plenty of links to other articles with details. But, I just looked at the instruction set page. Not many details at all. When you said Intel reference manual, did you mean online? I can't afford a book.
jason p sage
17
Years of Service
User Offline
Joined: 10th Jun 2007
Location: Ellington, CT USA
Posted: 9th Jul 2008 02:34
Well - in the good old days - when Intel was trying to do as much "get developers to adopt our chip" marketing as they could - you used to be able to call them - and ask for a book - on anything they sold - and it would arrive a week later... NO CHARGE.

Now - I imagine you would have to download a PDF file or some such non-sense - the books were awesome. I lost a lot of this kind of stuff in a move - MASM my intel books, etc... (stinks)

I used to even be on this special mailing list where you tell intel how old you are, your patriotism, how many kids you have or not, and why you want it "form" .. LOL... then oh yeah - non-compete, non-disclosure forms - and THEN they mailed you a little book called appendix "H"... "The Hidden Stuff LOL... but it had all the SERIOUSLY neat stuff only Microsoft and some other hardcore OS writers knew about.. and tricks too... like set this flag while doing that command and "this" will happen instead...etc.

So - SCOUR their web site for programming reference materials is all I can say....

Mahoney
16
Years of Service
User Offline
Joined: 14th Apr 2008
Location: The Interwebs
Posted: 9th Jul 2008 02:39
You think they still send out books for shipping only? Probably over optimistic, but you never know.
Benjamin
21
Years of Service
User Offline
Joined: 24th Nov 2002
Location: France
Posted: 9th Jul 2008 02:42
http://www.intel.com/products/processor/manuals/

What you want are:

Intel® 64 and IA-32 Architectures Software Developer's Manual
Volume 2A: Instruction Set Reference, A-M

Intel® 64 and IA-32 Architectures Software Developer's Manual
Volume 2B: Instruction Set Reference, N-Z


Mahoney
16
Years of Service
User Offline
Joined: 14th Apr 2008
Location: The Interwebs
Posted: 9th Jul 2008 02:44
Thank you, kind sir.

Also, this:

http://www.intel.com/design/literature.htm

Doesn't say anything about a fee.
Zuka
16
Years of Service
User Offline
Joined: 21st Apr 2008
Location: They locked me in the insane asylum.
Posted: 9th Jul 2008 02:52
Hey, Mahoney, how does that guy not fall off the ceiling?

Mahoney
16
Years of Service
User Offline
Joined: 14th Apr 2008
Location: The Interwebs
Posted: 9th Jul 2008 02:53
Quote: "Hey, Mahoney, how does that guy not fall off the ceiling?"


Holy crap, you're right. O.O
Mahoney
16
Years of Service
User Offline
Joined: 14th Apr 2008
Location: The Interwebs
Posted: 9th Jul 2008 02:54
Quote: "Also, this:

http://www.intel.com/design/literature.htm

Doesn't say anything about a fee. "


Anybody know more about this? Or should I just call and ask?
Benjamin
21
Years of Service
User Offline
Joined: 24th Nov 2002
Location: France
Posted: 9th Jul 2008 03:08
Personally I just downloaded the PDFs.

Mahoney
16
Years of Service
User Offline
Joined: 14th Apr 2008
Location: The Interwebs
Posted: 9th Jul 2008 03:10 Edited at: 9th Jul 2008 03:10
Like Jason said, having the book is so much nicer ( for me, at least ). I don't want to call and it cost money/requires being in a business, and piss the dude off for being stupid. Just asking if you knew.
jason p sage
17
Years of Service
User Offline
Joined: 10th Jun 2007
Location: Ellington, CT USA
Posted: 9th Jul 2008 03:26
LOL -My Uncle says you need to learn to wipe ... you can probably figure out the rest LOL... Call the guy - what's he gonna do ... say no? That's the worst that can happen!?!?! Go for it!

Find out!

Mahoney
16
Years of Service
User Offline
Joined: 14th Apr 2008
Location: The Interwebs
Posted: 9th Jul 2008 03:29
I called. They're closed until tomorrow at 7 in the morning. v.v

But, it said to leave a message if you want, so I left a message saying that I was curious about pricing, since it's not mentioned on the website, and left my number. I'll update you all in the morning.
Mahoney
16
Years of Service
User Offline
Joined: 14th Apr 2008
Location: The Interwebs
Posted: 9th Jul 2008 03:30
Quote: "My Uncle says you need to learn to wipe"


Wait, wat? XD
Zuka
16
Years of Service
User Offline
Joined: 21st Apr 2008
Location: They locked me in the insane asylum.
Posted: 9th Jul 2008 03:34
Neh, who cares if some crazy dude working for Intel thinks you're stupid?

Mahoney
16
Years of Service
User Offline
Joined: 14th Apr 2008
Location: The Interwebs
Posted: 9th Jul 2008 03:35
I know.
Zuka
16
Years of Service
User Offline
Joined: 21st Apr 2008
Location: They locked me in the insane asylum.
Posted: 9th Jul 2008 03:36 Edited at: 9th Jul 2008 03:37
Oh, just read that.

Mahoney, do you have MSN/Yahoo/Xfire?

jason p sage
17
Years of Service
User Offline
Joined: 10th Jun 2007
Location: Ellington, CT USA
Posted: 9th Jul 2008 04:48
My uncle says you need to learn to wipe your own rump!

Mahoney
16
Years of Service
User Offline
Joined: 14th Apr 2008
Location: The Interwebs
Posted: 9th Jul 2008 04:57
o.O
Mahoney
16
Years of Service
User Offline
Joined: 14th Apr 2008
Location: The Interwebs
Posted: 9th Jul 2008 04:58
Actually, I was asking first because it would be a bit before I could call.
Mahoney
16
Years of Service
User Offline
Joined: 14th Apr 2008
Location: The Interwebs
Posted: 9th Jul 2008 05:22
Found a good reference. MSDN's resource.

http://msdn.microsoft.com/en-us/library/t13a3526(VS.71).aspx

Thank you, Jason, for all the advice and help. I appreciate it.
Mahoney
16
Years of Service
User Offline
Joined: 14th Apr 2008
Location: The Interwebs
Posted: 9th Jul 2008 05:25
Quote: "Mahoney, do you have MSN/Yahoo/Xfire?"


Oh, I just read that. XD

I usually just use GMail IM. But, I can start using my Windows Live account.
Mahoney
16
Years of Service
User Offline
Joined: 14th Apr 2008
Location: The Interwebs
Posted: 9th Jul 2008 05:27
Alright. Added my Windows Live account to Pidgin. It's under mmahoney62292@gmail.com
Mahoney
16
Years of Service
User Offline
Joined: 14th Apr 2008
Location: The Interwebs
Posted: 9th Jul 2008 19:39
Apparently, there's no such thing as an x86 assembly tutorial. I just grasped that fact last night. That brought me to a startling realization: Jason, you wrote an OS in assembly with basically nothing except a book describing all the commands of x86 assembly.

Congratulations. You are now my hero.
Lilith
16
Years of Service
User Offline
Joined: 12th Feb 2008
Location: Dallas, TX
Posted: 9th Jul 2008 20:45
Quote: "Hey, Mahoney, how does that guy not fall off the ceiling?"


You have to press ESCape before he leaves the bottom of the box.

Lilith, Night Butterfly
I'm not a programmer but I play one in the office
Benjamin
21
Years of Service
User Offline
Joined: 24th Nov 2002
Location: France
Posted: 9th Jul 2008 21:19
Quote: "Apparently, there's no such thing as an x86 assembly tutorial."

I've seen a fair few around, particularly this one which I linked to previously.

Mahoney
16
Years of Service
User Offline
Joined: 14th Apr 2008
Location: The Interwebs
Posted: 9th Jul 2008 21:22
Wow. That's the first decent one I've seen. Thanks. I wish there were more, but, the only others are fairly unfinished.
Mahoney
16
Years of Service
User Offline
Joined: 14th Apr 2008
Location: The Interwebs
Posted: 10th Jul 2008 18:06
Jason, thanks for recommending finding those reference manuals. They just got back to me and I requested all of them free of charge. Thanks!
Mahoney
16
Years of Service
User Offline
Joined: 14th Apr 2008
Location: The Interwebs
Posted: 13th Jul 2008 04:03
Thank you so very much, Benjamin. The tutorial you sent me a link to is proving wonderful ( though difficult, at first ). I'm going over the basics of it to prepare to look over the Intel books. I greatly appreciate your help.
Benjamin
21
Years of Service
User Offline
Joined: 24th Nov 2002
Location: France
Posted: 13th Jul 2008 04:36
You're welcome. If there's anything you need explaining, just ask.

Login to post a reply

Server time is: 2024-09-30 05:36:14
Your offset time is: 2024-09-30 05:36:14