C and assembly/symbols and debugging, question and a discussion

  • Be sure to checkout “Tips & Tricks”
    Dear Guest Visitor → Once you register and log-in please checkout the “Tips & Tricks” page for some very handy tips!

    /Steve.
  • BootAble – FreeDOS boot testing freeware

    To obtain direct, low-level access to a system's mass storage drives, SpinRite runs under a GRC-customized version of FreeDOS which has been modified to add compatibility with all file systems. In order to run SpinRite it must first be possible to boot FreeDOS.

    GRC's “BootAble” freeware allows anyone to easily create BIOS-bootable media in order to workout and confirm the details of getting a machine to boot FreeDOS through a BIOS. Once the means of doing that has been determined, the media created by SpinRite can be booted and run in the same way.

    The participants here, who have taken the time to share their knowledge and experience, their successes and some frustrations with booting their computers into FreeDOS, have created a valuable knowledgebase which will benefit everyone who follows.

    You may click on the image to the right to obtain your own copy of BootAble. Then use the knowledge and experience documented here to boot your computer(s) into FreeDOS. And please do not hesitate to ask questions – nowhere else can better answers be found.

    (You may permanently close this reminder with the 'X' in the upper right.)

coffeeprogrammer

Well-known member
Jul 19, 2021
195
20
Hello All,


I have been a junior level C# developer since 2016. I programmed in qbasic and a little bit of c plus plus in high school and I will be 37 this year so I am starting assembler a little late. I had a math teacher in high school who introduced me to assembly, I think it was a 68000 cpu and called a heath kit that’s all I remember. This last week, I’ve been using Windows System Programming by Johnson M. Hart to understand windows better. I’ve also found archive.org is good for “Win32” programming, most books being 9x/NT4 and Win2000, but they seem to run fine on my killer Win10 machine with Visual Studio 2015. While learning the “Win32” api I am sticking with C mostly as I am wanting to cover the API directly and QUICKLY. I keep making mess after mess. Those messes seem like a no in coding and certainly assembly coding. Thinking about that, tonight I took a break to see if I could get OllyDbg to pick up the C source and disassembly of a very poorly written Win32 C program. It is actually the first Win32 program I have ever successfully written after a few failed attempts in MASM32. Does anyone know if Visual Studio or Hutch’s MASM32 can or will, with 32 bit assembly, produce the PDB files necessary to debug x86 assembly rather than the C shown here? Part of my original barrier to learning assembly was that I didn’t understand how to get a debugger working well and didn’t have much time to figure it out. Based on this screen shot I might have more success with OllyDbg for debugging. I guess I could use MASM32 or ml.exe with the different Visual Studio versions. I could google debugging symbols from MASM32 or something. For clarity in understanding my story, I also figured out that I could use VS for debugging in masm style assembler. I did this by telling VS that I wanted to build MASM as a build target and by changing the include and library files to point to the \masm32\include and \masm32\lib folders directly rather than (or in addition to) the typical C and C++ libraries and headers in the VS project settings. Then just add a ASM file and code. Well I hope people find this as exciting as I do. I am wanting to give up on the C#/Angular life and switch to C, Win32 and very likely masm assembler. I find been impressed with what Security Now and Steve brings for years. Also, I learned some of the win32 api by using a API monitor, I reversed sysinternals desktop.exe program and if worked, I’ve got the same multiple desktop functionality in my poorly written application. I did most of that in a XP VM and it worked, the crap code in the screen shot is where started that project with my main OS, Win10. Feel free to reply, I would be happy to make friends.
 

Attachments

  • GoodDebuggerBadCode.png
    GoodDebuggerBadCode.png
    109.9 KB · Views: 416
Hello,

I have been trying to recode the Bounce1 program written in C to masm assembler for Petzold's Programming Windows, chapter 14. I have ran into a few problems and am asking for help. Where the ball will not appear, video explains more. Code attached. Thanks.

Chad Botting
coffeeprog

"
"

PS I am still waiting for my MASM32 forum activation email to ask for help there.
 

Attachments

  • Petzold5_c14Bounce1_masm32.zip
    4 KB · Views: 401
Last edited:
The needs of the many…



