Results 1 to 15 of 35

Thread: Code: Learning Disassembly Assembly

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Administrator
    Join Date
    May 2011
    Location
    Lakes Region, NH
    Age
    54
    Posts
    3,867

    Code Questions

    Mark, working with assembly is kind of like working with a young child. You have to spell out every instruction to get a job done. To the processor, memory locations are mainly for storage. The accumulators are used for doing math operations or a few other larger instructions. If memory is like a storage shelf, then the accumulators are the workbench. Load accumulator means "get this thing from storage and put it on the bench." The instruction by itself doesn't do much. It's the steps that follow it that really do work. In the code section above D77D loads Accumulator B with a value from memory location 00DF. The next line is where something is done... in this case one of the bits is "set" or forced to be "1". Follow the BRA (branch) to the address it specifies and you'll see that the value from Accumulator B is then moved back to location 00DF with a "STAB" (STore Accumulator B) instruction.
    Last edited by 1project2many; 02-10-2013 at 05:49 AM.

  2. #2
    RIP EagleMark's Avatar
    Join Date
    Feb 2011
    Location
    North Idaho
    Age
    64
    Posts
    10,477

    Code: Learning Disassembly Assembly

    From 1project2many:

    EagleMark's post below made me realize it would be a good idea to have a place for code questions. Anything goes, so to speak, as long as it's code related. Assembly, Modula, C++, Motorola, Intel, Whatever.

    ------------------------------------------------

    $4F XDF Fuel VE table goes to 5200 RPM, but the assembly only goes to 4800? Somone started at 400 RPM instead of 0 RPM.

    Odd? Have you ever seen how much Air managmant code is in a $6E assembly? And I can't find a way to turn it off? In $42 it's just a temp on and timer...

    Since I'm stating to understand looups and sub routines how about a lesson on the commands? I just grabbed this piece and BOLD, Italic and UNDERLINED some examples.

    Code:
                     ;--------------------
                    ; LK UP  ACCEL ENRICH 
                    ; vs Diff TPS 
                    ; ** PUMP SHOT **
                    ;--------------------
    D775:            LDAA    #255
    D777:  LD777     LDX     #$D312         ; ACCEL ENRICH vs Diff TPS TBL
                                            ; Contrib vs Diff TPS TBL
    D77A:            JSR     LFAD7          ; 2D LK UP 
     ;                                                            
    D77D:            LDAB    L00DF
    D77F:            ORAB    #$10           ; BIT 4
    D781:            BRA     LD786
     ;                                                            
    D783:  LD783     CLRA    
    D784:            ANDB    #$EF       ; 0111 1111
    D786:  LD786     STAB    L00DF
    D788:            STAA    L0058      ; BPW, MSB
    D78A:            STAA    L009A
    D78C:            CLRA    
    D78D:            LDAB    L00DF
    D78F:            BITB    #4         ; BIT 2
    D791:            BEQ     LD796
     ;                                                            
    D793:            LDAA    LD28F      ; 183 Usec, BPW ADDER TO BPW WHILE 
                                        ; IAC IS OPENING
                                        ; VAL MSEC = 16.384 
                                        
    D796:  LD796     ADDA    L0058      ; BPW, MSB
    D798:            BCS     LD79E
                                        ; ... else                               
    D79A:            ADDA    L0059      ; BPW, LSB
    D79C:            BCC     LD7A0
                                        ; ... else    
    D79E:  LD79E     LDAA    #255       ; MAX LMT
    D7A0:  LD7A0     BEQ     LD7BE
     ;                                                            
    D7A2:            LDAB    L0098
    D7A4:            MUL     
    D7A5:            LSRD               ; DIV BY 8
    D7A6:            LSRD    
    D7A7:            LSRD    
    D7A8:            ADDD    L0096
    D7AA:            STD     L0096
    D7AC:            LDAB    L0006
    D7AE:            LDAA    L000D
    D7B0:            BITA    #$40       ; BIT 6
    D7B2:            BNE     LD7B6
                                        ; ...... else                         
    D7B4:            ORAB    #8
    D7B6:  LD7B6     ORAA    #$C0       ; 1100 0000
    D7B8:            ORAB    #1         ; BIT 0
    D7BA:            STAB    L0006
    D7BC:            BRA     LD7C2
                                                                
    D7BE:  LD7BE     LDAA    L000D
    D7C0:            ANDA    #$BF       ; 1011 1111
    D7C2:  LD7C2     STAA    L000D
    D7C4:            LDAB    L0072
    D7C6:            BITB    #2         ; BIT 1
    D7C8:            BEQ     LD7DD
    Code: Learning Disassembly Assembly
    Last edited by 1project2many; 02-10-2013 at 05:50 AM.

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

  3. #3
    Fuel Injected! jim_in_dorris's Avatar
    Join Date
    Dec 2011
    Posts
    803
    I'm not sure if I see it correctly myself, but it looks like this is highlighted. If I may.

    LDAA #255
    D777: LD777 LDX #$D312 ; ACCEL ENRICH vs Diff TPS TBL
    ; Contrib vs Diff TPS TBL
    D77A: JSR LFAD7
    ; 2D LK UP ;
    D77D: LDAB L00DF


    LDAA and LDAB are Load Accumulators A and B.
    LDX is Load index register X.
    and JSR is Jump to subroutine.

    What that piece of code is doing is loading accumulator A with $FF(256), loading the index register X with the address of the routine it wants (
    ACCEL ENRICH vs Diff TPS TBL)
    then jumping to that subroutine to do a lookup. on return it then loads the B accumulator with the contents of $DF which is a status flag most likely. I'm not looking at the
    hac of whatever piece of code that come from, but I feel confident that is what is happening
    Square body stepsides forever!!!

  4. #4
    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?

  5. #5
    Administrator
    Join Date
    May 2011
    Location
    Lakes Region, NH
    Age
    54
    Posts
    3,867
    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.

  6. #6
    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?

  7. #7
    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


  8. #8
    Fuel Injected! gregs78cam's Avatar
    Join Date
    May 2011
    Location
    N. Idaho
    Posts
    767
    Quote Originally Posted by 1project2many View Post
    .....the accumulators are the workbench.
    HAHAHAHAHA, story of my life.
    1978 Camaro Type LT, 383, Dual TBI, '7427, 4L80E
    1981 Camaro Z-28 Clone, T-Tops, 350/TH350
    1981 Camaro Berlinetta, V-6, 3spd
    1974 Chevy/GMC Truck, '90 TBI 350, '7427, TH350, NP203, 6" lift, 35s

  9. #9
    Fuel Injected! jim_in_dorris's Avatar
    Join Date
    Dec 2011
    Posts
    803
    1project2many that's a nice analogy. I'll have to remember it. Unfortunately, I don't get to tutor many people in assembly anymore, everybody wants to learn an object oriented programing language.
    Square body stepsides forever!!!

  10. #10
    RIP EagleMark's Avatar
    Join Date
    Feb 2011
    Location
    North Idaho
    Age
    64
    Posts
    10,477
    I'll bet you could have a full class here!

    Although I understood Jim, the analogy given by 1project2many made me look at it differantly, both accomplish the same thing. It's taken a long time to go througn ASM files to be able and add paremeters (stogage shelf) to the XDF files. But after that it's taken a while to find them and what they are doing with them (moved to accumulater). Then jumps to subroutines which could be a lookup? Stabbed in place as a vaule that is used... in general.

    I've got more from your guys 2 posts then hours of searching and reaeding for what/why how...

    Please go on, there's a lot more commands there, some may be coming together. I'll take a guess ADDA is add A? ANDA is and A? CLRA is clear A? LSRD Load Sub Routine? BEQ? BNA?

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

  11. #11
    Fuel Injected! jim_in_dorris's Avatar
    Join Date
    Dec 2011
    Posts
    803
    A really big help might be to download the microsoft pink book for the 68hc11 microcontrollers. The book has a section with all the instructions and their variations.

    http://www.technologicalarts.com/myfiles/links.html

    you want the reference manual. it's the 3rd link down and is a pdf.

    It is loads of help. if you want, we can actually start using this page to walk thru sections of code, it's also good for me to practice a skill I don't get to use except here.

    One big problem I have is using the editor on this page and formatting code, I guess I will have to edit it in HTML to get it to look right. Using the scroll box like you did is an excellent way to insert code, but when you want to comment on what is happening, you probably need to do it in this editor, hence the HTML.
    Last edited by jim_in_dorris; 02-10-2013 at 10:22 PM.
    Square body stepsides forever!!!

  12. #12
    RIP EagleMark's Avatar
    Join Date
    Feb 2011
    Location
    North Idaho
    Age
    64
    Posts
    10,477
    If you click reply and then advanced there is a [Code] [HTML] and other options instead of just the [quote] available in Quick reply.

    You can paste in code and then comment.

    I'll take a look at those links. Learning way around them helps, but most everything we need is already done and available. Need to get a 0411 LS ASM...

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

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
  •