;*** ADDX: a 2-module assembly language that adds 2 numbers
;*** Illustrates passing parameters on the stack

;*** ADDXMAIN.LST -- module containing the call to the external proc. ***
 0000                           stk        segment     stack
 0000     08 [                       dw          8 dup(?)
                ????            
                      ]         
 0010                           stk        ends
 
 0000                           data       segment
 0000  0005                     a          dw          5         ;sum = a + b
 0002  0003                     b          dw          3
 0004  ????                     sum        dw          ?
 
 0006                           data       ends
                                           extrn       adder:far ;external proc.
 0000                           code       segment
                                           assume      ds:data
 0000                           main       proc        far
 0000  B8 ---- R                           mov         ax,data
 0003  8E D8                               mov         ds,ax
 0005  FF 36 0000 R                        push        a         ;pass values on stack
 0009  FF 36 0002 R                        push        b
 000D  B8 0004 R                           mov         ax,offset sum 
 0010  50                                  push        ax        ;pass addr of sum on stack
 0011  9A 0000 ---- E                      call        adder     ;call external proc.
 0016  CC                                  int         3         ;breakpoint interrupt 
 0017                           main       endp
 0017                           code       ends
                                           end         main


;*** ADDXSUB.LST ***
                                           public      adder
 0000                           code       segment
 0000                           adder      proc        far
 0000  55                                  push        bp
 0001  8B EC                               mov         bp,sp
 0003  8B 46 0A                            mov         ax,[bp+10]  ;ax=a
 0006  03 46 08                            add         ax,[bp+8]   ;ax=a+b
 0009  8B 5E 06                            mov         bx,[bp+6]   ;get address of sum
 000C  89 07                               mov         [bx],ax     ;store result in sum
 000E  5D                                  pop         bp
 000F  CA 0006                             ret         6           ;even stack & return
 0012                           adder      endp
 0012                           code       ends
                                           end



;*** ADDXMAIN.MAP--the memory map file produced by the linker ***
 Start  Stop   Length  Name                   Class
 00000H 00016H 0017H  CODE                   
 00020H 00025H 0006H  DATA                   
 00030H 0003FH 0010H  STK                    
 00040H 00051H 0012H  CODE                   

 Origin   Group

Program entry point at 0000:0000
;*** A DEBUG session with the 2-module adding program, ADDXMAIN.EXE

-u0,16
2693:0000 B89526        MOV     AX,2695     ;main module code
2693:0003 8ED8          MOV     DS,AX
2693:0005 FF360000      PUSH    [0000]
2693:0009 FF360200      PUSH    [0002]
2693:000D B80400        MOV     AX,0004
2693:0010 50            PUSH    AX
2693:0011 9A00009726    CALL    2697:0000
2693:0016 CC            INT     3

-u40,50
2693:0040 55            PUSH    BP          ;subordinate module code
2693:0041 8BEC          MOV     BP,SP
2693:0043 8B460A        MOV     AX,[BP+0A]
2693:0046 034608        ADD     AX,[BP+08]
2693:0049 8B5E06        MOV     BX,[BP+06]
2693:004C 8907          MOV     [BX],AX
2693:004E 5D            POP     BP
2693:004F CA0600        RETF    0006

-dcs:0     ;memory dump of load module
2693:0000  B8 95 26 8E D8 FF 36 00-00 FF 36 02 00 B8 04 00   ..&...6...6.....
2693:0010  50 9A 00 00 97 26 CC 00-00 00 00 00 00 00 00 00   P....&..........
2693:0020  05 00 03 00 00 00 00 00-00 00 00 00 00 00 00 00   ................
2693:0030  00 00 00 00 00 00 00 00-00 00 00 00 00 00 00 00   ................
2693:0040  55 8B EC 8B 46 0A 03 46-08 8B 5E 06 89 07 5D CA   U...F..F..^...].
2693:0050  06 00 B8 FF FF 89 EC 5D-C3 55 8B EC 51 51 8B 7E   .......].U..QQ.~
2693:0060  0A 8D 7D 11 C4 76 06 8A-4E 04 B5 00 1E 06 1E 07   ..}..v..N.......
2693:0070  1F FC F2 A4 1F 8A 46 04-B4 00 89 C6 8B 5E 0A C6   ......F......^..

-g=0,5   ;execute bookkeeping instructions

AX=2695  BX=0000  CX=0052  DX=0000  SP=0010  BP=0000  SI=0000  DI=0000
DS=2695  ES=2683  SS=2696  CS=2693  IP=0005   NV UP EI PL NZ NA PO NC
2693:0005 FF360000      PUSH    [0000]                             DS:0000=0005

-g40     execute to first instruction in adder procedure

AX=0004  BX=0000  CX=0052  DX=0000  SP=0006  BP=0000  SI=0000  DI=0000
DS=2695  ES=2683  SS=2696  CS=2697  IP=0000   NV UP EI PL NZ NA PO NC
2697:0000 55            PUSH    BP

-dss:0,f   ;display the stack segment--not parameters on stack
2696:0000  00 00 97 26 EF 1F 16 00-93 26 04 00 03 00 05 00   ...&.....&......

-g       ;execute to end of program
AX=0008  BX=0004  CX=0052  DX=0000  SP=0010  BP=0000  SI=0000  DI=0000
DS=2695  ES=2683  SS=2696  CS=2693  IP=0016   NV UP EI PL NZ NA PO NC
2693:0016 CC            INT     3

-dds:0,f   ;dump the data segment--note result (8) has been stored
2695:0000  05 00 03 00 08 00 00 00-00 00 00 00 00 00 00 00   ................