Yes, I am not surprised that Steve is too busy for the likes of me. In fact I’d say there might be better people to help me as Steve has decades of windows programming on me. I know a small handful of the Win32 API and not that well. I am sure I could learn more in C than assembly, but this is just a hobby today. I have not given up in the higher level world of C#. I would be only too happy to switch to assembler when the time is right if ever. With Windows 11 right around the corner sometimes assembler seems a little out of touch. Where I would like to have Steve’s concern is to see his code someday. I bet I am not the only one. I think that only makes sense however after I have pushed my self as much as I can without much expert help. He has provided the Small is Beautiful code which I have yet to examine closely. It includes some cool custom macros I seen in the windows.inc file and I wondered if he uses masm32 from Hutch or if he is just using masm. That is the ml.exe and link.exe included with visual studio and somehow creating the libraries needed from like the windows sdk or something. I remember he once said he was on VS6 with WinXP and VS2008 with Win7. I think that it is possible to use masm assembler without masm32 by Hutch, but Hutchs’ does include some good example code. So yes, this is a coding forum and I am not only asking for help, there is also stackoverflow and masm32 forums for that. If I get really good at it, it will generate interest and I can share my code. Most of what turns up in google for masm is very superficial, simple console code type things. I am just looking for everyday people for friends and ideas even if assembler is not your primary language. Coding forums should include code I think, and this is a Gibson Research coding forum. I see people in these forums have started threads on php, python and powershell. I have coded in Python, Java, C++, Visual Basic .NET, and mostly C#. Some of the memories from C++ from my Data Structures and Algorithms cource include linked list, balancing trees, an open shortest path first algorithm, and a text parser I made in C++. That was in 2015 I think and I don’t think I remember where the code is. Alot of Java algorithms too in school.

I would like to continue posting here and someday I would like to author a video tutorial or maybe a book on Windows Assembler, but I am still very much a novice. I have a few editions of the Windows Internals books and Windows via C/C++ as well as a Windows 10 System Programming by Pavel Yosifovich, a pdf I bought. If Steve wants to offer advice he is welcome, but that is likely overkill for me these days. Hopefully he writes a book in his spare time. :). All are welcome. Anyhow, I did get some of the problems solved on the bouncing ball program and learned along the way. Not 100% yet, but something. I will share when I get it 100% working even if the code still looks sub par.



PS I also have "The Assembly Programming Master Book", by Vlad Pirogov but I bought it before the price skyrocketed on amazon.



Thanks,

Chad Botting
 
Chad, I admire your energy, but you may be biting off a pretty large chunk for starters.

