mikebb משתמש מתחיל
הצטרף / הצטרפה: 29 April 2011
משתמש: מנותק/ת הודעות: 11
|
נשלח בתאריך: 29 April 2011 בשעה 16:23 | | IP רשוּם
|
|
|
|
שלום אני סטודנט להנדסת תוכנה תואר ראשון ובמהלך קורס את''מ נתקלתי באטימות מצד המרצים שממהרים עם החומר ולא מסבירים אפילו קצת כמו שצריך. מרצה אחת היא אנטיפטית רצינית, השני מרצה משעמם ולא מובן.
ככה אני לא מבין קטעי קוד מסויימים. אם תוכלו תסבירו לי בבקשה איך הם עובדים תודה!
; ; stack3.asm - demonstrate hardware stack usage. ; .MODEL SMALL .STACK 100h .DATA Separator EQU '#' DisplayString DB 64 DUP('$') Numbs DB '0123456789' Stack_Size DW (?) .CODE ProgStart: MOV AX,@DATA ; Set DS to point ... MOV DS,AX ; ... to data segment ; MOV DI,OFFSET DisplayString ; Have DI point to start ... ; ... of DisplayString MOV Stack_Size,SP ; Save stack size ; XOR BX,BX ; BX := 0; MOV CX,5 ; Size(Numbs) = 2*5 ; StackStore: MOV DX,WORD PTR Numbs[BX] ; Read two bytes in Numbs PUSH DX &nb sp; ; Store in Stack MOV [DI],DX ; Store in DisplayString ADD BX,2 ; BX point to next word in Numbs ADD DI,2 ; DI point to next available position LOOP StackStore ; Repeat 5 times ; MOV DL,Separator ; MOV [DI],DL ; Store '#' ... INC DI &nb sp; ; ... to separate ; MOV CX,Stack_Size ; SUB CX,SP ; Set CX to equal ... ; .. number of relevant ... ; ... bytes in stack MOV BP,SP ; StackLoop1: & nbsp; ; Print Stack downward MOV BL,[BP] ; INC BP &nb sp; ; MOV [DI],BL ; Store in DisplayString INC DI &nb sp; ; point to next available position LOOP StackLoop1 ; ; MOV DL,Separator ; MOV [DI],DL ; Store '#' ... INC DI &nb sp; ; ... to separate ; MOV BX,[BP-3] ; Retrieve eighth and ninth bytes ... MOV [DI],BX ; ... in stack ADD DI,2 ; ; MOV DL,Separator ; MOV [DI],DL ; Store '#' ... INC DI &nb sp; ; ... to seperate ; MOV BP,SP ; Retrieve third and forth bytes ... MOV BX,[BP+2] ; ... in stack MOV [DI],BX ; ADD DI,2 ; ; MOV DL,Separator ; MOV [DI],DL ; Store '#' ... INC DI &nb sp; ; ... to seperate ; MOV CX,Stack_Size ; SUB CX,SP ; Set CX to equal ... ; ... number of relevant ... ; ... bytes in stack MOV BP,Stack_Size ; DEC BP &nb sp; ; Set BP to point to last ... ; ... byte in stack StackLoop2: & nbsp; ; Print stack, upward MOV BL,[BP] ; DEC BP &nb sp; ; MOV [DI],BL ; Store in DisplayString INC DI &nb sp; ; point to next available position LOOP StackLoop2 ; ; MOV AH,9 ; Set print option for int 21h MOV DX,OFFSET DisplayString ; Set DS:DX to point to DisplayString INT 21h &n bsp; ; Print DisplayString ; MOV AH,4Ch ; Set terminate option for int 21h INT 21h &n bsp; ; Return to DOS (terminate program) END ProgStart
השני:
; ; procs3.asm - Demonstrate use of local procedures ; .MODEL SMALL .STACK 100h .DATA Max_Str_Lngth EQU 1000 PromptString DB 'Enter string:',13,10 ResultMsg DB 'The string you entered:',13,10 InputString DB Max_Str_Lngth DUP (?) InputLength DW ? ; .CODE Dos_Readln PROC FAR ; CALL INT 21h with AH = 3Fh, BX = 0 ; Read from stndin until eoln, ... ; ... but no more than CX chars into buffer ; Input expected: ; DX = Buffer OFFSET ; CX = Max buffer size ; Output: ; AX = Number of chars read. ; PUSH BX &nbs p; ; Preserve service register MOV AH,3Fh ; DOS read from handle function # MOV BX,0 &n bsp; ; Standard input handle INT 21h &nb sp; ; Get the string POP BX &nbs p; ; Restore service register RET Dos_Readln ENDP ; ; Dos_Write PROC FAR ; CALL INT 21h with AH = 40h, BX = 1 ; Write to stndout CX chars from buffer ; Input expected: ; DX = Buffer OFFSET ; CX = Number of chars to print. ; PUSH AX &nbs p; ; Preserve service register PUSH BX &nbs p; ; Preserve service register MOV AH,40h ; DOS write from handle function # MOV BX,1 &n bsp; ; Standard output handle INT 21h &nb sp; ; Print the string POP BX &nbs p; ; Restore service register POP AX &nbs p; ; Restore service register RET Dos_Write ENDP ; ; Main: MOV AX,@DATA MOV DS,AX & nbsp; ; Set DS to point to data segment ; MOV DX,OFFSET PromptString ; Set DX to point to string ; Set number of chars to print MOV CX,ResultMsg - PromptString CALL Dos_Write ; Print the string MOV CX,Max_Str_Lngth ; Read up to maximum number of chars MOV DX,OFFSET InputString ; Store the string here CALL Dos_Readln ; MOV InputLength,AX ; Preserve input length ; MOV DX,OFFSET ResultMsg ; Set DX to point to string ; Set number of chars to print MOV CX,InputString - ResultMsg CALL Dos_Write ; Print the string MOV DX,OFFSET InputString ; Set DX to point to string MOV CX,InputLength ; Set number of chars to print CALL Dos_Write ; ; MOV AH,4Ch ; DOS terminate program function # INT 21h &nb sp; ; Terminate the program END Main
|