Page 2 of 3 FirstFirst 123 LastLast
Results 16 to 30 of 35

Thread: Code: Learning Disassembly Assembly

  1. #16
    Fuel Injected! jim_in_dorris's Avatar
    Join Date
    Dec 2011
    Posts
    803
    1Project2Many, What do you do that you work with special needs kids? My daughter has been a special Olympics coach for years and loves it, I admire people who can give so much of themselves to those who need it the most. I use the MGTEK asm11 assembler, it works great for me. As for forcing address modes, I want to spend a little time putting together a little primer on why and how I do that. I am sure that you understand it quite well, but for everyone else, it may shed some light on the subject. I intend to work on it and have it ready for the weekend.

    Mark, I really like the $0D mask myself, and have probably 2-300 hours invested in formatting my copy, looking at what the code is doing, and in general, just trying to understand it. If it was easier to get into, and cheaper, I would be jumping all over the 411 stuff you guys are playing with. If I ever get to start my 58 Jag street rod project, I think that the 411 will be in the mix.
    Square body stepsides forever!!!

  2. #17
    RIP EagleMark's Avatar
    Join Date
    Feb 2011
    Location
    North Idaho
    Age
    64
    Posts
    10,477
    Quote Originally Posted by jim_in_dorris View Post
    Mark, I really like the $0D mask myself, and have probably 2-300 hours invested in formatting my copy...
    I thought I was a nut job for admitting all the hours I put into this stuff, but actually I enjoy it! More importantly because in the end I can make vehicles run better. It's always been my first goal and still an end goal.

    Looking forward to continuing this, strange that since this thread started I've actually had to much work for a change.

    1990 Chevy Suburban 5.7L Auto ECM 1227747 $42!
    1998 Chevy Silverado 5.7L Vortec 0411 Swap to RoadRunner!
    -= =-

  3. #18
    Super Moderator Six_Shooter's Avatar
    Join Date
    Feb 2011
    Posts
    2,968
    I'm going to have to read back through this again, see if it helps.

    I started reading the Pink Book a number of years ago, got about 10 or 12 pages in, set it down (closed the file) with intentions of getting back to it and never did. :/

    I'm currently taking C++ right now, and C last semester, it still hasn't clicked yet. I understand bits and pieces, but not as a whole, and not as well as I need to.

    This summer will be dedicated to learning the intricate details that I know I won't get before the end of the semester, without some sort of miracle.

    Once school is done, I plan to get back to learning to disassemble, and how the machine code works. Coincidentally, my C++ programming instructor was talking about machine language this morning, and how we might encounter it in our future careers.
    The man who says something is impossible, is usually interrupted by the man doing it.

  4. #19
    Fuel Injected! jim_in_dorris's Avatar
    Join Date
    Dec 2011
    Posts
    803
    Six_Shooter,

    Back when I was coding in C, we would frequently output the C code as assembly to optimize the code. Fortunately, I was really familiar with assembly so it was no problem. C (and C++) are a little tricky to get until you spend a lot of time writing code, then it clicks. I think that one of the problems with teaching people how to use a particular language is that you don't have a real application that you are coding (this is not always true, but mostly) If you really want to learn to code, write actual programs like a browser, or text editor. Good Luck in your programming class.
    Square body stepsides forever!!!

  5. #20
    Administrator
    Join Date
    May 2011
    Location
    Lakes Region, NH
    Age
    54
    Posts
    3,862
    I'm currently taking C++ right now, and C last semester, it still hasn't clicked yet. I understand bits and pieces, but not as a whole, and not as well as I need to.
    There usually isn't a lightbulb moment when learning coding. Don't expect that all of a sudden the big picture is crystal clear because it's not like that. Programming languages are nothing more than a set of rules with the actual instructions and commands being tools used to accomplish a job. The goal is to make stuff happen using those rules. It takes time to learn them, and more time to get good at using them. You can read about a wrench all day long but you won't develop that instinctive knowledge of what you and the wrench can do together until you pick it up and try to do something. And in the same line of thought, it's highly unlikely that you'll become Programming Buddha without spending crazy amounts of time writing code.

    If you really want to learn to code, write actual programs like a browser, or text editor.
    Exactly. I've never learned a language only by following little lessons out of a book. I always learn the most by deciding I want to solve a problem then setting out to write code to solve it. Write a million little programs. Find ten different ways to solve the same problem. Get bored and try to challenge yourself to write the most complex code to add two numbers. Take a section of GM assembly code and try to duplicate the functions exactly in C (try duplicating an eight bit multiply operation on a 16 bit value with proper rounding, keeping all the values in hex!). Grab code snippets off the internet that seem interesting and try incorporating them into a program... then troubleshoot them when they don't work.

    And don't hesitate to ask questions here. ;)
    Last edited by 1project2many; 02-13-2013 at 03:35 PM.

  6. #21
    RIP EagleMark's Avatar
    Join Date
    Feb 2011
    Location
    North Idaho
    Age
    64
    Posts
    10,477
    Moved my 10 degree issues to my 10 degree disaster thread to clean up this code thread...

    1990 Chevy Suburban 5.7L Auto ECM 1227747 $42!
    1998 Chevy Silverado 5.7L Vortec 0411 Swap to RoadRunner!
    -= =-

  7. #22
    Fuel Injected!
    Join Date
    Feb 2013
    Location
    Oklahoma
    Age
    44
    Posts
    445
    Subscribed,great descriptions.
    I'll post when I start understanding it.

    Quote Originally Posted by EagleMark View Post
    Making cars run better is my intrest, I'm more intrested in data coming out of car, back to this, I need to know why and how? I've tempted this a few times before and backed away because of the learning curve and time. But it keeps coming back as software just does not have all paremeters and sometimes I need to know how they work.
    Describes me to a tee,though you are furthur along than I am.
    I have written a hello world program though :)

    Quote Originally Posted by 1project2many View Post
    We've had a lot of newbies here in the shop and because I work for a company that handles special needs children I frequently have a "work study" kid here as well.
    off-topic,pm if you like.
    Just curious what type of special needs if I can ask,I've got two here at home :)

  8. #23
    Fuel Injected!
    Join Date
    May 2011
    Location
    Alamogordo, NM
    Posts
    330
    BUMP! just skimmed this at work(at least im doing something constructive on the payroll!), and added to my faves.

    1project2many,
    Hi Shannen, didnt realize that was you LOL
    '86 Grand National

  9. #24
    Administrator
    Join Date
    May 2011
    Location
    Lakes Region, NH
    Age
    54
    Posts
    3,862
    Awww, dangit. Now my cover's blown.

  10. #25
    Fuel Injected!
    Join Date
    Jan 2012
    Age
    52
    Posts
    46
    I started with learning 6502 assembly on an Apple-IIe. I designed and built a hard drive controller for it, and even a copy-protection scheme. So when I started, assembly code was the first thing you learned. I did some work for a small-ish data modem company in Calgary on the 68HC705C8 and it was very similar to the 6502. After that switching between any assembly code in the Freescale/Motorola line - or the 6502 - was no problem regardless if it was a data decoder or an engine controller. I did one engine controller in 68HC11 assembler (ground-up design, 30k of code and calibration), and at about that time I started disassembling GM and Ford ECM code. Ford was harder since it was an 8096 but I managed to get through it. Now my code is mostly written in 'C' but since it is on a 9S12X part I have a lot of assembly language macros that I use for efficiency. That will not be much fun to port into a 32-bit processor but it works fine.

    Anyways, one thing that I did a lot of to learn how an algorithm would work was to download the code to an evaluation board, then single-step through it. I think now you could use a simulator. The other thing I found was important was to figure out what are I/O locations on the board and datastream locations in the communication section. Getting those figured out allows a fast decode from there. On the OBD-II code I start with attacking the mode 1 data (generic data) because that gives you things like O2 sensor voltage, MAF, MAP, etc. Then you can track down what the code does based on its function. One acid test for a disassembly is try to reassemble it and get the same image. If you do, that's good. next, add one 'NOP' at the start of EPROM and offset the code by one byte and make sure it still runs! Do the same with calibration and also with RAM. If your disassembly is correct the code will run with each of those changes. Then you can make changes to the code. I did that with the Diesel 6.5L TD code. It was a lot of work but I fixed some bugs that were in that code base. Some of these sort of hints would apply after you get a bunch of the way there. The OBD-II code, BTW, is very interesting but it is massive. The newer ones (MPC556x) have massive amounts of code in them and are generally programmed graphically (Simulink/Stateflow) and calibrated using automated tools (CAGE). I would hate to try looking at the assembled code.
    1994 6.5L 4L80E K
    2001 VW GTI
    2006 Smart ForTwo CDI

  11. #26
    Fuel Injected!
    Join Date
    Sep 2012
    Posts
    23
    I see references to "initalize the stack". A lot of times on the masks I look at it is initialized to $01FF. First, what is the stack? Second, what does it mean and do to initalize it?

  12. #27
    Administrator
    Join Date
    May 2011
    Location
    Lakes Region, NH
    Age
    54
    Posts
    3,862
    Stack is a "reserved" space in memory used to store information for processor operation. It's different from regular memory because the processor generally determines how to use it, not the programmer. For example, when a JSR instruction (Jump to SubRoutine) is encountered, the expectation is that the processor will stop what it's doing, run a temporary job using code at a different address, then return to the original job and pick up where it left off. The processor stores information on the stack needed to resume the original code before heading off to the subroutine.

    This memory is called a stack to give a nice graphic image to work with. Imagine a stack of dishes. As you add to the stack it grows. As you take from the stack it shrinks.

    The stack is initialized when the processor is given an address to use for the first memory item. Once you set that first plate down, that's where the stack will be. In the 6811 the stack will "grow" down. IOW each new item added to the stack gets a lower address than the previous item. If the stack is initialized too close to the lowest accessible memory address, you will not have a large enough space to pile your plates and you'll end up with problems. Careful programmers will often "clear" the stack or set all memory values to zero in addition to setting the initial address. Some processors have a single command to clear the stack. In the earliest GM disassemblies you'll sometimes see an actual code loop that writes zeros to each location in the stack. Either way, this helps ensure you're not going to randomly read incorrect data somewhere in the program.

  13. #28
    Fuel Injected!
    Join Date
    Sep 2012
    Posts
    23
    Initalizing at $01FF makes sense then, it is the highest RAM address in the ECM's I'm looking at and would grow down from there. How do you determine how deep the stack can get? Count the nested JSR and similar?

    Second question(s). I know about the main segment loop and how it is called based off of a interrupt from a timer. What happens if it is still in one of the loops when the next interrupt comes, for example if you add too much code and it doesn't complete in time? What happens when a loop finishes before the next interrupt?

    The main segment loop seems to be mainly the measurement and calculation of values and the output of those values (ignition and injection events) are driven by other interrupts seperate from the main segment loop? How do I determine how those are called, and which part of code is called? Or do I have it all mixed up and it works differently?

  14. #29
    Super Moderator
    Join Date
    Mar 2011
    Location
    Camden, MI
    Age
    35
    Posts
    3,026
    i determine how far the stack gets by transmitting addresses near the end of the memory map via ALDL. if the values always stay 0, the stack hasn't reached that far. if they change values at any point, the stack has reached that far.

    if one loop doesn't finish before the next is set to begin, a couple of things happen.... in all code i've seen, there is a flag that will get set when that event occurs, but it is entirely informational, it won't effect the operation of the code. when an interrupt happens though, A, B, X, Y the CCR, stack pointer and program counter all get stored to the stack, that's 11 bytes. when the RTI instruction comes up, those get pulled back off and the processor resumes what it was doing before the interrupt. if the stack gets reinitialized, then all of that data is lost. incidentally, the interrupt code for the 160Hz timer reinitializes the stack every time it comes up. in A1, the address of FFF2 shows A21F, so the code jumps there. byte 100 is checked to see if bit 7 is set, can jump around depending on why the timing interrupt was called, but if it was due to the 160Hz timer code, then it LDS 1FF to clear the existing stack.
    1995 Chevrolet Monte Carlo LS 3100 + 4T60E


  15. #30
    Fuel Injected!
    Join Date
    Sep 2012
    Posts
    23
    Is there one timer interrupt, or many timer interrupts? I am assuming that the 160Hz timer is for the main segment loop?

    If I understand correctly, if a loop is interrupted and the stack is reinatlized it just keeps moving along with the next segment in the sequence? Since the main segment loops only really measure and calculate the worse that happens is something doesn't get updated to a more current value and since each segment of the loop runs 10 times a second this is no big deal since it will just be done on the next time the loop is ran?

    Ignition, injection, and what else? I assume these are ran on an interrupt to be sure they happen at the correct time, and they take priority over the background main segment loop processing? What all runs on these interrupts? Where do these interrupts get defined/called? I sort of followd your last paragraph but not fully understanding it.

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •