1 / 16

Assembly For X86

Assembly For X86. Chapter 7 הסתעפויות, שימוש במחסנית. הפקודה jmp. הגרסה הפשוטה ביותר ניתן להפעיל על תוית או אוגר: מוגבל בטווח של -128 עד 127 lp1: …. jmp lp1 ….. jmp bx. פקודות הסתעפות מותנות. JZ,JE (z==0) JNZ,JNE (z!=0) JA – jump above (unsigned) JG – jump greater(signed)

senta
Télécharger la présentation

Assembly For X86

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Assembly For X86 Chapter 7 הסתעפויות, שימוש במחסנית

  2. הפקודה jmp • הגרסה הפשוטה ביותר • ניתן להפעיל על תוית או אוגר: • מוגבל בטווח של -128 עד 127 lp1: …. jmp lp1 ….. jmp bx

  3. פקודות הסתעפות מותנות • JZ,JE (z==0) • JNZ,JNE (z!=0) • JA – jump above (unsigned) • JG – jump greater(signed) • JAE/JAG – jump if >= • JB/JBE (unsigned) • JL/JLE (signed) • JCXZ – jump if CX == 0 • JC/JNC/JS/JNS/JZ/JNZ…..

  4. המחסנית • מבנה נתונים זמין שעובד בשיטת LIFO • אוגרים: SS, SP, BP • משמשת להעברת פרמטרים לפונקציות • המעבד משתמש בה בביצוע פסיקה • ניתן להגדיר את גודלה כרצוננו, ברירת המחדל היא K1

  5. Push push op ;reg/mem • סדר פעולות: sp=sp-2 ss:sp = op • אם האופרנד הוא 32 סיביות: sp=sp-4 ss:sp=op

  6. Pop • pop op ;reg/mem • 16 bit: op=ss:sp sp=sp+2 • 32 bit: op=ss:sp sp=sp+4

  7. פקודות נוספות • pusha – הכנסת האוגרים: AX, CX, DX, BX, SP+8, BP, SI, DI (לפי סדר זה) • popa – הוצאת האוגרים הנ"ל (בסדר הפוך ללא SP – כלומר מתעלמים מקיומו במחסנית) • pushad, popad – כנ"ל עבור האוגרים המורחבים • pushf, popf – הכנסת/הוצאת אוגר הדגלים • popef ,pushfd – כנ"ל עבור אוגר הדגלים המורחב

  8. דוגמא: החלפת ערכים mov ax,10 mov bx,20 push ax push bx pop ax pop bx

  9. שימוש במשתנים .data mem1 db 0 mem2 dw 1234 .code … pop ax pop mem1 push word ptr mem2 push [si]

  10. Memcopy mov bx,arr1 mov cx,size lp1: mov dx,[bx] push dx add bx,2 loop lp1 mov bx,arr2 mov cx,size lp2: pop dx mov [bx],dx sub bx,2 loop lp2

  11. שגרות • מבנה: <procname> PROC NEAR/FAR : ret <procname> ENDP • קריאה לשגרה: CALL <procname>

  12. NEAR/FAR • NEAR - השגרה נמצאת באותו סגמנט ואז לפני הקריאה לשגרה מוכנס IP למחסנית • FAR – השגרה נמצאת בסגמנט אחר, לפני הקריאה מוכנס למחסנית CS ואחריו IP • ניתן לקרוא לשגרה ע"י אופרנד זיכרון(במקום שם) עבור אופרנד 16 סיביות – NEAR, עבור 32 סיביות - FAR

  13. איזון המחסנית • שגרה שמשתמשת באוגרים, חייבת לשמור את ערכם במחסנית לפני השימוש ולשחזרם בסיום השגרה. • השחזור חייב להיות בסדר הפוך לשמירה • חוסר תיאום בין שמירת האוגרים ושחזורם יגרום לקריאת כתובת חזרה לא תקינה

  14. Fact PROC NEAR push bp push cx mov bp,sp mov cx,[bp+6] ; the parameter of the function mov ax,1 mov currDeg,1 cmp cx,0 jz exit factloop: mul currDeg inc currDeg loop factloop exit: ;the return value stored in AX pop cx pop bp ret fact endp

  15. יצירת פרוייקט ממספר קבצים • יש להגדיר את הפונקציות שרוצים לייצא: • PUBLIC procname • בקובץ שמשתמש בפונקציות יש להצהיר עליהן: • EXTRN procname:NEAR,proc2:FAR…

  16. תהליך הקישור c:\> tasm file1 c:\> tasm file2 c:\> tasm file3 : c:\> tlink file1+file2+file3 c:\> file1.exe

More Related