My experience with assembly is with small micros (8- and 16-bitters0 with simple memory maps (often no MMU) and I/O. Check out embedded device projects on hackaday.io or other similar forums, for ideas. The idea is to get an Atmel 328P processor without the Arduino environment, but using the Atmel assembler, put together a program or two that blinks LEDs attached to the I/O ports, or maybe sends Morse code from an attached dot/dash paddle, etc. Of course, you can start with the Arduino environment if you like, which uses at least 2K of the 32K memory on the 328P. Adding in your code and various libraries from the Arduino environment, you'll be surprised what you can do with 32K of program space, using a hybrid C/C++ syntax, but you can 'escape' and code directly in assembly, if you wish.

For an example, check out the QCX+ and QCX-mini on the qrplabs.com site. They both use a 328P without the Arduino environment, to squeeze a LOT of functionality into that 32K memory footprint. Hans has started to graduate towards bigger processors, like the STM32 for his balloon projects, and his QSX, which has been on the back-burner for a while, but promises to be an SDR-based all-band 10 watt HF ham transceiver with cabinet for $150. You should be aware that Hans does not open-source his projects (except the balloon projects, which are running tiny BASIC interpreters), since they form his and his family's living wages. On the other hand, he sells his stuff for what I consider way too cheap, but I guess you can make it up in volume? He's sold over 15,000 of his QCX-family of 5W CW-only transceiver kits at about $50 each.

There's lots of little projects in the ham radio community. Check out books like Arduino for Ham Radio and the like.

73,

-- Dave, N8SBE
 
One thing that I have noticed is that I lack direction. Recently I have bought many books on Windows Programming and Windows Internals. I also recently purchased the “The Linux Programming Interface” and I bought the Art of Electronics 3rd edition about a year ago. I know almost nothing about electronic or even digital electronics. I watched some clips of Ben Eater on youtube and I seen he built a computer on a breadboard with a 6502 microprocessor. I was going to try and memories the appearance, characteristics, and units that common electrical compounds use. I know that resisters are ohms and I know about ohms law and I think I remember current laws, but it was been many years since the physics class where I learned that. I did well in that course and I can relearn it. I have no idea how one really designs circuits with given components. I went looking for software for designing and maybe simulate circuits. So far I have found Circuit Maker and LibrePCB, neither seemed to actually simulate circuits only design. I know that computer microprocessors like in computers and tablets (x86 and ARM things) are built on adder circuits with break down to AND and other logic gates. But I don’t really know what makes makes a computer. I remember Steve did a series on lets build a computer from first principles years ago and he may have recommended a book. I should re-listen to that. I remember on a non-Secuity now twit show he recommended the TI lunch pad and software package called Pep/9 that simulates and a computer. I did install that quite some time ago on a laptop.

To be honest I have a rough few years and this dive into x86 assembly has help take my mind off my problems. I am currently under psychiatry care and its good to keep my mind active. I have many diagnosis including schizoaffective disorder and autism. I am currently not working and live alone, so it is important that I focus on project that can be fun. Money is not a major issue, so I will definitely try and move closer to electrical engineering side of things rather than just programming. In the past when I have been working others have complemented me on my technical competence and coding skill, so perhaps someday I start coding again professionally. Tomorrow I will write down the more technical aspects of your post and try to figure out some of this. Thank you. Always willing to chat/talk.



Chad
 
Chad,

I've suffered from lack of focus (some call it ADD) for many years. I found that just buying Arduino and Raspberry PI boards don't really do anything, they just sit on the shelf, reminding me that I should be doing something with them. It's fun to just use them as a learning vehicle, but at some point, I really need them to DO something, and that means dedicating one to a particular purpose. So what if you 'use it up'? They are cheap enough that you can get another for another project.

So, a project! (or two). That's the ticket! Find a project in one of the many books on Arduino projects, and put something together that does something you'd like to have on your desk/bench, doing something useful.

Or, purchase a kit that's based on a microcontroller, and build the kit. At that point, you can just let it do whatever it was originally designed to do, or maybe you'd like to tweak it for some new feature, or to just change its behavior to closer match your expectations.

Getting your ham radio license might turn out to be a good thing, as then you can work on station accessories (think - GPS 24hr clock, Morse code keyboard, WSPR/FT8 digital mode setup, remote antenna switch, etc.), or even building your own radios from scratch or from kits. Or barring that, try building a PDP-11/70 kit from https://obsolescence.wixsite.com/obsolescence/pidp-11 --- they also have a PDP-8 kit, both of which you'll see on the set of the Security Now podcast.

I also have an Altair-Duino kit from https://adwaterandstir.com/altair/ -- which I think is also now on the Security Now podcast.

I guess great minds think alike?

73,

-- Dave, N8SBE
 
Chad,

I've suffered from lack of focus (some call it ADD) for many years. I found that just buying Arduino and Raspberry PI boards don't really do anything, they just sit on the shelf, reminding me that I should be doing something with them. It's fun to just use them as a learning vehicle, but at some point, I really need them to DO something, and that means dedicating one to a particular purpose. So what if you 'use it up'? They are cheap enough that you can get another for another project.

So, a project! (or two). That's the ticket! Find a project in one of the many books on Arduino projects, and put something together that does something you'd like to have on your desk/bench, doing something useful.

Or, purchase a kit that's based on a microcontroller, and build the kit. At that point, you can just let it do whatever it was originally designed to do, or maybe you'd like to tweak it for some new feature, or to just change its behavior to closer match your expectations.

Getting your ham radio license might turn out to be a good thing, as then you can work on station accessories (think - GPS 24hr clock, Morse code keyboard, WSPR/FT8 digital mode setup, remote antenna switch, etc.), or even building your own radios from scratch or from kits. Or barring that, try building a PDP-11/70 kit from https://obsolescence.wixsite.com/obsolescence/pidp-11 --- they also have a PDP-8 kit, both of which you'll see on the set of the Security Now podcast.

I also have an Altair-Duino kit from https://adwaterandstir.com/altair/ -- which I think is also now on the Security Now podcast.

I guess great minds think alike?

73,

-- Dave, N8SBE
You on commission? HIHI

73 de N1MXV

P.S. I have a Raspberry Pi with some old drives hanging off it, serving as a NAS.
 
I’ve been thinking that I want to get back to work sometime in the next few months. I gave assembler a break after I finished the bounce1 program. I was a C# developer and had to go to a work site everyday. I live in a very rural part of Maine and I almost never work with the kind of clarity and directness that people like Steve have. I was thinking I don’t want to roll back in to a C# position, both positions I have had since 2016 were very web oriented with Microsoft technologies, ASP.NET, MVC, WebAPI and such, sometimes I had to used Visual Basic .NET which was just awful. Today I wrote a small amount of JavaFX code, thinking maybe my next job would be with non-Microsoft languages. I thought about doing pen testing as well. I want to stay in Maine and do all work over the Internet. Not go to a work site, work from home. To that end I have wonder if I should start my own business writing code. The problem in the past as been that employers want things so rushed and productivity is a popular word. It turns me in a coding marathon runner. It’s not really that hard to code “marathon like” in C#, but I often get the sense that I have had some peers where there is little or no understanding or is suppose to be done or what the software is for. I really feel quite strongly that in my experience software development strategies have been mismanaged by the powers that be. No one ever says the word quality, just productivity. I can honestly say that I would no run most of the code that I felt compelled to write or work on with when I was working professionally. That is what brings me to the idea that I want to do things on my own. There is no shortage of jobs listed for remote work on indeed.com. When I wrote code in assembler I was really looking at C code and saying to my self, how would this work in assembly and then writing that. It was harder than writing C#, but it was not impossibly hard. Also once I had found online forums at masm32 it become easier. The kind of programming that Steve does is much more thoughtful that what I have been required to do. I have the SQRL Cryptography pdf open on my computer and I reading some of the Diffie Hellman Key Agreement things that SQRL is using for identity purposes and I left thinking that Steve is different breed that other programmers than I have meet. Many, not all, just make piles of bad code, which is not fun if you are required to work on teams or you have to go back and fix, in some cases, ridiculous bugs. When I of think of C# or Java I think, just do the work. When I think of assembler I feel a sigh and think, I bet there will be many unknowns for me.

When thinking about writing good code and succinct software that directly solve a real problem, SQRL comes to mind. It seems to me that only a developer that is well worth their salt could dream up a concept like SQRL. Someone that understands both the problem and the technology used to solve it. The developer in me does not know exactly how it works, but the user in me is willing to give it a try. (I have many accounts that it would not be the end of the world even if a bad actor did gain access, think streaming video, e-commerce, or free email accounts. I am not sure why organizations don’t allow a transition from older user name and password type accounts to a SQRL system. I have not watched all of the videos Steve made, but I do know that you can keep things recoverable by printing out a few pieces of paper. That’s not asking much). I think the kind of software GRC puts out is the kind of software that real users want and real programmers want to develop. It does something and you can use it. As a living is concerned I’ve worked on project, team projects, where deep down I am thinking, this is not usable and because of poor engineering it is hard to get under the hood and fix problems. I don’t want to go back to bad code, productivity focused work days. I’ve checked out code at some organizations and thought, really? REALLY!?!?!

There is something wrong in the industry, just look at Windows, it comes with Xbox, Soda, and other dumb gimmicky things that don’t do anything, its just noise. Compare that with software from GRC or another place like terabyte unlimited, it always does something, sometimes more focused that others, but is always have a definable purpose.

Finally, I’ve liked the conversion about building things, but I feel like I need to figure out how to make a good living. Thanks



Chad
 
Chad,

So, you want to work on things were folks care more about quality than productivity? Try some space (as in outer space) work. Folks that work on satellites, or better yet, deep space or planetary probes, are mainly interested in having something work across millions of miles of space, and not fail, no matter what.

Check out your local university and see if they have a deep space exploration program, and need folks that can write hardware-oriented code that cannot be re-booted or re-flashed and must run 24/7/365 over a several-month or several-year period.

Maybe another related area is things like machine vision for electronics fabrication, or automated testing machines. In a production environment, uptime is paramount. Many years ago, I worked on a machine vision library (over 400 functions) for a 10-bonds/second wire-bonding machine that did the wire-bonding for the Intel Pentium processor on their assembly line. I worked directly with our hardware engineers, who designed the 10K gate arrays that did the heavy lifting, while I wrote the two-clock loops for an Intel i960 C-core superscalar processor running at the then-screaming clock rate of 25 MHz, to drive the 128 pixel-wide SIMD gate array. I could get a half-gigapixel of binary morphology per second for vision primitives (plug, erode, etc).

Working hand-in-hand with a hardware developer, helping them understand how to design the interface to make both your and their job easier was a blast, and just about the most fun I ever had on the job.

73,

-- Dave, N8SBE
 
Quick Note about Micheal Abrash books


I started watching the last two Security Now episodes and when I googled what Periscope Debugger is, it looked like a piece of hardware that intercepts the CPU? Does it plug into a CPU Socket? Maybe I am misunderstanding. When I first thought that might be that kind of hardware I instantly smiled. I don’t think that kind of thing is still made and it’s usefulness might be more limited. Not sure, but interesting. I guess if that is correct, it is to get the state of the CPU at any given time. I think a person might be able to do something simulare in a modern sense that with a VM or emulator. Not sure. I’ve scene youtube videos of Windows Kernel Debugging with vmware and WinDBG. He must need real hardware for SpinRite.

Anyway, as for what he said about Micheal Abrash’s books I thought I remembered finding the below links when browsing the reddit’s programming channel a few years ago as I recall. I googled this morning and found it again.