public SUMME assume cs:_TEXT _TEXT segment extrn AUSGEBEN:near ; function Summe(var t:Block; n:integer):integer; SUMME: push bp mov bp, sp sub sp, 4 ; Wir speichern Platz für die lokalen Variablen ;Parameter: ; bp+0 -> bp gespeichert ; bp+2 -> Rücksprungsadresse (NEAR Adresse, also nur Offsetadresse) ; bp+4 -> n ; bp+6 -> @t (Adresse der t: Segmentadresse auf bp+8 ; Offsetadresse auf bp+6) ; lokale Variablen: ; bp-2 -> Index des aktuellen Elementes (i) ; bp-4 -> partielle Summe (s) } xor ax,ax ;statt mov ax, 0 mov word ptr ss:[bp-4], ax ; s := 0 mov word ptr ss:[bp-2], ax ; i := 0 jmp test_schleife schleife: ; wir addieren das aktuelle Element zur partielle Summe mov si, word ptr ss:[bp-2] ; si := i shl si, 1 ; i wird mit 2 multipliziert, denn ; jedes Element 16 Bit (also 2 Byte) gross ist les bx, dword ptr ss:[bp+6] ; es:bx = @t mov ax, word ptr es:[bx+si] ; ax := t[i] add word ptr ss:[bp-4], ax ; s := s + t[i] ; wir zeigen das aktuelle Element an push ax ; wir legen den Parameter in den Stapel call AUSGEBEN ; wir treten zum nächsten Element mov ax, word ptr ss:[bp-2] ; ax := i inc ax mov word ptr ss:[bp-2], ax test_schleife: ; wir testen ob wir noch Elemente in der Reihe haben; hier ax=i cmp ax, word ptr ss:[bp+4] ; i und n wird vergleicht jb schleife ; wenn i